From patchwork Mon Jan 17 10:25:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 12715124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F47FC433F5 for ; Mon, 17 Jan 2022 10:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238558AbiAQKZV (ORCPT ); Mon, 17 Jan 2022 05:25:21 -0500 Received: from aposti.net ([89.234.176.197]:49620 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235846AbiAQKZV (ORCPT ); Mon, 17 Jan 2022 05:25:21 -0500 From: Paul Cercueil To: Jonathan Cameron , Lars-Peter Clausen Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Paul Cercueil , Lorenzo Bianconi Subject: [PATCH 1/2] iio: imu: st_lsm6dsx: Limit requested watermark value to hwfifo size Date: Mon, 17 Jan 2022 10:25:11 +0000 Message-Id: <20220117102512.31725-1-paul@crapouillou.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 --- 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 727b4b6ac696..5fd46bf1a11b 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 @@ -1607,8 +1608,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);