summaryrefslogtreecommitdiff
path: root/drivers/platform/x86
diff options
context:
space:
mode:
authorArmin Wolf <W_Armin@gmx.de>2024-10-02 00:28:35 +0300
committerHans de Goede <hdegoede@redhat.com>2024-10-06 13:31:19 +0300
commitb6c57b70a343da512e0fdcae9a097b3aa506b9bb (patch)
treea7a140f996e05be820be3a82d88478075c5dd85d /drivers/platform/x86
parented0e64d85fe79db0472531e6bf43d8fe2524c75c (diff)
downloadlinux-b6c57b70a343da512e0fdcae9a097b3aa506b9bb.tar.xz
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 <pali@kernel.org> Fixes: ab58016c68cc ("platform/x86:dell-laptop: Add knobs to change battery charge settings") Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://lore.kernel.org/r/20241001212835.341788-4-W_Armin@gmx.de Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/platform/x86')
-rw-r--r--drivers/platform/x86/dell/dell-laptop.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index a3cd0505f282..5671bd0deee7 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -2391,12 +2391,18 @@ 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);
}
@@ -2404,6 +2410,9 @@ static int dell_battery_add(struct power_supply *battery,
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;
}