The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: pali@kernel.org, dilinger@queued.net
Cc: rafael@kernel.org, lenb@kernel.org, hdegoede@redhat.com,
	ilpo.jarvinen@linux.intel.com,
	platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH RESEND v3 3/3] platform/x86: dell-laptop: Do not fail when encountering unsupported batteries
Date: Tue,  1 Oct 2024 23:28:35 +0200	[thread overview]
Message-ID: <20241001212835.341788-4-W_Armin@gmx.de> (raw)
In-Reply-To: <20241001212835.341788-1-W_Armin@gmx.de>

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>
---
 drivers/platform/x86/dell/dell-laptop.c | 15 ++++++++++++---
 1 file 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;
 }
--
2.39.5


  parent reply	other threads:[~2024-10-01 21:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01 21:28 [PATCH RESEND v3 0/3] platform/x86: dell-laptop: Battery hook fixes Armin Wolf
2024-10-01 21:28 ` [PATCH RESEND v3 1/3] ACPI: battery: Simplify battery hook locking Armin Wolf
2024-10-02 12:06   ` Rafael J. Wysocki
2024-10-02 14:48     ` Armin Wolf
2024-10-01 21:28 ` [PATCH RESEND v3 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook Armin Wolf
2024-10-02 12:08   ` Rafael J. Wysocki
2024-10-02 12:35     ` Hans de Goede
2024-10-02 12:54       ` Rafael J. Wysocki
2024-10-02 17:54         ` Rafael J. Wysocki
2024-10-01 21:28 ` Armin Wolf [this message]
2024-10-06 10:31   ` [PATCH RESEND v3 3/3] platform/x86: dell-laptop: Do not fail when encountering unsupported batteries Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241001212835.341788-4-W_Armin@gmx.de \
    --to=w_armin@gmx.de \
    --cc=dilinger@queued.net \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox