linux-stable/drivers/usb
Dan Carpenter c33ca06578 extcon: Fix extcon_get_extcon_dev() error handling
[ Upstream commit 58e4a2d27d ]

The extcon_get_extcon_dev() function returns error pointers on error,
NULL when it's a -EPROBE_DEFER defer situation, and ERR_PTR(-ENODEV)
when the CONFIG_EXTCON option is disabled.  This is very complicated for
the callers to handle and a number of them had bugs that would lead to
an Oops.

In real life, there are two things which prevented crashes.  First,
error pointers would only be returned if there was bug in the caller
where they passed a NULL "extcon_name" and none of them do that.
Second, only two out of the eight drivers will build when CONFIG_EXTCON
is disabled.

The normal way to write this would be to return -EPROBE_DEFER directly
when appropriate and return NULL when CONFIG_EXTCON is disabled.  Then
the error handling is simple and just looks like:

	dev->edev = extcon_get_extcon_dev(acpi_dev_name(adev));
	if (IS_ERR(dev->edev))
		return PTR_ERR(dev->edev);

For the two drivers which can build with CONFIG_EXTCON disabled, then
extcon_get_extcon_dev() will now return NULL which is not treated as an
error and the probe will continue successfully.  Those two drivers are
"typec_fusb302" and "max8997-battery".  In the original code, the
typec_fusb302 driver had an 800ms hang in tcpm_get_current_limit() but
now that function is a no-op.  For the max8997-battery driver everything
should continue working as is.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 18:41:35 +02:00
..
atm
c67x00
cdns3 usb: cdns3: Fix issue for clear halt endpoint 2022-05-09 09:16:14 +02:00
chipidea USB/Thunderbolt changes for 5.17-rc1 2022-01-12 11:27:57 -08:00
class usb: cdc-wdm: fix reading stuck on device close 2022-05-18 10:28:19 +02:00
common usb: ulpi: Call of_node_put correctly 2022-01-31 14:11:20 +01:00
core USB: hcd-pci: Fully suspend across freeze/thaw cycle 2022-06-14 18:41:34 +02:00
dwc2 usb: dwc2: gadget: don't reset gadget's driver->bus 2022-06-14 18:41:35 +02:00
dwc3 extcon: Fix extcon_get_extcon_dev() error handling 2022-06-14 18:41:35 +02:00
early Revert "usb: early: convert to readl_poll_timeout_atomic()" 2021-12-17 16:29:11 +01:00
gadget usb: gadget: fix race when gadget driver register via ioctl 2022-05-25 09:58:56 +02:00
host drivers: usb: host: Fix deadlock in oxu_bus_suspend() 2022-06-14 18:41:34 +02:00
image
isp1760 usb: isp1760: Fix out-of-bounds array access 2022-06-09 10:25:14 +02:00
misc usb: misc: fix improper handling of refcount in uss720_probe() 2022-05-09 09:16:12 +02:00
mon
mtu3 usb: mtu3: fix USB 3.0 dual-role-switch from device to host 2022-05-09 09:16:11 +02:00
musb usb: musb: Fix missing of_node_put() in omap2430_probe 2022-06-14 18:41:14 +02:00
phy extcon: Fix extcon_get_extcon_dev() error handling 2022-06-14 18:41:35 +02:00
renesas_usbhs usb: renesas_usbhs: Use platform_get_irq() to get the interrupt 2021-12-21 08:51:57 +01:00
roles
serial USB: serial: option: add Quectel BG95 modem 2022-06-09 10:25:14 +02:00
storage USB: storage: karma: fix rio_karma_init return 2022-06-14 18:41:14 +02:00
typec extcon: Fix extcon_get_extcon_dev() error handling 2022-06-14 18:41:35 +02:00
usbip usb: usbip: add missing device lock on tweak configuration cmd 2022-06-14 18:41:14 +02:00
Kconfig
Makefile
usb-skeleton.c