]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
extcon: Fix extcon_get_extcon_dev() error handling
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 17 Dec 2021 06:28:46 +0000 (09:28 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 26 Aug 2022 08:53:06 +0000 (10:53 +0200)
commit6f99bf25b65737c77d5f215b2a630ad78f36829f
tree7e6973fde67b1e36ffec0a5dba28bcfeade360dc
parentf47823aca7699ce3f25f3f4e621d13dfdc8afdcb
extcon: Fix extcon_get_extcon_dev() error handling

BugLink: https://bugs.launchpad.net/bugs/1982968
[ Upstream commit 58e4a2d27d3255e4e8c507fdc13734dccc9fc4c7 ]

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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/extcon/extcon-axp288.c
drivers/extcon/extcon.c
drivers/power/supply/axp288_charger.c
drivers/power/supply/charger-manager.c
drivers/power/supply/max8997_charger.c
drivers/usb/dwc3/drd.c
drivers/usb/phy/phy-omap-otg.c
drivers/usb/typec/tcpm/fusb302.c
include/linux/extcon.h