From patchwork Sun Sep 22 06:40:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 830147 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F79336C; Sun, 22 Sep 2024 06:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987249; cv=none; b=ZacmaX+S4HpfI39kcEU5xWDrb3jUXw2mQ7kBObUAjqhqzYuFHq+B59Wzu7iv5ovvS5ts5xf6DiupesxwF8QzWBfkBB8YpUJGHI80ShCaSP9vGCiHhPoWC4jdakBSGXACaEz3lWZen3v/SWtNzD5PZ4FQ1AfEedo97DBn6uFuNJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987249; c=relaxed/simple; bh=Z+4Ro6PqO14eV0eK7NAetUAnbu4ylAFI7iOIXIh90bE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=To1HwC98zTUUNOK8IZ94TLLAReD2Uv1qF4Y+pDjKRfhDToVdjoWzsLkKAhaFPVMDxS/A8bCql/OVQ4SESi8oZWCn3+6q6FxfLm9ygq5ePNoRUi8CWULJ4OGMu8gUSHv7m9VWNV0gflw1DtpK39n929F94cUHW4JUbOXwqMBtaqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=I0m1gSCQ; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="I0m1gSCQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1726987232; x=1727592032; i=w_armin@gmx.de; bh=Oq6agqHzSfOQAvgj22C78dYAyUDRZmpPUD+MVlr2AwA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=I0m1gSCQWChjmVinMLTSX8lGdM01E+dzAXxbLSyIBUfWYiS3jwsNh4HAVu4BHm5P xqd4btJ+7txheyaLIVyws4pCtyMzalk/FkmKCaiH56AXTSSFvtVoDITJcKc9KyIKU S4dHezVa4/aTMSzx2ZOFZQvEDV7kD2hvjE/QplyuuDtTVrvcoEJsUd5SUrOsYLvWF r3tsobyof1+aA3NvIXNu978sOyPorafVLkNSbJVZGNATdpJ5g/yOYutr45nRaJ+X7 XwPFFDhhuEUiW3jCSluLLw8bexKVT1cgwAoWaaZKMmKgGyeHRv/qO2fL1EGlHwHa/ cQFNU4IlGTHwlgvi7w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1McY8T-1sFLUD0hiv-00i2UN; Sun, 22 Sep 2024 08:40:32 +0200 From: Armin Wolf To: mjg59@srcf.ucam.org, 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 v2 1/3] ACPI: battery: Simplify battery hook locking Date: Sun, 22 Sep 2024 08:40:24 +0200 Message-Id: <20240922064026.496422-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240922064026.496422-1-W_Armin@gmx.de> References: <20240922064026.496422-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:T7np9KYag3uEbNY7iVclFrnqk1x+1dhOU3DbnPXnBJljhRCJ7+q IEMhKTXD4W+uZTtiwW96CRCbzXu6MpbMkwkbQR7Ll+2XWDynM66Y83svwX3zWxNvr/usmK5 lnxI7tZBoSVVMId2dh1MqWX15sIEXXoS5QeGKuI84DqdgL6eXCr1rcTXFl3WREwuoz9BGa9 HPmDKacLnmaO2IBkpsspA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:3fLpkX8iGE0=;CmWOcmyxk+8UxNgvk2jox2fkHuP DH9oBlYzG+cNvCUQhOHQsojURWgWgnQboKsUlJVUKEszFOJCAmzg/pGZoII0bOMqGU0mUihIK p4tORM+3Ab3fbUy0gYJIphDkGzoACIFa+LDtg6u3GjCz7z1sfrbI9CeZrpLAg0mI6GivvR1D4 NEFNkGIJA6SJ1fpPrgLkF99j6crqAW76EPo063xNFVtBgbCRhugV+0BOpT4u9FbU4SCP/rblt rWLFjUDgKXEfQWUTSPTlfkS+vSsZu4irN0mc3pl11qcGOwEkKMXF/RA7BIsj4QFAaZHM25Tlq UMuXoxWbUqgtTv44y1vC4fvvJhmrJ/YG7SqPK0DjHnW2d6TSRx2C8fkMgTYx6bvazqxKwqwIb NHOE1Dom7AimjyFQ4y5o6Ut8VPQH3mTfyybBJeB7Ftoa9MQfPQobzg8/YLLTpL5RKRQ6E62Px 6CukWM3QZWaqNr+obhHOd/l3x09hU7Zwxyk5vzUV2ntzR5R32187YkwfKFuuwprMlYx7013Z+ 2mcVbmkyo+5222bf8xf4aZdEDLtqRTTd8lR4X6/y/Wf8MLjA0f+FTEJs8bMAnaCJiLyaub8HF n/EA/IZQZS5d5ifG+4tdV67HhH9ty9WmQf9kK8p1dyqVYLcuI5Xj/snrzKUTOIUdjNfmONRU0 bo7gliiMoT+t4/YF4nlLvNb3UyjvyYOlANLeRw4BiCcjraS+30LN8bALjGD/5EotrLCZHVDM6 fFlV/a/7dhGExvLeTwPhhvFEkfVNtWqjWLeL3Xkj7/8X+ktCrL2XsqJ7oD+iR6pjk9/o2JvFG JPmQIGZf7YQFAOpnprNuMFe0sGqHbWXgj9ah3wxkvsH+0= Move the conditional locking from __battery_hook_unregister() into battery_hook_unregister() and rename the low-level function to simplify the locking during battery hook removal. Signed-off-by: Armin Wolf Reviewed-by: Ilpo Järvinen --- drivers/acpi/battery.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.39.5 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index da3a879d638a..10e9136897a7 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -706,28 +706,28 @@ static LIST_HEAD(acpi_battery_list); static LIST_HEAD(battery_hook_list); static DEFINE_MUTEX(hook_mutex); -static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock) +static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook) { struct acpi_battery *battery; + /* * In order to remove a hook, we first need to * de-register all the batteries that are registered. */ - if (lock) - mutex_lock(&hook_mutex); list_for_each_entry(battery, &acpi_battery_list, list) { if (!hook->remove_battery(battery->bat, hook)) power_supply_changed(battery->bat); } list_del(&hook->list); - if (lock) - mutex_unlock(&hook_mutex); + pr_info("extension unregistered: %s\n", hook->name); } void battery_hook_unregister(struct acpi_battery_hook *hook) { - __battery_hook_unregister(hook, 1); + mutex_lock(&hook_mutex); + battery_hook_unregister_unlocked(hook); + mutex_unlock(&hook_mutex); } EXPORT_SYMBOL_GPL(battery_hook_unregister); @@ -753,7 +753,7 @@ void battery_hook_register(struct acpi_battery_hook *hook) * hooks. */ pr_err("extension failed to load: %s", hook->name); - __battery_hook_unregister(hook, 0); + battery_hook_unregister_unlocked(hook); goto end; } @@ -807,7 +807,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery) */ pr_err("error in extension, unloading: %s", hook_node->name); - __battery_hook_unregister(hook_node, 0); + battery_hook_unregister_unlocked(hook_node); } } mutex_unlock(&hook_mutex); @@ -840,7 +840,7 @@ static void __exit battery_hook_exit(void) * need to remove the hooks. */ list_for_each_entry_safe(hook, ptr, &battery_hook_list, list) { - __battery_hook_unregister(hook, 1); + battery_hook_unregister(hook); } mutex_destroy(&hook_mutex); } From patchwork Sun Sep 22 06:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 830220 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76249192B84; Sun, 22 Sep 2024 06:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987251; cv=none; b=sSGxrN6V1qd+CZgyEdtEQscNxZemCUfF1iYTzuIb0suFHWjMCu3zH/mrSE4bG76MS2AajzAXSpTScqBQNDDPsZ1kSNleCpZE7qHMDe5lWiWjxxP1S/Xgoxhy+Dm0xPedNcjRhGF2IE4017ulLR2tem64Ob3nAzdmf2conNja4oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987251; c=relaxed/simple; bh=7EKPq1By31iy4+3m8HPLcZT9DyoKRKr1fIZ3P/0R2zo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=omKJ6cvwujU8WpnwzNAQ3SDs+bUc1pX5hQbhDTeO3DaNo6/mABaqMa4ufJdSH1wS4Tdez6g/ErcasT7zWtnjceabrdInFXn2uUcBpMPsBpA6WMWzz2xnhg9+pb/JOISUlfL7MiPM0OTiVwyQoi7kuVXDY3Ej5lBjcsNNuaRUSy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=Hfnv1No8; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="Hfnv1No8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1726987236; x=1727592036; i=w_armin@gmx.de; bh=V5StzW4LA8uvP7+ScgSDLOyMk+nvdOwL3xbCGZkTW8w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Hfnv1No8s7jdcHkpzbMnaweK1DWGF0ZtWUCekFbNM3SPpRcBosBAVjA+y41asALH 7G2d0kP1cVbaSMobdLFPlxpipnKFnEzX/n+VcS5KAfQ3pWsU/cAIIxjoWMsZTgnxd Don17L1eUP3QaqmFhIkau9+L5bd4rgkQrdWW9FtG+BcaE3Ilhmdd8UTFBKo+vpO9l mOgRmYWkf4qz/zpaxyXNlkz1wwhVaiYSAfj0LCe7BxvgKgfHGWZvl/bUJI/X8kEct FTArHDZQycIRoVKz8o6b+/CYgkRbDfzNRRf97w2jP9ZkRkqudSAJP2u6Qss6H/d13 kN48c/+l2yoptmvFeA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MVvPJ-1sQWda3cST-00Ro50; Sun, 22 Sep 2024 08:40:35 +0200 From: Armin Wolf To: mjg59@srcf.ucam.org, 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 v2 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook Date: Sun, 22 Sep 2024 08:40:25 +0200 Message-Id: <20240922064026.496422-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240922064026.496422-1-W_Armin@gmx.de> References: <20240922064026.496422-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:gpOC2/nb/ukWoQXwnCPRneIftGzaHWRoTLr3dFHi4S2UM7wwYJO y4cyGmfT3Ty4+zDkRcRfDuKc2kLIvXyGCBW0faci22TJJ1UtlxUKXF9IenDKVidWRjsaHsQ yWussq19NO43E5AXqGeWPlFa/y8fG9sO7vG4yxmMpPwYJ+GUpb3hIh9lej7uX58w5K1ooea SHPa3gdNOK1CN5qHv/PcQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:WBFFszxG25k=;g/J5Fcl9Lw+oqIpKMdZBpY57277 xP8akA8fzl2ZBFMOp5kNnMJOGLeupLRbo6pbujhfIGr7ZLQ1bvDsHU3i91UPWTbItIBbAURxP 6Gpd6x7ca3WhfovFRfEXBYINGW+ddTDAZ/HAweDCVG2Zp8MBhoIfUI9JZKUHLNPRSblehytHd F3a4fPSNCttn6Xh+Y/GpWkPzOularH2H/MuFqphtDpmTOSShDvdjduiiVYpyd0n9a/GP0BFsv Fl9YiL/WHtOOU+ozQ7WV80ibiSG4HbAUSF7nQ4WXBUxctpwHp71iDjpBA1VlNKhNs47GrNNf7 ecl2jCbyuWCB2wdKaPIebpeH8Ltk/Ni7MgPyiXGG/k+hVKa6Zd75IVAg52nBvjFJSLtpYIpaJ a2mZ3du2WJ4IIPTqNYcdgVSHcn42bY9FKra+b/jKMWZQrvvsZs7WiAPgL+jxtaGbN7fOFC5iF MU+/WjyouIhyrCs7cgJ+GhLlCO3uKta8bSPnJ1IVKVMoph1LJDBsmfL8mdDnMCAhCroiIjfW+ Tox6ew8w13T8KTpgUMdln9IpKRseX6kwP6agkUzk9Ur2Dtom7uGeASR22eqh2bUNa/Js+Cxmo Ml7EbY/yvpJX049XPJAJn6E7tgjuyrui/q+FRfGPHH36WsWIG1K3M3jxJ8yLQOSAiE4LEMEO7 yBBJhSrlP/QBrWSuK4A1Y9DvQ0HOAv6P/RHMIhLqoFdtkNIrJBreegtzN0oQXKAErb/MVpkZc p4mN+s4Emq6o4xQAjSVLcqCYMb7rqG6sE4ktvpXOD/Jc7meoODnfj9se4/S90CpHs4FMwqoRx BJkdY0vZmi12cpdYLKOMF3BQ== When a battery hook returns an error when adding a new battery, then the battery hook is automatically unregistered. However the battery hook provider cannot know that, so it will later call battery_hook_unregister() on the already unregistered battery hook, resulting in a crash. Fix this by using a boolean flag to mark already unregistered battery hooks as "dead" so that they can be ignored by battery_hook_unregister(). Fixes: fa93854f7a7e ("battery: Add the battery hooking API") Signed-off-by: Armin Wolf --- drivers/acpi/battery.c | 11 ++++++++++- include/acpi/battery.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) -- 2.39.5 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 10e9136897a7..b31a6183a082 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -719,6 +719,7 @@ static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook) power_supply_changed(battery->bat); } list_del(&hook->list); + hook->dead = true; pr_info("extension unregistered: %s\n", hook->name); } @@ -726,7 +727,14 @@ static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook) void battery_hook_unregister(struct acpi_battery_hook *hook) { mutex_lock(&hook_mutex); - battery_hook_unregister_unlocked(hook); + /* + * Ignore already unregistered battery hooks. This might happen + * if a battery hook was previously unloaded due to an error when + * adding a new battery. + */ + if (!hook->dead) + battery_hook_unregister_unlocked(hook); + mutex_unlock(&hook_mutex); } EXPORT_SYMBOL_GPL(battery_hook_unregister); @@ -737,6 +745,7 @@ void battery_hook_register(struct acpi_battery_hook *hook) mutex_lock(&hook_mutex); INIT_LIST_HEAD(&hook->list); + hook->dead = false; list_add(&hook->list, &battery_hook_list); /* * Now that the driver is registered, we need diff --git a/include/acpi/battery.h b/include/acpi/battery.h index c93f16dfb944..5cfe132bb7f5 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -16,6 +16,7 @@ struct acpi_battery_hook { int (*add_battery)(struct power_supply *battery, struct acpi_battery_hook *hook); int (*remove_battery)(struct power_supply *battery, struct acpi_battery_hook *hook); struct list_head list; + bool dead; }; void battery_hook_register(struct acpi_battery_hook *hook); From patchwork Sun Sep 22 06:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 830146 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05F15194082; Sun, 22 Sep 2024 06:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987256; cv=none; b=SgnumTXjI4tdvgwehQWPqaP0C3IdG2/MsTNHgvftnGOdrk+Cuak3YmUYwrcL+D8AWRWrhfRtgPl2xLkMCi4HH7EpfPp47jNglOeLfiDgkho83SSkrHWuerP+Mdacyx2dJ3sCvt5kmchDF3hcWnnDw94PWocQb7mq4y63W81bTTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726987256; c=relaxed/simple; bh=ZUtwmKv0+8uzyC3LpsSYhaN7w1pqqTA2l9pOhf0ogMc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=naeiPlSB+iyh+oGOJaRE02B5s93V6sj+u/9XOpd2+bkCtMr+PJmhcCs/4i+EtvPlsay+lNy4Tc+LOVxaa/nDo1zawukwItKuTkfMThcAVu1oGXMH19GV0GZJff296+j3zL66t3uvrJ4N2TQmnGB/0XeQ1+xwWo6M6JZS8zHj/Tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=ILyw8A3w; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="ILyw8A3w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1726987240; x=1727592040; i=w_armin@gmx.de; bh=KA+0oXdhhScvc3Uq9mWyMMg/fCnFPW3cMzJuenHO3C8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=ILyw8A3wX2JegSPJDiMWGL8s/sOo0tJ+nionQKqu7+4HWMB+jSUBeONISQbsLSkv aVBvRg8tKDwn/aElqy/A8owy6w46gHeVo6jSu8t8tecktmeZ6tnUiX5guQ3Z41RZ8 5vUF/URRBUKrLZEeM+QMnFGT8f307iczI0pUIpjDQo2cFkk5vUie8kpNRcFJW45cK Hhbw8TpUUrhDQERUivMO+4HALDrimt3M/biJ1GhasMDENt0CbaBESXo6IIhVTOd6L mhlPZ+OCzS3xLxGXOq25VrIMpn9PDls/K5rXOteCxUdYb+SrqGck8N44DWLRyOIjx zJ+2+U9OFEFBSPrDMg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MMGRA-1sZ5EE1E0M-00UWoE; Sun, 22 Sep 2024 08:40:40 +0200 From: Armin Wolf To: mjg59@srcf.ucam.org, 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 v2 3/3] platform/x86: dell-laptop: Do not fail when encountering unsupported batteries Date: Sun, 22 Sep 2024 08:40:26 +0200 Message-Id: <20240922064026.496422-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240922064026.496422-1-W_Armin@gmx.de> References: <20240922064026.496422-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:1F99vtVdLm3Y/R4dwTNJzHeGgcAJvTjNtUzR/QMq1SsAcdFCtgA uKQWkkwKpW817fQzd+JCICWZsxTv1+fc8bsPTTnRgCoOp2IBmZ7N+oD3gWd9NRYVz8VUxIW G2Y9bmVLuEwU9SmgMo9MyaZjhsD5y8OHw8PTV37VPxeQ8Yy+c30jBXDxE8UN+Ty8gv7SAjx bU1YfKzQYNg+pdUJUcObQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:jB/2nP6lybY=;GDf+aqYEXDqm7YWL9S9NZ78AIRW xNwywZ0HdxwjOi8RVjgc/tvyU1bNWpVmbsjDQUlINho0MYwWMoERin34ArT94kWrb0sU9CYXI RtwQx2f9dr/3RE1Ei6zMaM2unnZwBoY3220tlJyKn7tzv9p04oZE+CGr2AvJRA0mbVsa/+yqX 1f6mY+D8i4bh1wKj8KfrhPunGZaEC/KZRedaMQZzu08azOFEhDPzq/Vq/5ke7DtQcABLGJPpx elEvstRySOZi72dYVUor0q4Fep2wproU9hOTXxkXUCX6/ZoujMp4k07/RyBmfWiCwUyJGF3Xr 2t8rSUP1S5KqONzfvNe3MLy0e/9qJ6NsnG147Kq/1ntIAzx7w0hFtMXY7JyfkEic8QWFBOJut V/ZJcZDaqNmVGz8gWMy+kYoBc7SDwjVWzLx5fHdQo0xO+HlCXKT4HZMCmY/uliBTJ0nvo8jCe a7YSknKdkLP0JhAbJHH/NOwfRzdxAcZDn1h3la2IHMMf4od2mcnrVpG0svIJa0VmTou3OQG9V 3OkyLVh/aWUFKHj6fqqwvMs6uyvytLC/LjQMBBnHUuIb7MJE8zmGMiij1nQhV4p9FPOHGHj0a ZcfikwAhhdTlKrnKCVej9vVEqCjy9RHlEhGcGCupz8g4E/8fL+WKSR9HYrf0vlle9dWW/70LR Xhzx4VJX8r0v/9sR/LrvT3oIuGusT4OOhn+BW+UHUV+HDFlpn55+doH9+ngfCWajliHV35gmJ jLTXHvNJ+Er6QFjqdlXkONgS715ulShtCPT3jNHt4BsjLPmiPK2SQm53C/Ab1m0t2pcjOCpLc WAm9/ITG8ODz1cDBRi7ICyug== 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. Fixes: ab58016c68cc ("platform/x86:dell-laptop: Add knobs to change battery charge settings") Signed-off-by: Armin Wolf --- drivers/platform/x86/dell/dell-laptop.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.39.5 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; }