diff mbox series

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

Message ID 20230511004330.206942-1-marex@denx.de (mailing list archive)
State Accepted
Headers show
Series iio: dac: mcp4725: Fix i2c_master_send() return value handling | expand

Commit Message

Marek Vasut May 11, 2023, 12:43 a.m. UTC
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>
---
Cc: "Marek Behún" <kabel@kernel.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Benjamin Mugnier <benjamin.mugnier@foss.st.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Marek Vasut <marex@denx.de>
Cc: Maximilian Luz <luzmaximilian@gmail.com>
Cc: linux-iio@vger.kernel.org
---
 drivers/iio/dac/mcp4725.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Uwe Kleine-König May 11, 2023, 6:15 a.m. UTC | #1
On Thu, May 11, 2023 at 02:43:30AM +0200, Marek Vasut wrote:
> 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>

Makes sense,

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe
Jonathan Cameron May 13, 2023, 6:47 p.m. UTC | #2
On Thu, 11 May 2023 08:15:21 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> On Thu, May 11, 2023 at 02:43:30AM +0200, Marek Vasut wrote:
> > 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>  
> 
> Makes sense,
> 
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Applied to the fixes-togreg branch of iio.git and marked for
stable inclusion

Thanks,

Jonathan

> 
> Best regards
> Uwe
>
diff mbox series

Patch

diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index 46bf758760f85..3f5661a3718fe 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -47,12 +47,18 @@  static int mcp4725_suspend(struct device *dev)
 	struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	u8 outbuf[2];
+	int ret;
 
 	outbuf[0] = (data->powerdown_mode + 1) << 4;
 	outbuf[1] = 0;
 	data->powerdown = true;
 
-	return i2c_master_send(data->client, outbuf, 2);
+	ret = i2c_master_send(data->client, outbuf, 2);
+	if (ret < 0)
+		return ret;
+	else if (ret != 2)
+		return -EIO;
+	return 0;
 }
 
 static int mcp4725_resume(struct device *dev)
@@ -60,13 +66,19 @@  static int mcp4725_resume(struct device *dev)
 	struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	u8 outbuf[2];
+	int ret;
 
 	/* restore previous DAC value */
 	outbuf[0] = (data->dac_value >> 8) & 0xf;
 	outbuf[1] = data->dac_value & 0xff;
 	data->powerdown = false;
 
-	return i2c_master_send(data->client, outbuf, 2);
+	ret = i2c_master_send(data->client, outbuf, 2);
+	if (ret < 0)
+		return ret;
+	else if (ret != 2)
+		return -EIO;
+	return 0;
 }
 static DEFINE_SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend,
 				mcp4725_resume);