Skip to content

Commit

Permalink
iio: dac: cio-dac: Fix max DAC write value check for 12-bit
Browse files Browse the repository at this point in the history
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: 3b8df5f ("iio: Add IIO support for the Measurement Computing CIO-DAC family")
Cc: [email protected]
Signed-off-by: William Breathitt Gray <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
vilhelmgray authored and gregkh committed Apr 20, 2023
1 parent 50aeb77 commit 8094711
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/iio/dac/cio-dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8094711

Please sign in to comment.