[PATCH] ASoC: codecs: aw88395: Validate 4-byte alignment and init ret in reg update
From: Ian Rogers
Date: Thu Nov 19 2026 - 12:15:39 EST
In aw_dev_update_reg_container(), each register entry consists of two
16-bit values (4 bytes). Because 'data_len = len >> 1' shifts off bit
0 before checking 'data_len & 0x1', byte lengths with (len & 0x3) == 1
bypass validation: len == 1 yields data_len == 0, executing zero loop
iterations and returning an uninitialized ret, while larger odd
lengths silently ignore the trailing byte.
Reject any length with (len & 0x3) != 0 and initialize ret to 0.
Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig
build. Verified by building
sound/soc/codecs/aw88395/aw88395_device.o with LLVM=1 W=1 (-Werror)
and -Wconditional-uninitialized, and with a standalone C reproducer;
not runtime-tested on AW88395 hardware.
Fixes: 06d2fe9cb423 ("ASoC: codecs: Aw88395 function for ALSA Audio Driver")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
sound/soc/codecs/aw88395/aw88395_device.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/aw88395/aw88395_device.c b/sound/soc/codecs/aw88395/aw88395_device.c
index 3ae418c8b34e..2dd0b3b7de0d 100644
--- a/sound/soc/codecs/aw88395/aw88395_device.c
+++ b/sound/soc/codecs/aw88395/aw88395_device.c
@@ -1004,16 +1004,16 @@ static int aw_dev_update_reg_container(struct aw_device *aw_dev,
u16 read_vol;
u16 reg_val;
u8 reg_addr;
- int i, ret;
-
- reg_data = (int16_t *)data;
- data_len = len >> 1;
+ int i, ret = 0;
- if (data_len & 0x1) {
- dev_err(aw_dev->dev, "data len:%d unsupported", data_len);
+ if (len & 0x3) {
+ dev_err(aw_dev->dev, "data len:%u unsupported\n", len);
return -EINVAL;
}
+ reg_data = (int16_t *)data;
+ data_len = len >> 1;
+
for (i = 0; i < data_len; i += 2) {
reg_addr = reg_data[i];
reg_val = reg_data[i + 1];
--
2.56.1.708.g77570a6a1d-goog