]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: uda1380: fix missing return value checks for I2C operations
authorWenyuan Li <2063309626@qq.com>
Tue, 24 Mar 2026 08:36:05 +0000 (16:36 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 24 Mar 2026 15:03:58 +0000 (15:03 +0000)
The driver currently ignores the return values of several I2C operations
during register writes, which could lead to silent failures and
inconsistent device state.

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@qq.com>
Link: https://patch.msgid.link/tencent_579D057AC557914CF739A2D9EAD045CE7306@qq.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/uda1380.c

index 9e9c540a45ca9720378fe45b55f790c665d81dbc..55b03d1ac8d2b78b971c5c14fb2c6418ae838673 100644 (file)
@@ -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)