]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: dac: max5821: fix return value check in powerdown sync
authorSalah Triki <salah.triki@gmail.com>
Mon, 27 Apr 2026 21:33:19 +0000 (22:33 +0100)
committerJonathan Cameron <jic23@kernel.org>
Fri, 15 May 2026 11:05:34 +0000 (12:05 +0100)
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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/dac/max5821.c

index e7e29359f8fe5a5c33c29a100b2ce381f2321f71..dd4e35460195a081ad0b714535e25dfaf6cd43a5 100644 (file)
@@ -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,