Skip to contentSkip to conversation

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.

PATCH In review Wenyuan Li 2 participants 2 messages Mar 24

Subsystems (2)
lore
Share & tools
lore

Wenyuan Li

author
#0 lore raw

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.

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.

---
 sound/soc/codecs/uda1380.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
sound/soc/codecs/uda1380.c +22 -14
index 9e9c540a45ca..55b03d1ac8d2 100644
@@ -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)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Wenyuan Li

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.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.1

Thanks!

[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.

      https://git.kernel.org/broonie/sound/c/071efde6b756
[2/2] ASoC: uda1380: use dev_err() and %pe for better error reporting
      https://git.kernel.org/broonie/sound/c/e5d5cc44791f

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark