Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
power: supply: ab8500: Avoid NULL pointers
Browse files Browse the repository at this point in the history
[ Upstream commit 5bcb5087c9dd3dca1ff0ebd8002c5313c9332b56 ]

Sometimes the code will crash because we haven't enabled
AC or USB charging and thus not created the corresponding
psy device. Fix it by checking that it is there before
notifying.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
linusw authored and SonicBSV committed Aug 23, 2022
1 parent 9ab9344 commit ebfc51f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/power/ab8500_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ static void ab8500_enable_disable_sw_fallback(struct ab8500_charger *di,
static void ab8500_power_supply_changed(struct ab8500_charger *di,
struct power_supply *psy)
{
/*
* This happens if we get notifications or interrupts and
* the platform has been configured not to support one or
* other type of charging.
*/
if (!psy)
return;

if (di->autopower_cfg) {
if (!di->usb.charger_connected &&
!di->ac.charger_connected &&
Expand All @@ -435,7 +443,15 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,
if (!connected)
di->flags.vbus_drop_end = false;

sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, "present");
/*
* Sometimes the platform is configured not to support
* USB charging and no psy has been created, but we still
* will get these notifications.
*/
if (di->usb_chg.psy) {
sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL,
"present");
}

if (connected) {
mutex_lock(&di->charger_attached_mutex);
Expand Down

0 comments on commit ebfc51f

Please sign in to comment.