* [bug report] ACPI: battery: Adjust event notification routine
[not found] <caa37f28-a2e8-4e0a-a9ce-a365ce805e4b@stanley.mountain>
@ 2026-02-06 13:40 ` Dan Carpenter
2026-02-06 21:28 ` [PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify() Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2026-02-06 13:40 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Len Brown, linux-acpi, linux-kernel
[ Smatch checking is paused while we raise funding. #SadFace
https://lore.kernel.org/all/aTaiGSbWZ9DJaGo7@stanley.mountain/ -dan ]
Hello Rafael J. Wysocki,
This is a semi-automatic email about new static checker warnings.
Commit 08b54fd57782 ("ACPI: battery: Adjust event notification
routine") from Dec 15, 2025, leads to the following Smatch complaint:
drivers/acpi/battery.c:1062 acpi_battery_notify()
warn: variable dereferenced before check 'battery' (see line 1059)
drivers/acpi/battery.c
1058 struct acpi_battery *battery = data;
1059 struct acpi_device *device = battery->device;
^^^^^^^^^^^^^^^
The patch adds a dereference.
1060 struct power_supply *old;
1061
1062 if (!battery)
^^^^^^^^
Checked too late.
1063 return;
1064
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify()
2026-02-06 13:40 ` [bug report] ACPI: battery: Adjust event notification routine Dan Carpenter
@ 2026-02-06 21:28 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2026-02-06 21:28 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Rafael J. Wysocki, linux-acpi, linux-kernel
On Friday, February 6, 2026 2:40:27 PM CET Dan Carpenter wrote:
> [ Smatch checking is paused while we raise funding. #SadFace
> https://lore.kernel.org/all/aTaiGSbWZ9DJaGo7@stanley.mountain/ -dan ]
>
>
> Hello Rafael J. Wysocki,
>
> This is a semi-automatic email about new static checker warnings.
>
> Commit 08b54fd57782 ("ACPI: battery: Adjust event notification
> routine") from Dec 15, 2025, leads to the following Smatch complaint:
>
> drivers/acpi/battery.c:1062 acpi_battery_notify()
> warn: variable dereferenced before check 'battery' (see line 1059)
>
> drivers/acpi/battery.c
> 1058 struct acpi_battery *battery = data;
> 1059 struct acpi_device *device = battery->device;
> ^^^^^^^^^^^^^^^
> The patch adds a dereference.
>
> 1060 struct power_supply *old;
> 1061
> 1062 if (!battery)
> ^^^^^^^^
> Checked too late.
>
> 1063 return;
> 1064
Thanks for the report, but the check above is redundant.
For the reason explained in the changelog of the patch below, the
battery pointer above cannot be NULL.
---
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify()
The battery pointer check against NULL in acpi_battery_notify() is
redundant because the value of that pointer is the one passed to
acpi_dev_install_notify_handler() in acpi_battery_probe() as the
last argument which is not NULL.
Drop the redundant check.
No intentional functional impact.
Closes: https://lore.kernel.org/linux-acpi/aYXvS1h3Bxf_5sCj@stanley.mountain/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/battery.c | 3 ---
1 file changed, 3 deletions(-)
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1066,9 +1066,6 @@ static void acpi_battery_notify(acpi_han
struct acpi_device *device = battery->device;
struct power_supply *old;
- if (!battery)
- return;
-
guard(mutex)(&battery->update_lock);
old = battery->bat;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-06 21:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <caa37f28-a2e8-4e0a-a9ce-a365ce805e4b@stanley.mountain>
2026-02-06 13:40 ` [bug report] ACPI: battery: Adjust event notification routine Dan Carpenter
2026-02-06 21:28 ` [PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify() Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox