public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: SBS: Fix present test in acpi_battery_read()
@ 2025-10-31 13:03 Dan Carpenter
  2025-11-03 16:32 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-10-31 13:03 UTC (permalink / raw)
  To: Alexey Starikovskiy, Harshit Mogalapalli
  Cc: Rafael J. Wysocki, Len Brown, linux-acpi, linux-kernel,
	kernel-janitors

The battery->present variable is a 1 bit bitfield in a u8.  This means
that the "state & (1 << battery->id)" test will only work when
"battery->id" is zero, otherwise ->present is zero.  Fix this by adding
a !!.

Fixes: db1c291af7ad ("ACPI: SBS: Make SBS reads table-driven.")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
This is a new static checker warning that Harshit and I wrote.  It's
untested.

 drivers/acpi/sbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index a3f95a3fffde..d3edc3bcbf01 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -487,7 +487,7 @@ static int acpi_battery_read(struct acpi_battery *battery)
 		if (result)
 			return result;
 
-		battery->present = state & (1 << battery->id);
+		battery->present = !!(state & (1 << battery->id));
 		if (!battery->present)
 			return 0;
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPI: SBS: Fix present test in acpi_battery_read()
  2025-10-31 13:03 [PATCH] ACPI: SBS: Fix present test in acpi_battery_read() Dan Carpenter
@ 2025-11-03 16:32 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-11-03 16:32 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Alexey Starikovskiy, Harshit Mogalapalli, Rafael J. Wysocki,
	Len Brown, linux-acpi, linux-kernel, kernel-janitors

On Fri, Oct 31, 2025 at 2:03 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> The battery->present variable is a 1 bit bitfield in a u8.  This means
> that the "state & (1 << battery->id)" test will only work when
> "battery->id" is zero, otherwise ->present is zero.  Fix this by adding
> a !!.
>
> Fixes: db1c291af7ad ("ACPI: SBS: Make SBS reads table-driven.")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> This is a new static checker warning that Harshit and I wrote.  It's
> untested.
>
>  drivers/acpi/sbs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index a3f95a3fffde..d3edc3bcbf01 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -487,7 +487,7 @@ static int acpi_battery_read(struct acpi_battery *battery)
>                 if (result)
>                         return result;
>
> -               battery->present = state & (1 << battery->id);
> +               battery->present = !!(state & (1 << battery->id));
>                 if (!battery->present)
>                         return 0;
>
> --

Applied as 6.18-rc material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-03 16:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 13:03 [PATCH] ACPI: SBS: Fix present test in acpi_battery_read() Dan Carpenter
2025-11-03 16:32 ` 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