From patchwork Tue Oct 1 21:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13818782 X-Patchwork-Delegate: rjw@sisk.pl Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 254431CBEB8; Tue, 1 Oct 2024 21:28:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727818141; cv=none; b=bQQf6Y5rnv0dbhoE1/Pb/wxY0WWPsun07LgqkAjy3lEWr0CloIwLD+Mfxyrof7eiV38dLcAfD8IFi7jet3WMJB6yL2MDVP7bjDTz0UxEgQ4kMHyT1fpV+yILK54l+MfRDFpH59RgikRkvwYF8qXAswyfyM+rujakNHHE9Zza6Og= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727818141; c=relaxed/simple; bh=zRrK5MFLc1JOcsvDvNeBvZ62OTjh8GMAY70UPMH4h+w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=QzsvqpLDJcau3M1Hm93FPYjbaQrM2Ftxvv9ea57ICkS4FNWY5q2RqsJJ/wSJBBAiX3bEGzDW5+ru9PHBM8cyySrzhJfP3sDwWkYtAIruHpc/XwhDe6nf6w2OmDUTRoi3O++rv5txilpD/7NN6xX8cGipYbWhn3FGzvwT47wlMR8= 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=MRbHqekI; arc=none smtp.client-ip=212.227.15.15 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="MRbHqekI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1727818123; x=1728422923; i=w_armin@gmx.de; bh=5R8P7uAwF3AYond08GKx/BPQQKEFJ8KK25PxVprj+Uk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=MRbHqekIhkgl1p0KFvuEjh8v6yVVAnGjgy1f5CK3MGHzfvw+WJ/fT2Dlt4xXurB4 CR91ZrVQB41qrrDa7LX/YTy/GeMT6X9ldHO/czDGLV7GmsrewaOLHhcaSw/FGYmeR WKbK8Ds2l1+erlumrs6qF5F2LWWIvj0gqmbF91JYkFkDfIrAJDijelhJOyMC02C7b jhZlFvNFNvjHfVgWd0Fz3N3lgJbsUjpDvzGyojr+k8v73NLAOCBWbs2fCcXoHl0Fd 0I2bJSs8HqkilVfWXNkeNgo9U905NzaHvgQ87HT6fjeTKpeXSpJ/EZ08IyJiKdUum h7WFor/FoIoTgSV0yg== 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 (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mf07E-1sGeFF36uA-00fEWm; Tue, 01 Oct 2024 23:28:43 +0200 From: Armin Wolf 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 1/3] ACPI: battery: Simplify battery hook locking Date: Tue, 1 Oct 2024 23:28:33 +0200 Message-Id: <20241001212835.341788-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241001212835.341788-1-W_Armin@gmx.de> References: <20241001212835.341788-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:6Trhycs4U/GeqUTO44q2sziMLm9j9fSCuEUkg0p6zxkXd+uMA7c HK26uINFVUTRZJPwTfKq1Vxs1lIWGOXkjp9SST8Mc0lQnKn85kWAQNkl0Gx6k37VnMntwOF kykLTjGvV+Wz8PoAeXbEwrVpV322CfwRzPwwytRCAdx6BNJ0kx2g8rs6Hg5bG5nAsrKAqu1 sAAbRX7tfKZaSpdRWl+bg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:1VcvCWkHb20=;oHmGt4fIoIJxHInZNupLg94rCNK 2ftDnU5nD5ngaAOKy0Aa4ouYwcZm1gL9oJlBKWxfCa1/hFuwPb1/qa+4L7pU3WRaTGtG6WIyL LNky2lXmuOZ47BqDm6Pnrumg1EiaBHP3evQPAxVcDCSQ8kAKSpMfMOdCi9Bl6OORtI3hktAUi yShEuq4/mlI0oZsBhaA9QhTo6i9SopirIF9weUweEeLby1BpbYpVssCQlzvoq4Y8pyy+TYFmW HW5BWnTMdwGpBwUEP15q1AczFM13RFT2WNTT/1xUr4LTdBHExP34oWl1fScdts4fvF3DL6smm kfTAxk7fjb3CPS7As2GwNKJfuLMt89MWmvsZYwFNiaaZJRyiTPVGs/m3V+BzSGZiS1Z3QKxk7 W0MF/LuHtBoXYTCI12wWuhaJlHCz7zImlln88bVvHBLsBGAhNuaejKxw3nEZe4IYctXn8pkvc Wf5LEFKpLmIcFKWsv5+rL7uEdM0VPWRD0jzXpVK7jR/vjwb9jgHQ5rXN5hWM0nzyPg9tBFAxA FpxQQObQuNAbhGd28pionxh1DZwXLa6z7NZ/T2S0xLcnsyBgGGi/OZUVHse8z/2+5wkSjPXlr d2bpR5zkiBEmAOelGb01hfMn7Mgg+HxPjdyh+yenRTp8jCARGRCJRiZ0kQ1yjmcc16BQIJlA1 jiatrA92QS9l7bWQUcHaUZxUE6w6m9T8iwf3WWUlT2qpqB94Nj7//xbuaF1Ky3zYGR38fQAi4 RYhieMgzbIfbaqZUloQLiPXgtfUl5Z1dyHdHhXR94HfyYpb5E4UIKPjIkGOGx1+BAfe6+S+8r VhhQzAtrxRgTFGftjYa/qu9A== 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. Reviewed-by: Ilpo Järvinen Reviewed-by: Rafael J. Wysocki Reviewed-by: Pali Rohár Signed-off-by: Armin Wolf --- 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 f4599261cfc3..dda59ee5a11e 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -703,28 +703,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); @@ -750,7 +750,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; } @@ -804,7 +804,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); @@ -837,7 +837,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 Tue Oct 1 21:28:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13818781 X-Patchwork-Delegate: rjw@sisk.pl 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 6C4B6322E; Tue, 1 Oct 2024 21:28:57 +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=1727818140; cv=none; b=frZQJEH75+7LrgCN7kAp1lfLC9u2EqgJ7xxHd08mKNzcKou/1K6q/t+0mS43gvESN6LPsbiPCuMs3jdmXzqp9fF/8FL2LDFxRJPG1L1XU2V1pEy0IpsWEM7L7MgdZ3pPwjRjX2B0oSQNLoZSokfL/Q1c4IkgMk4iUK6fP4mlSIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727818140; c=relaxed/simple; bh=HSgmYOiPjTS+Y7k55CMsqRvyzjtSPq2GUW0pjz5carE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ExXEItPmQiiPC08oGLkPTOLiNYf8ZYsFzs14sEP0sM1/FXh+th7TKJIG4uTnTJbmmzFrHXtL41RAPyUO31SMY2dkHs35Z406kFdotZ8Bx/lr3x+MtbYCj+XVMXBRKXB52W6mTCHPXSAB/uvjtvoVJHvtarqGGLgPv3+z2/4H4+0= 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=rwtWe6hC; 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="rwtWe6hC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1727818125; x=1728422925; i=w_armin@gmx.de; bh=wnm+2LUKJumpZZKg7ux4iBcF5swPdX4Q7oXTV5DFeCc=; 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=rwtWe6hC2/+zlvUiiNAq6zmKD4DdkdnpDYZcI7W1mcKWoksxlXok5NAw0X1flciW tY4wMWWj4uGzhmRCss8EQuQaQycsVfqG5f5nQkX34c517w4o3VSbL3CKBTdy1g6DR 0l8OuZpCBWtFhhxOrZDIXrn3I73zIVvS62At8llbhVqMgIonGkEDnMaKUoPmj61aC FMJWuda1dHCj2RkD9UloQtEDc7qG+aLZ2J2Ts0nHgFw/uVSBzRMDwAX22xdGdjt5s lE0wJvpSOOD8vYblXTTNsqE0vrsKK13J3N9QbXBJHyRjg531eL1kZWSlFydJcwh4g uMzOCWfdkr93u3DjRg== 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 1MBUmD-1skR5m0G3r-00GuXx; Tue, 01 Oct 2024 23:28:45 +0200 From: Armin Wolf 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 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook Date: Tue, 1 Oct 2024 23:28:34 +0200 Message-Id: <20241001212835.341788-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241001212835.341788-1-W_Armin@gmx.de> References: <20241001212835.341788-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:HbmhkhuJank0diWHw2R8aalQ2wrO18QkAEZH4K0IOV1d+cZFoNU WnbBpuYxFVaMjcv/Wv7czwPahb/wqiu5XdvObPp5/qJYCUdUSbeaWbF8rZaJKCd48IjrtNY z1FlIwNdX3iPt+hkGCOxfY5B+ggm4+wUDTOU8LdhoS98/pSZPUVuWf5zDx6LeaGUZylWxaz f3AcsbKj2MjEHnVnGs35w== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:anvl3W1DNEA=;iW2UEA65vG3+h/IzA/s08Qj6ir+ 2YF21LrJNxCg++m4kG95jCSHms8IbRKewn9ugt9C6nqzmzlc7lVUYWY7baVKViD3GSen13Wi2 /HIdM0+CDhEclgA7OIhyWa9w0QTVAHkbLF10mCUmf4959jEu9Rkq0iYc/9aeC1yleMC7R28+E AY0BHwcrys+jdr5AG96FmeK8LF+cVVa69yruuD3p60Bu9EewYcc2bIDK8dpDzb+RVSJet8l39 jOIdVX33ZlEzn9ygR1lupK/FdGM9s+agrh/59pEOpyvGCyOz3tboVmdphfBcbEsIRB5IldmK1 yFoPQfce2aITY6uCjx7/ZEByGGEyyoe58ETr1bwqi1BRTl8B62R4AD3NSGG2QvmmqhI0VuUow NLrgWl8T1Pap6K1ycPIm8X2xfrm4z9ZGzepo7eWYnvAivUZn7cAuJjvtUdeTMirw8j67rQ8Gu UPr2rvY7Yc40yY8bxf+TKjLZH0iL5R5KMnPnTKwfiuuj77PeFlV7an3EVR+JjRktC7TVmW5S5 ga9vKG138KqSeJLgz8eNhcJBE3wYfg0aX33g04WG5poHo27PZOR0wXvPeZXKGY2KEMnSFL0oD QoZhNzmYUNxkdiM9agfocfayLpo0pWpiTyIfbC8wXDW9TLSf8mVh5W8jnrUCERcCIRCkTSx48 7kAYy8Iux8kh7CdwqgwBUL0XyaYBvxJFuD+XBG0czdbOdiNs5NiLNtBOVoPPKzeoa13WMxhrd c1+X+AVETPv+j04RJFCMTpRzbLU9llTeF7syPlUo0aIrWIHXO8EszImOEIBr6wbSLb4JcJzDt Cn3/JgyUe19gKUO8kt2mqz4Q== 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 the list head to mark already unregistered battery hooks as already being unregistered so that they can be ignored by battery_hook_unregister(). Fixes: fa93854f7a7e ("battery: Add the battery hooking API") Signed-off-by: Armin Wolf Acked-by: Rafael J. Wysocki --- drivers/acpi/battery.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 2.39.5 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index dda59ee5a11e..1c45ff6dbb83 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -715,7 +715,7 @@ static void battery_hook_unregister_unlocked(struct acpi_battery_hook *hook) if (!hook->remove_battery(battery->bat, hook)) power_supply_changed(battery->bat); } - list_del(&hook->list); + list_del_init(&hook->list); pr_info("extension unregistered: %s\n", hook->name); } @@ -723,7 +723,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 (!list_empty(&hook->list)) + battery_hook_unregister_unlocked(hook); + mutex_unlock(&hook_mutex); } EXPORT_SYMBOL_GPL(battery_hook_unregister); @@ -733,7 +740,6 @@ void battery_hook_register(struct acpi_battery_hook *hook) struct acpi_battery *battery; mutex_lock(&hook_mutex); - INIT_LIST_HEAD(&hook->list); list_add(&hook->list, &battery_hook_list); /* * Now that the driver is registered, we need From patchwork Tue Oct 1 21:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13818783 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 A0F721CEE89; Tue, 1 Oct 2024 21:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727818143; cv=none; b=Xyeh2wKw1TF4VE2DFD5LhrlqLrQ+2KZklGz2HSl6863RZW5ruRZlBK83vF3o6uCJrjhB0S/7E9EaTRXNYxCKaihTYK0fFHWraXooVOMUvALeHzygqZ2YNyVFCff7I5qFjx+APbGnaPuHG9mPNvdZj3tYZ2Equuv1gVVhlu3Md6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727818143; c=relaxed/simple; bh=E3ikZX/J9p7T+xtBjvUT5zEquGjOrUzgmRmz6mEQDAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AmhFxiLXhXXaC+5YVxjE9wgyR43BXuZ8W3GdeEt1nP4HkV0fQaofw57bHx4C1tgByiERFFLDZGh1QdcH/1l6MBln/N3qni5O4xnQsn8ysj+05XFC6Jh/KxZGlIBb5GndftlDYtBEReQcqlK/sj2XyMBD+kqmQgiRByUAe6kutAg= 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=CDk6aw15; arc=none smtp.client-ip=212.227.17.22 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="CDk6aw15" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1727818127; x=1728422927; i=w_armin@gmx.de; bh=aU2UjlqRMRf3Xmr3GhmFWSRSgp7A5bWPS5sVfd5PE5A=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=CDk6aw151asrltm8pjpVN18xY+Hbw8n/OSVegBVRMmqAHNxlyXSsI9wtk83QKico cI88NE9kIFHvUyqaTTQc2Zm82MNz8CB+2AxmOrzKpq0wNJHDl5oW62QKebGVDjmme sFHABIGBXL9IUa3v/dFZDizbHBS6RoJIdG5FAdxYadky2fcAB6vvxQMSLtEK8Ju5y 6T0Gu7BjYP7tIBGlXgxH6QSFxfDGc6UQLSfCC2bJx6TvQWPUO53DUmQuAC/xqoyDN 8uxiQYsNy6s2gzjMFbBexn6XNorKZD2nactxbdXm7M8EW5tL/x5QgnXXiWmZaZ6aZ GAZFE0RYCfy3Y8FxQA== 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 1Ma24y-1sPliV00IO-00RHYD; Tue, 01 Oct 2024 23:28:47 +0200 From: Armin Wolf 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 Message-Id: <20241001212835.341788-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241001212835.341788-1-W_Armin@gmx.de> References: <20241001212835.341788-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:14mEFumuCpmjAAMGTsp3PWmCbDT0sHWRQ/kjJkVIvHsVtObARcq ulQ8I4IMQ5jId6AYhPWvhhNi5zYfIlpB/rSaeDjwOd1Uro8mV1Ds6Den92us3aYHnWM7k53 ieMZm3lLUzQnEB32T6PcEdq3rzBL8cybofll13jJE+cm9syDREX0G1+86EEajVZymDPm3b+ LNQ7NTwxb2bpoX126P45g== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:7Kf5BdmY/Uo=;oWIcQ/9Vwys9hgaqnKN6IWZ5vaw tCUEtGb1gbntm+e9HhjWFn8A/PIEnTVYBPIW6vcFIb+ojY2vsdsybha8b/UrfyDaUbE4pD3YW Pa25+/0fRAtdrt+YqSSioXZTEcCNWusAIBYT5ovs+whwzz5rp6PhM/Hr3BXX3/Aq6GOnnYVNX QnOF/ZaBcomKCywZxcRo/v7EE4JlQVG6LosZhymZ5OwuBFnQnFK4cK3g2TdgV8SsCVeKr0EVB 4GfDLaxQgODOfs4cVVt9alcwgZwPpKji0wr75QQO6dCsvQ0kVyyT/Lt39ZYKzbTlfjUZZ/Zbq 8MWHapEzJwZGAMtRkRC0TbbVZOOi6nEf9oN3+V0r2FTlXiiJLLC6RuyxtbWQuvjgYwhQ9jQO1 ht2VDb/5NNzk3mFVQ9+tzUKVnDpGfHxWIHsL8NBLPSGyb47sQMZgKr8DQpIYMEt+sGXKwlmD7 HACAXFEjJLt8d4T5FvX/fyciEANeUJozwPUsbnWaUKgOhi7zm287ou5vCsV5U23+n1lSDqjJG sIhfMq8pg+ONwkPPao9z9OcwVwIPsryfEs+vw3E5esZrDom7iQ1XxX43mgp2L7NlB5IVIBSth 2dABElLe6OROBhUO6vRM/ey75bXbCdvhUw6vuVwDSzVrL8NmBB0KpLzM6Akj2PC6DWfXterls IIs44OKp3QtKZgbDlTxbX459MWfNv8DHeWLm80lJBkS+1vmlROhAiQTDJ7PIKa/jAqMne5ztu qvv1mKpNfJEX3tnH0gMqoSmaYY3l2HaLQebk+8bABZv+Qj33BhG8xUsy7CrlCCJ5eSwmVhKpq vpKu8EcjDNwZfwQRKhRURBlQ== 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 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; }