Commit 558df982 authored by Pekka Korpinen's avatar Pekka Korpinen Committed by Jonathan Cameron

iio: dac: ad5446: Fix ad5622_write() return value

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: 3ec36a2c ("iio:ad5446: Add support for I2C based DACs")
Signed-off-by: default avatarPekka 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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 8fc4f038
......@@ -531,8 +531,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;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment