]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: max17040: handle missing status supplier
authorJianing Li <m13940358460@163.com>
Wed, 1 Jul 2026 06:10:42 +0000 (14:10 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 20 Jul 2026 22:30:12 +0000 (00:30 +0200)
MAX17040 does not report charger state itself, so the driver forwards
POWER_SUPPLY_PROP_STATUS to a supplier power supply. If no supplier is
registered, power_supply_get_property_from_supplier() returns -ENODEV and
leaves the output value untouched.

max17040_get_property() currently ignores that error and returns success,
so userspace can read an uninitialized status value from the battery power
supply. This happens on systems that use the fuel gauge without a charger
supplier relationship in firmware.

Return POWER_SUPPLY_STATUS_UNKNOWN when no supplier provides STATUS, and
propagate other supplier lookup errors.

Fixes: f4b782af61ae ("power: max17040: pass status property from supplier")
Cc: stable@vger.kernel.org # 6.7+
Signed-off-by: Jianing Li <m13940358460@163.com>
Link: https://patch.msgid.link/20260701061042.1008-1-m13940358460@163.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/max17040_battery.c

index e94d53b36aa490effde2346bfcbcf5e6195e0e85..03ac569e185c5461dbd5f18a6432c0e4c6df78a6 100644 (file)
@@ -405,7 +405,11 @@ static int max17040_get_property(struct power_supply *psy,
                val->intval = chip->low_soc_alert;
                break;
        case POWER_SUPPLY_PROP_STATUS:
-               power_supply_get_property_from_supplier(psy, psp, val);
+               ret = power_supply_get_property_from_supplier(psy, psp, val);
+               if (ret == -ENODEV)
+                       val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
+               else if (ret)
+                       return ret;
                break;
        case POWER_SUPPLY_PROP_TEMP:
                if (!chip->channel_temp)