[PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify()

Rafael J. Wysocki posted 1 patch 18 hours ago
drivers/acpi/battery.c |    3 ---
1 file changed, 3 deletions(-)
[PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify()
Posted by Rafael J. Wysocki 18 hours ago
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;