Skip to content

Commit 95339f4

Browse files
superm1sre
authored andcommitted
power: supply: Fix logic checking if system is running from battery
The logic used for power_supply_is_system_supplied() counts all power supplies and assumes that the system is running from AC if there is either a non-battery power-supply reporting to be online or if no power-supplies exist at all. The second rule is for desktop systems, that don't have any battery/charger devices. These systems will incorrectly report to be powered from battery once a device scope power-supply is registered (e.g. a HID device), since these power-supplies increase the counter. Apart from HID devices, recent dGPUs provide UCSI power supplies on a desktop systems. The dGPU by default doesn't have anything plugged in so it's 'offline'. This makes power_supply_is_system_supplied() return 0 with a count of 1 meaning all drivers that use this get a wrong judgement. To fix this case adjust the logic to also examine the scope of the power supply. If the power supply is deemed a device power supply, then don't count it. Cc: Evan Quan <[email protected]> Suggested-by: Lijo Lazar <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 4cbb0d3 commit 95339f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/power/supply/power_supply_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data)
348348
struct power_supply *psy = dev_get_drvdata(dev);
349349
unsigned int *count = data;
350350

351+
if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_SCOPE, &ret))
352+
if (ret.intval == POWER_SUPPLY_SCOPE_DEVICE)
353+
return 0;
354+
351355
(*count)++;
352356
if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
353357
if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
@@ -366,8 +370,8 @@ int power_supply_is_system_supplied(void)
366370
__power_supply_is_system_supplied);
367371

368372
/*
369-
* If no power class device was found at all, most probably we are
370-
* running on a desktop system, so assume we are on mains power.
373+
* If no system scope power class device was found at all, most probably we
374+
* are running on a desktop system, so assume we are on mains power.
371375
*/
372376
if (count == 0)
373377
return 1;

0 commit comments

Comments
 (0)