Skip to content

Commit b6c57b7

Browse files
Wer-Wolfjwrdegoede
authored andcommitted
platform/x86: dell-laptop: Do not fail when encountering unsupported batteries
If the battery hook encounters a unsupported battery, it will return an error. This in turn will cause the battery driver to automatically unregister the battery hook. On machines with multiple batteries however, this will prevent the battery hook from handling the primary battery, since it will always get unregistered upon encountering one of the unsupported batteries. Fix this by simply ignoring unsupported batteries. Reviewed-by: Pali Rohár <[email protected]> Fixes: ab58016 ("platform/x86:dell-laptop: Add knobs to change battery charge settings") Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent ed0e64d commit b6c57b7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/platform/x86/dell/dell-laptop.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,19 +2391,28 @@ static struct attribute *dell_battery_attrs[] = {
23912391
};
23922392
ATTRIBUTE_GROUPS(dell_battery);
23932393

2394+
static bool dell_battery_supported(struct power_supply *battery)
2395+
{
2396+
/* We currently only support the primary battery */
2397+
return strcmp(battery->desc->name, "BAT0") == 0;
2398+
}
2399+
23942400
static int dell_battery_add(struct power_supply *battery,
23952401
struct acpi_battery_hook *hook)
23962402
{
2397-
/* this currently only supports the primary battery */
2398-
if (strcmp(battery->desc->name, "BAT0") != 0)
2399-
return -ENODEV;
2403+
/* Return 0 instead of an error to avoid being unloaded */
2404+
if (!dell_battery_supported(battery))
2405+
return 0;
24002406

24012407
return device_add_groups(&battery->dev, dell_battery_groups);
24022408
}
24032409

24042410
static int dell_battery_remove(struct power_supply *battery,
24052411
struct acpi_battery_hook *hook)
24062412
{
2413+
if (!dell_battery_supported(battery))
2414+
return 0;
2415+
24072416
device_remove_groups(&battery->dev, dell_battery_groups);
24082417
return 0;
24092418
}

0 commit comments

Comments
 (0)