]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
iio: dac: ad5446: Fix ad5622_write() return value
authorPekka Korpinen <pekka.korpinen@iki.fi>
Wed, 29 Sep 2021 18:57:55 +0000 (21:57 +0300)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 13 Jan 2022 17:42:02 +0000 (18:42 +0100)
BugLink: https://bugs.launchpad.net/bugs/1953387
commit 558df982d4ead9cac628153d0d7b60feae05ddc8 upstream.

On success i2c_master_send() returns the number of bytes written. The
call from iio_write_channel_info(), however, expects the return value to
be zero on success.

This bug causes incorrect consumption of the sysfs buffer in
iio_write_channel_info(). When writing more than two characters to
out_voltage0_raw, the ad5446 write handler is called multiple times
causing unexpected behavior.

Fixes: 3ec36a2cf0d5 ("iio:ad5446: Add support for I2C based DACs")
Signed-off-by: Pekka Korpinen <pekka.korpinen@iki.fi>
Link: https://lore.kernel.org/r/20210929185755.2384-1-pekka.korpinen@iki.fi
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/iio/dac/ad5446.c

index 61c670f7fc5f13d76d440f7b0ffd14cf9ed8ea85..1f55cd8abb5585ad8bcf822798fffe2d6cf644e6 100644 (file)
@@ -527,8 +527,15 @@ static int ad5622_write(struct ad5446_state *st, unsigned val)
 {
        struct i2c_client *client = to_i2c_client(st->dev);
        __be16 data = cpu_to_be16(val);
+       int ret;
+
+       ret = i2c_master_send(client, (char *)&data, sizeof(data));
+       if (ret < 0)
+               return ret;
+       if (ret != sizeof(data))
+               return -EIO;
 
-       return i2c_master_send(client, (char *)&data, sizeof(data));
+       return 0;
 }
 
 /**