From: William Breathitt Gray Date: Thu, 6 Apr 2023 14:40:12 +0000 (-0400) Subject: iio: addac: stx104: Use define rather than hardcoded limit for write val X-Git-Tag: v6.6.17~5000^2~34^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46a4cac7f841a2a2cb397bcb2fd24324004c853e;p=platform%2Fkernel%2Flinux-rpi.git iio: addac: stx104: Use define rather than hardcoded limit for write val The DAC register is 16 bits wide, so the value passed by write_raw() should be checked against that limit. Rather than hardcoding the 16-bit maximum value limit, use a define to improve readability and make the intention of the code clearer. The explicit cast is also avoided by instead explicitly checking for negative values. Suggested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray Link: https://lore.kernel.org/r/4c9f4f1b4a270d133be70c82a091351b531b5e3e.1680790580.git.william.gray@linaro.org Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/addac/stx104.c b/drivers/iio/addac/stx104.c index 8730b79..0ed5f71 100644 --- a/drivers/iio/addac/stx104.c +++ b/drivers/iio/addac/stx104.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -181,8 +182,7 @@ static int stx104_write_raw(struct iio_dev *indio_dev, return 0; case IIO_CHAN_INFO_RAW: if (chan->output) { - /* DAC can only accept up to a 16-bit value */ - if ((unsigned int)val > 65535) + if (val < 0 || val > U16_MAX) return -EINVAL; mutex_lock(&priv->lock);