Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: dac: mcp4725: Fix i2c_master_send() return value handling

The i2c_master_send() returns number of sent bytes on success,
or negative on error. The suspend/resume callbacks expect zero
on success and non-zero on error. Adapt the return value of the
i2c_master_send() to the expectation of the suspend and resume
callbacks, including proper validation of the return value.

Fixes: cf35ad61aca2 ("iio: add mcp4725 I2C DAC driver")
Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230511004330.206942-1-marex@denx.de
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Marek Vasut and committed by
Jonathan Cameron
09d3bec7 56cd3d1c

+14 -2
+14 -2
drivers/iio/dac/mcp4725.c
··· 47 47 struct mcp4725_data *data = iio_priv(i2c_get_clientdata( 48 48 to_i2c_client(dev))); 49 49 u8 outbuf[2]; 50 + int ret; 50 51 51 52 outbuf[0] = (data->powerdown_mode + 1) << 4; 52 53 outbuf[1] = 0; 53 54 data->powerdown = true; 54 55 55 - return i2c_master_send(data->client, outbuf, 2); 56 + ret = i2c_master_send(data->client, outbuf, 2); 57 + if (ret < 0) 58 + return ret; 59 + else if (ret != 2) 60 + return -EIO; 61 + return 0; 56 62 } 57 63 58 64 static int mcp4725_resume(struct device *dev) ··· 66 60 struct mcp4725_data *data = iio_priv(i2c_get_clientdata( 67 61 to_i2c_client(dev))); 68 62 u8 outbuf[2]; 63 + int ret; 69 64 70 65 /* restore previous DAC value */ 71 66 outbuf[0] = (data->dac_value >> 8) & 0xf; 72 67 outbuf[1] = data->dac_value & 0xff; 73 68 data->powerdown = false; 74 69 75 - return i2c_master_send(data->client, outbuf, 2); 70 + ret = i2c_master_send(data->client, outbuf, 2); 71 + if (ret < 0) 72 + return ret; 73 + else if (ret != 2) 74 + return -EIO; 75 + return 0; 76 76 } 77 77 static DEFINE_SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend, 78 78 mcp4725_resume);