linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: cio-dac: Fix max DAC write value check for 12-bit
@ 2023-03-11  0:22 William Breathitt Gray
  2023-03-11 12:35 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: William Breathitt Gray @ 2023-03-11  0:22 UTC (permalink / raw)
  To: jic23, lars; +Cc: linux-iio, linux-kernel, William Breathitt Gray, stable

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>
---
 drivers/iio/dac/cio-dac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/dac/cio-dac.c b/drivers/iio/dac/cio-dac.c
index 791dd999cf29..18a64f72fc18 100644
--- a/drivers/iio/dac/cio-dac.c
+++ b/drivers/iio/dac/cio-dac.c
@@ -66,8 +66,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;

base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: dac: cio-dac: Fix max DAC write value check for 12-bit
  2023-03-11  0:22 [PATCH] iio: dac: cio-dac: Fix max DAC write value check for 12-bit William Breathitt Gray
@ 2023-03-11 12:35 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2023-03-11 12:35 UTC (permalink / raw)
  To: William Breathitt Gray; +Cc: lars, linux-iio, linux-kernel, stable

On Fri, 10 Mar 2023 19:22:48 -0500
William Breathitt Gray <william.gray@linaro.org> wrote:

> 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>
Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/iio/dac/cio-dac.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/dac/cio-dac.c b/drivers/iio/dac/cio-dac.c
> index 791dd999cf29..18a64f72fc18 100644
> --- a/drivers/iio/dac/cio-dac.c
> +++ b/drivers/iio/dac/cio-dac.c
> @@ -66,8 +66,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;
> 
> base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-11 12:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11  0:22 [PATCH] iio: dac: cio-dac: Fix max DAC write value check for 12-bit William Breathitt Gray
2023-03-11 12:35 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).