Skip to content

Commit 09d3bec

Browse files
Marek Vasutjic23
authored andcommitted
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: cf35ad6 ("iio: add mcp4725 I2C DAC driver") Signed-off-by: Marek Vasut <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 56cd3d1 commit 09d3bec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/iio/dac/mcp4725.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,38 @@ static int mcp4725_suspend(struct device *dev)
4747
struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
4848
to_i2c_client(dev)));
4949
u8 outbuf[2];
50+
int ret;
5051

5152
outbuf[0] = (data->powerdown_mode + 1) << 4;
5253
outbuf[1] = 0;
5354
data->powerdown = true;
5455

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;
5662
}
5763

5864
static int mcp4725_resume(struct device *dev)
5965
{
6066
struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
6167
to_i2c_client(dev)));
6268
u8 outbuf[2];
69+
int ret;
6370

6471
/* restore previous DAC value */
6572
outbuf[0] = (data->dac_value >> 8) & 0xf;
6673
outbuf[1] = data->dac_value & 0xff;
6774
data->powerdown = false;
6875

69-
return i2c_master_send(data->client, outbuf, 2);
76+
ret = i2c_master_send(data->client, outbuf, 2);
77+
if (ret < 0)
78+
return ret;
79+
else if (ret != 2)
80+
return -EIO;
81+
return 0;
7082
}
7183
static DEFINE_SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend,
7284
mcp4725_resume);

0 commit comments

Comments
 (0)