public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] iio: dac: max5821: fix return value check in powerdown sync
@ 2026-04-27 21:33 Salah Triki
  2026-04-28  7:55 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Salah Triki @ 2026-04-27 21:33 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, Salah Triki

The function max5821_sync_powerdown_mode() returned the result of
i2c_master_send() directly. If a partial transfer occurred, it would
be incorrectly treated as a success by the caller.

While the caller currently handles the positive return value of 2 as
success, this patch refactors the function to return 0 on full success
and -EIO on short writes. This ensures robust error handling for
incomplete transfers and improves code maintainability by using
sizeof(outbuf).

Fixes: 472988972737 ("iio: add support of the max5821")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
Changes in v3:
- Remove blank lines

Changes in v2:
- Replace magic number '2' with 'sizeof(outbuf)' for better maintainability.
- Remove redundant blank line between i2c_master_send() and error check.
- Update commit message to clarify that the 'Fixes' tag is primarily for
  handling partial transfers (short writes), as the caller already
  handled the success case correctly.

 drivers/iio/dac/max5821.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index e7e29359f8fe..dd4e35460195 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -90,6 +90,7 @@ static int max5821_sync_powerdown_mode(struct max5821_data *data,
 				       const struct iio_chan_spec *chan)
 {
 	u8 outbuf[2];
+	int ret;
 
 	outbuf[0] = MAX5821_EXTENDED_COMMAND_MODE;
 
@@ -103,7 +104,13 @@ static int max5821_sync_powerdown_mode(struct max5821_data *data,
 	else
 		outbuf[1] |= MAX5821_EXTENDED_POWER_UP;
 
-	return i2c_master_send(data->client, outbuf, 2);
+	ret = i2c_master_send(data->client, outbuf, sizeof(outbuf));
+	if (ret < 0)
+		return ret;
+	if (ret != sizeof(outbuf))
+		return -EIO;
+
+	return 0;
 }
 
 static ssize_t max5821_write_dac_powerdown(struct iio_dev *indio_dev,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] iio: dac: max5821: fix return value check in powerdown sync
  2026-04-27 21:33 [PATCH v3] iio: dac: max5821: fix return value check in powerdown sync Salah Triki
@ 2026-04-28  7:55 ` Andy Shevchenko
  2026-04-28 16:12   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-28  7:55 UTC (permalink / raw)
  To: Salah Triki
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Mon, Apr 27, 2026 at 10:33:19PM +0100, Salah Triki wrote:
> The function max5821_sync_powerdown_mode() returned the result of
> i2c_master_send() directly. If a partial transfer occurred, it would
> be incorrectly treated as a success by the caller.
> 
> While the caller currently handles the positive return value of 2 as
> success, this patch refactors the function to return 0 on full success
> and -EIO on short writes. This ensures robust error handling for
> incomplete transfers and improves code maintainability by using
> sizeof(outbuf).

Makes sense, FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] iio: dac: max5821: fix return value check in powerdown sync
  2026-04-28  7:55 ` Andy Shevchenko
@ 2026-04-28 16:12   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-04-28 16:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Salah Triki, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Tue, 28 Apr 2026 10:55:45 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Apr 27, 2026 at 10:33:19PM +0100, Salah Triki wrote:
> > The function max5821_sync_powerdown_mode() returned the result of
> > i2c_master_send() directly. If a partial transfer occurred, it would
> > be incorrectly treated as a success by the caller.
> > 
> > While the caller currently handles the positive return value of 2 as
> > success, this patch refactors the function to return 0 on full success
> > and -EIO on short writes. This ensures robust error handling for
> > incomplete transfers and improves code maintainability by using
> > sizeof(outbuf).  
> 
> Makes sense, FWIW,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 

Applied and marked for stable.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-28 16:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 21:33 [PATCH v3] iio: dac: max5821: fix return value check in powerdown sync Salah Triki
2026-04-28  7:55 ` Andy Shevchenko
2026-04-28 16:12   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox