power: supply: ab8500: Avoid NULL pointers
authorLinus Walleij <linus.walleij@linaro.org>
Sat, 22 May 2021 22:50:41 +0000 (00:50 +0200)
committerSebastian Reichel <sre@kernel.org>
Thu, 3 Jun 2021 16:40:15 +0000 (18:40 +0200)
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>
drivers/power/supply/ab8500_charger.c

index af32cfae9f194d3b04d04b4e4794f092477fe202..57fbfe3d8c03df7b1c34f4594643ccc4f85076f7 100644 (file)
@@ -415,6 +415,14 @@ disable_otp:
 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 &&
@@ -441,7 +449,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);