Skip to contentSkip to conversation

ACPI: SBS: Fix present test in acpi_battery_read()

PATCH Applied Dan Carpenter 2 participants 2 messages Oct 31, 2025 – Nov 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: SBS: Fix present test in acpi_battery_read()

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.")

---
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(-)
drivers/acpi/sbs.c +1 -1
index a3f95a3fffde..d3edc3bcbf01 100644
@@ -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;
 
Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 20 lines · Dan Carpenter

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.")

---
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(-)
drivers/acpi/sbs.c +0 -0
index a3f95a3fffde..d3edc3bcbf01 100644

drivers/acpi/sbs.c static int acpi_battery_read(struct acpi_battery *battery)

Quoted 9 lines
drivers/acpi/sbs.c +1 -2
@@ -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!