mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 03:24:19 +02:00
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. 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>
This commit is contained in:
parent
c369299895
commit
071efde6b7
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user