[PATCH v2 1/2] ASoC: uda1380: fix missing return value checks for I2C operations The driver currently ignores the return values of several I2C operations during register writes, which could lead to silent failures and inconsistent device state.
From: Wenyuan Li
Date: Tue Mar 24 2026 - 04:50:42 EST
Fix this by:
- Moving variable declarations to the beginning of the function (C90).
- Checking the return value of every i2c_master_send() and recv() call.
- Returning the actual error code if it's negative, or -EIO if the
transfer was incomplete.
Signed-off-by: Wenyuan Li <2063309626@xxxxxx>
---
sound/soc/codecs/uda1380.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 9e9c540a45ca..55b03d1ac8d2 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -95,6 +95,8 @@ static int uda1380_write(struct snd_soc_component *component, unsigned int reg,
{
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
u8 data[3];
+ unsigned int val;
+ int ret;
/* data is
* data[0] is register offset
@@ -113,21 +115,27 @@ static int uda1380_write(struct snd_soc_component *component, unsigned int reg,
if (!snd_soc_component_active(component) && (reg >= UDA1380_MVOL))
return 0;
pr_debug("uda1380: hw write %x val %x\n", reg, value);
- if (i2c_master_send(uda1380->i2c, data, 3) == 3) {
- unsigned int val;
- i2c_master_send(uda1380->i2c, data, 1);
- i2c_master_recv(uda1380->i2c, data, 2);
- val = (data[0]<<8) | data[1];
- if (val != value) {
- pr_debug("uda1380: READ BACK VAL %x\n",
- (data[0]<<8) | data[1]);
- return -EIO;
- }
- if (reg >= 0x10)
- clear_bit(reg - 0x10, &uda1380_cache_dirty);
- return 0;
- } else
+
+ ret = i2c_master_send(uda1380->i2c, data, 3);
+ if (ret != 3)
+ return ret < 0 ? ret : -EIO;
+
+ ret = i2c_master_send(uda1380->i2c, data, 1);
+ if (ret != 1)
+ return ret < 0 ? ret : -EIO;
+
+ ret = i2c_master_recv(uda1380->i2c, data, 2);
+ if (ret != 2)
+ return ret < 0 ? ret : -EIO;
+
+ val = (data[0] << 8) | data[1];
+ if (val != value)
return -EIO;
+
+ if (reg >= 0x10)
+ clear_bit(reg - 0x10, &uda1380_cache_dirty);
+
+ return 0;
}
static void uda1380_sync_cache(struct snd_soc_component *component)
--
2.43.0