[PATCH 0/2] power: supply: sbs-battery: Fix the shared serial number buffer
From: Babanpreet Singh
Date: Sun Jul 26 2026 - 03:22:34 EST
The serial number of every sbs-battery instance is formatted into one
file-scope buffer, so concurrent reads on two batteries can make one
battery report the other's serial number. Patch 1 gives each device its
own buffer.
While rewriting that sprintf() call it became apparent that the
conversion is also the only W=1 warning in this driver: the value is
carried in an int and only its negative half is rejected, so gcc cannot
prove that four hex digits fit the five-byte buffer. Patch 2 casts to
the register's actual width. It is a separate patch because it is a
distinct (and purely cosmetic) change - please just drop it if you would
rather not carry it.
Both patches are compile-tested only; I have no SBS hardware. The race
in patch 1 was derived from the code, not observed on a running system.
Detail on the multi-instance premise for patch 1, since it is the part
that matters: sbs-battery binds per I2C client and sbs-manager registers
one muxed I2C channel per supported battery precisely so that the smart
battery driver can be bound to each of them (MANAGER_SBS Kconfig help
says as much), so more than one instance is a supported configuration
rather than a hypothetical one.
Babanpreet Singh (2):
power: supply: sbs-battery: Use a per-device serial number buffer
power: supply: sbs-battery: Bound the serial number conversion to 16
bits
drivers/power/supply/sbs-battery.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--
2.43.0