From 9e5b4cd2e9c0b1bd426bda633677eb870327faf5 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 17 Jan 2022 10:25:11 +0000 Subject: [PATCH] iio: imu: st_lsm6dsx: Limit requested watermark value to hwfifo size Instead of returning an error if the watermark value is too high, which the core will silently ignore anyway, limit the value to the hardware FIFO size; a lower-than-requested value is still better than using the default, which is usually 1. Cc: Lorenzo Bianconi Signed-off-by: Paul Cercueil Acked-by: Lorenzo Bianconi Link: https://lore.kernel.org/r/20220117102512.31725-1-paul@crapouillou.net Signed-off-by: Jonathan Cameron --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 6b268f1c5fc3c..b5e4a4113652c 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -1615,8 +1616,7 @@ int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val) struct st_lsm6dsx_hw *hw = sensor->hw; int err; - if (val < 1 || val > hw->settings->fifo_ops.max_size) - return -EINVAL; + val = clamp_val(val, 1, hw->settings->fifo_ops.max_size); mutex_lock(&hw->conf_lock); -- 2.30.2