From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
linux-acpi@vger.kernel.org,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH v1] ACPI: battery: Drop redundant check from acpi_battery_notify()
Date: Fri, 06 Feb 2026 22:28:12 +0100 [thread overview]
Message-ID: <5981321.DvuYhMxLoT@rafael.j.wysocki> (raw)
In-Reply-To: <aYXvS1h3Bxf_5sCj@stanley.mountain>
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;
prev parent reply other threads:[~2026-02-06 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 ` Rafael J. Wysocki [this message]
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=5981321.DvuYhMxLoT@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
/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