[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJZ5v0hnWigDAgAsd6moc6qaK2Hn2MfU7PunrgukOAPCvt8dHQ@mail.gmail.com>
Date: Mon, 9 Feb 2026 18:57:20 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Alper Ak <alperyasinak1@...il.com>
Cc: rafael@...nel.org, lenb@...nel.org, linux-acpi@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ACPI: battery: Avoid dereferencing battery before NULL check
On Mon, Feb 9, 2026 at 6:38 PM Alper Ak <alperyasinak1@...il.com> wrote:
>
> acpi_battery_notify() dereferences the battery pointer before checking
> for NULL. Reorder the check to ensure the pointer is validated before
> use.
The check is redundant, please see:
https://lore.kernel.org/linux-acpi/5981321.DvuYhMxLoT@rafael.j.wysocki/
> This issue was reported by the Smatch static analyzer.
>
> Fixes: 08b54fd57782 ("ACPI: battery: Adjust event notification routine")
> Signed-off-by: Alper Ak <alperyasinak1@...il.com>
> ---
> drivers/acpi/battery.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 3bbddd6f622c..abc82be69215 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -1063,12 +1063,14 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
> static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
> {
> struct acpi_battery *battery = data;
> - struct acpi_device *device = battery->device;
> + struct acpi_device *device;
> struct power_supply *old;
>
> if (!battery)
> return;
>
> + device = battery->device;
> +
> guard(mutex)(&battery->update_lock);
>
> old = battery->bat;
> --
> 2.43.0
>
>
Powered by blists - more mailing lists