diff mbox series

ACPI: battery: Call power_supply_changed() when adding hooks

Message ID 20221130184101.357899-1-W_Armin@gmx.de
State Accepted
Commit 98b0cf207b61e17f3ea6d9c17334c8ffc2f44863
Headers show
Series ACPI: battery: Call power_supply_changed() when adding hooks | expand

Commit Message

Armin Wolf Nov. 30, 2022, 6:41 p.m. UTC
If a battery hook is added to a battery, userspace software
is not informed that the available properties of the battery
might have changed. This for example causes upower to react
slowly if a new battery hook is added during runtime.

Fix this by calling power_supply_changed() if a battery hook
was successfully added/removed.

Tested on a Dell Inspiron 3505.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/acpi/battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--
2.30.2

Comments

Rafael J. Wysocki Dec. 2, 2022, 7:31 p.m. UTC | #1
On Wed, Nov 30, 2022 at 7:41 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> If a battery hook is added to a battery, userspace software
> is not informed that the available properties of the battery
> might have changed. This for example causes upower to react
> slowly if a new battery hook is added during runtime.
>
> Fix this by calling power_supply_changed() if a battery hook
> was successfully added/removed.
>
> Tested on a Dell Inspiron 3505.
>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/acpi/battery.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 9482b0b6eadc..bf99053e5021 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -696,7 +696,8 @@ static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
>         if (lock)
>                 mutex_lock(&hook_mutex);
>         list_for_each_entry(battery, &acpi_battery_list, list) {
> -               hook->remove_battery(battery->bat, hook);
> +               if (!hook->remove_battery(battery->bat, hook))
> +                       power_supply_changed(battery->bat);
>         }
>         list_del(&hook->list);
>         if (lock)
> @@ -735,6 +736,8 @@ void battery_hook_register(struct acpi_battery_hook *hook)
>                         __battery_hook_unregister(hook, 0);
>                         goto end;
>                 }
> +
> +               power_supply_changed(battery->bat);
>         }
>         pr_info("new extension: %s\n", hook->name);
>  end:
> --

Applied as 6.2 material, but I had to rebase it, so please check the
result in my bleeding-edge branch.

Thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 9482b0b6eadc..bf99053e5021 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -696,7 +696,8 @@  static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)
 	if (lock)
 		mutex_lock(&hook_mutex);
 	list_for_each_entry(battery, &acpi_battery_list, list) {
-		hook->remove_battery(battery->bat, hook);
+		if (!hook->remove_battery(battery->bat, hook))
+			power_supply_changed(battery->bat);
 	}
 	list_del(&hook->list);
 	if (lock)
@@ -735,6 +736,8 @@  void battery_hook_register(struct acpi_battery_hook *hook)
 			__battery_hook_unregister(hook, 0);
 			goto end;
 		}
+
+		power_supply_changed(battery->bat);
 	}
 	pr_info("new extension: %s\n", hook->name);
 end: