[PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs
From: Lee Jones
Date: Mon Nov 23 2026 - 15:01:46 EST
bq32k_sysfs_show_tricklecharge_bypass() and
bq32k_sysfs_store_tricklecharge_bypass() pass an uninitialised int to
1-byte bq32k_read() and bq32k_write() transfers. This leaves three
bytes of reg uninitialised on the stack, and on big-endian systems
populates the most significant byte while bitwise operations with
BQ32K_TCFE inspect and modify the uninitialised least significant byte,
leaking a bit of stack memory on reads and failing to update the
hardware register on writes.
Declare reg as u8 in both callbacks.
Fixes: 4c466872d8ae ("rtc: bq32000: add support to enable disable the trickle charge FET bypass")
Closes: https://sashiko.dev/#/bug/linux-1ab3635e-98ec-4ca3-a4d3-58033a48c44d
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/rtc/rtc-bq32k.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 0f50cfce88cb..7e5080eeee3a 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -204,7 +204,8 @@ static ssize_t bq32k_sysfs_show_tricklecharge_bypass(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- int reg, error;
+ u8 reg;
+ int error;
error = bq32k_read(dev, ®, BQ32K_CFG2, 1);
if (error)
@@ -217,7 +218,8 @@ static ssize_t bq32k_sysfs_store_tricklecharge_bypass(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- int reg, enable, error;
+ int enable, error;
+ u8 reg;
if (kstrtoint(buf, 0, &enable))
return -EINVAL;
--
2.56.1.750.gf70dc682cf-goog