summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Breathitt Gray <william.gray@linaro.org>2023-03-10 19:22:48 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-20 12:02:10 +0200
commit7a1b666811aea3abeb5fd51833b88d2068e93b2d (patch)
tree332e48a0ada53605ac9bcd2b13c7d86b49d072f6
parentf2d27fe568cd5fb31eae4a2349668a02fb6fdfad (diff)
downloadlinux-7a1b666811aea3abeb5fd51833b88d2068e93b2d.tar.gz
linux-7a1b666811aea3abeb5fd51833b88d2068e93b2d.tar.bz2
linux-7a1b666811aea3abeb5fd51833b88d2068e93b2d.zip
iio: dac: cio-dac: Fix max DAC write value check for 12-bit
commit c3701185ee1973845db088d8b0fc443397ab0eb2 upstream. The CIO-DAC series of devices only supports DAC values up to 12-bit rather than 16-bit. Trying to write a 16-bit value results in only the lower 12 bits affecting the DAC output which is not what the user expects. Instead, adjust the DAC write value check to reject values larger than 12-bit so that they fail explicitly as invalid for the user. Fixes: 3b8df5fd526e ("iio: Add IIO support for the Measurement Computing CIO-DAC family") Cc: stable@vger.kernel.org Signed-off-by: William Breathitt Gray <william.gray@linaro.org> Link: https://lore.kernel.org/r/20230311002248.8548-1-william.gray@linaro.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/iio/dac/cio-dac.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/iio/dac/cio-dac.c b/drivers/iio/dac/cio-dac.c
index a8dffd938615..8b48f834d3b6 100644
--- a/drivers/iio/dac/cio-dac.c
+++ b/drivers/iio/dac/cio-dac.c
@@ -74,8 +74,8 @@ static int cio_dac_write_raw(struct iio_dev *indio_dev,
if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL;
- /* DAC can only accept up to a 16-bit value */
- if ((unsigned int)val > 65535)
+ /* DAC can only accept up to a 12-bit value */
+ if ((unsigned int)val > 4095)
return -EINVAL;
priv->chan_out_states[chan->channel] = val;