public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Armin Wolf <W_Armin@gmx.de>
Cc: mjg59@srcf.ucam.org, pali@kernel.org, dilinger@queued.net,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	lenb@kernel.org,  Hans de Goede <hdegoede@redhat.com>,
	platform-driver-x86@vger.kernel.org,  linux-acpi@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] ACPI: battery: Simplify battery hook locking
Date: Mon, 23 Sep 2024 16:35:39 +0300 (EEST)	[thread overview]
Message-ID: <5b3e4ec1-e5a6-cb77-1d57-3515eb051cc2@linux.intel.com> (raw)
In-Reply-To: <20240922064026.496422-2-W_Armin@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

On Sun, 22 Sep 2024, Armin Wolf wrote:

> 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 <W_Armin@gmx.de>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/acpi/battery.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> 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);
>  }
> --
> 2.39.5
> 

  reply	other threads:[~2024-09-23 13:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-22  6:40 [PATCH v2 0/3] platform/x86: dell-laptop: Battery hook fixes Armin Wolf
2024-09-22  6:40 ` [PATCH v2 1/3] ACPI: battery: Simplify battery hook locking Armin Wolf
2024-09-23 13:35   ` Ilpo Järvinen [this message]
2024-09-22  6:40 ` [PATCH v2 2/3] ACPI: battery: Fix possible crash when unregistering a battery hook Armin Wolf
2024-10-01 18:57   ` Rafael J. Wysocki
2024-09-22  6:40 ` [PATCH v2 3/3] platform/x86: dell-laptop: Do not fail when encountering unsupported batteries Armin Wolf
2024-09-22  7:45 ` [PATCH v2 0/3] platform/x86: dell-laptop: Battery hook fixes Andres Salomon
2024-09-22  8:53   ` Pali Rohár
2024-09-23 20:14   ` Armin Wolf
2024-09-30 18:53 ` Armin Wolf
2024-09-30 19:03   ` Rafael J. Wysocki

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=5b3e4ec1-e5a6-cb77-1d57-3515eb051cc2@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=W_Armin@gmx.de \
    --cc=dilinger@queued.net \
    --cc=hdegoede@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjg59@srcf.ucam.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