Skip to content

Commit

Permalink
platform/x86: dell-laptop: Do not fail when encountering unsupported …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
Wer-Wolf authored and jwrdegoede committed Oct 6, 2024
1 parent ed0e64d commit b6c57b7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions drivers/platform/x86/dell/dell-laptop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2391,19 +2391,28 @@ static struct attribute *dell_battery_attrs[] = {
};
ATTRIBUTE_GROUPS(dell_battery);

static bool dell_battery_supported(struct power_supply *battery)
{
/* We currently only support the primary battery */
return strcmp(battery->desc->name, "BAT0") == 0;
}

static int dell_battery_add(struct power_supply *battery,
struct acpi_battery_hook *hook)
{
/* this currently only supports the primary battery */
if (strcmp(battery->desc->name, "BAT0") != 0)
return -ENODEV;
/* Return 0 instead of an error to avoid being unloaded */
if (!dell_battery_supported(battery))
return 0;

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

static int dell_battery_remove(struct power_supply *battery,
struct acpi_battery_hook *hook)
{
if (!dell_battery_supported(battery))
return 0;

device_remove_groups(&battery->dev, dell_battery_groups);
return 0;
}
Expand Down

0 comments on commit b6c57b7

Please sign in to comment.