From patchwork Sun Feb 9 18:05:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967037 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 738431DED7B for ; Sun, 9 Feb 2025 18:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124408; cv=none; b=rjPAEOxOqJBprxFv/iyllXPbIwItMxwnXlrcaYaj6Q8dPhst70SaLK3B3XVKxSHdle8b28fwNeDUS28QmBSCymH8r3cfR2d5YlQdU8OgnvuyAs7bpC4SoE8uO3/O3Sqd24crhCbqgXMKEtkolC0ivXmKXm0DcAWXo+PaNk4HnZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124408; c=relaxed/simple; bh=qOTqh1nP4UcSxvI6b8/TEnuk9ArZHvSLvRZLr6Q7trc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hxNs6H4V+7nr8/jXkpW/eeOb9mAQ3HUv5KitAMY9VLJe/dyV0XI/3jDeKtylrjwOQ8m6NxPkIwjAVHjtOU0rlk5PhRqUuQ1alB3Gc09bqtBi5EO2jPYFEPaoBdAQnBicetBtLah+h5s6OHu/RWsS8TxpKcIM7EPDXFdh2G3UuYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fOc5JHj4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fOc5JHj4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C859FC4CEDD; Sun, 9 Feb 2025 18:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124408; bh=qOTqh1nP4UcSxvI6b8/TEnuk9ArZHvSLvRZLr6Q7trc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fOc5JHj4UEHKs6dNHDxOw6dvaJ9Qhp0l3GAkGBB11jQyQNa/WgMhgS+WOSGxNpYj7 dFLUXbUA7fel43t7kwwE+xrOo6WJGH49bb9NZS3XEkO4ex9SKRON4Dxc1hAK92kf7q imRzXa91w/FeCWwx9htXr3etts+Q4AsgE5GuFQYOftzTJwNpj67t4fuci5+S2Aq1VP pSi9w5J4LpWhqOByf0L45VaPyTe40ekTNSNi4wmCcX0ifd1iMqfu+0Q18jJlIM932e L7y1zsg6nrIAO38fvF08eC6/ARtgkxe1jH0P+S43YsxnQ/PyEoPRferEPbGk6YemgB 9KgTXtD/2sYBg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 01/27] iio: core: Rework claim and release of direct mode to work with sparse. Date: Sun, 9 Feb 2025 18:05:58 +0000 Message-ID: <20250209180624.701140-2-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Initial thought was to do something similar to __cond_lock() do_iio_device_claim_direct_mode(iio_dev) ? : ({ __acquire(iio_dev); 0; }) + Appropriate static inline iio_device_release_direct_mode() However with that, sparse generates false positives. E.g. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c:1811:17: warning: context imbalance in 'st_lsm6dsx_read_raw' - unexpected unlock So instead, this patch rethinks the return type and makes it more 'conditional lock like' (which is part of what is going on under the hood anyway) and return a boolean - true for successfully acquired, false for did not acquire. To allow a migration path given the rework is now non trivial, take a leaf out of the naming of the conditional guard we currently have for IIO device direct mode and drop the _mode postfix from the new functions giving iio_device_claim_direct() and iio_device_release_direct() Whilst the kernel supports __cond_acquires() upstream sparse does not yet do so. Hence rely on sparse expanding a static inline wrapper to explicitly see whether __acquire() is called. Note that even with the solution here, sparse sometimes gives false positives. However in the few cases seen they were complex code structures that benefited from simplification anyway. Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- v2: include linux/compiler_types.h (David) --- include/linux/iio/iio.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 56161e02f002..fe33835b19cf 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -662,6 +662,31 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); int iio_device_claim_direct_mode(struct iio_dev *indio_dev); void iio_device_release_direct_mode(struct iio_dev *indio_dev); +/* + * Helper functions that allow claim and release of direct mode + * in a fashion that doesn't generate many false positives from sparse. + * Note this must remain static inline in the header so that sparse + * can see the __acquire() marking. Revisit when sparse supports + * __cond_acquires() + */ +static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) +{ + int ret = iio_device_claim_direct_mode(indio_dev); + + if (ret) + return false; + + __acquire(iio_dev); + + return true; +} + +static inline void iio_device_release_direct(struct iio_dev *indio_dev) +{ + iio_device_release_direct_mode(indio_dev); + __release(indio_dev); +} + /* * This autocleanup logic is normally used via * iio_device_claim_direct_scoped(). From patchwork Sun Feb 9 18:05:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967038 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85D621E1C0F for ; Sun, 9 Feb 2025 18:06:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124416; cv=none; b=QFFIxDJzBuUqjD7aJXUI8QBJYh/0TYv8I7MWm2oWEj/8nqRn+U9y/JZEbNCqwuZMpP+DPD5iUbpfjROhyIgO6I/dC0rRdLatfxr8k4IKlj0cp1e8GWZIXp8H+LWTFceZAMGA1BP4HFnAtrCXuGSNS7O4WzCqDU+ibc+h+YcCWpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124416; c=relaxed/simple; bh=z9DhfTDN+CDBvEa9oZ5ue8if/eEG9pfn7ir8IVWFDWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vA1z5K3v8k+F3nORcqFaza3UquxitIhFa5cNrAVjdQUUfTf3UR1btADNM6CIidMfCNOsioxVnhLjVyuJVE/RGtzfUH+X+QrQsmvgxxZAdImmyK3BLaa7pD1SbcUVcg4FleqfG3cK8uz0soS3gYpgGB8rewXGPFPhndfEEjYSNK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ewO/ZAmp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ewO/ZAmp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0354C4CEDD; Sun, 9 Feb 2025 18:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124416; bh=z9DhfTDN+CDBvEa9oZ5ue8if/eEG9pfn7ir8IVWFDWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewO/ZAmp78PnEhg3RJ9HySkBKdbVxC3VZJWPClQf2zBqM9HybWfW7fZQCZjmFKrQZ 5FR8MLpLb/F/6pE87vw4OIPmd1KoUxrbHAUsAhArBWhhIDchgc2O8LciktjgosDV2j dbVgvYpRCKvxNL6WcotKD+/JY4LNcDH3W59/vxuLK9AzTC9eaNs3+hQVZWajKbIviG KNjjra7tXz1jp+bfLD3T/NLnS8wy2/Je9pcYmZg45YKfSEF9IzsxQLaaoYx0AzgsiG XZKVZszMYSZRXtP52+Wg4LyZANal6TvfYIpHYjOgvPa347NBJnreNNkHP2Fx1WiBTG b8x/pyaJvje8Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 02/27] iio: chemical: scd30: Use guard(mutex) to allow early returns Date: Sun, 9 Feb 2025 18:05:59 +0000 Message-ID: <20250209180624.701140-3-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Auto cleanup based release of the lock allows for simpler code flow in a few functions with large multiplexing style switch statements and no common operations following the switch. Suggested-by: David Lechner Cc: Tomasz Duszynski Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- v2: Fix include ordering (David) --- drivers/iio/chemical/scd30_core.c | 63 ++++++++++++++----------------- include/linux/iio/iio.h | 1 + 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c index d613c54cb28d..23ba46f7ca32 100644 --- a/drivers/iio/chemical/scd30_core.c +++ b/drivers/iio/chemical/scd30_core.c @@ -5,6 +5,7 @@ * Copyright (c) 2020 Tomasz Duszynski */ #include +#include #include #include #include @@ -198,112 +199,104 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const int *val, int *val2, long mask) { struct scd30_state *state = iio_priv(indio_dev); - int ret = -EINVAL; + int ret; u16 tmp; - mutex_lock(&state->lock); + guard(mutex)(&state->lock); switch (mask) { case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: if (chan->output) { *val = state->pressure_comp; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; } ret = iio_device_claim_direct_mode(indio_dev); if (ret) - break; + return ret; ret = scd30_read(state); if (ret) { iio_device_release_direct_mode(indio_dev); - break; + return ret; } *val = state->meas[chan->address]; iio_device_release_direct_mode(indio_dev); - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; *val2 = 1; - ret = IIO_VAL_INT_PLUS_MICRO; - break; + return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SAMP_FREQ: ret = scd30_command_read(state, CMD_MEAS_INTERVAL, &tmp); if (ret) - break; + return ret; *val = 0; *val2 = 1000000000 / tmp; - ret = IIO_VAL_INT_PLUS_NANO; - break; + return IIO_VAL_INT_PLUS_NANO; case IIO_CHAN_INFO_CALIBBIAS: ret = scd30_command_read(state, CMD_TEMP_OFFSET, &tmp); if (ret) - break; + return ret; *val = tmp; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; + default: + return -EINVAL; } - mutex_unlock(&state->lock); - - return ret; } static int scd30_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { struct scd30_state *state = iio_priv(indio_dev); - int ret = -EINVAL; + int ret; - mutex_lock(&state->lock); + guard(mutex)(&state->lock); switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: if (val) - break; + return -EINVAL; val = 1000000000 / val2; if (val < SCD30_MEAS_INTERVAL_MIN_S || val > SCD30_MEAS_INTERVAL_MAX_S) - break; + return -EINVAL; ret = scd30_command_write(state, CMD_MEAS_INTERVAL, val); if (ret) - break; + return ret; state->meas_interval = val; - break; + return 0; case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_PRESSURE: if (val < SCD30_PRESSURE_COMP_MIN_MBAR || val > SCD30_PRESSURE_COMP_MAX_MBAR) - break; + return -EINVAL; ret = scd30_command_write(state, CMD_START_MEAS, val); if (ret) - break; + return ret; state->pressure_comp = val; - break; + return 0; default: - break; + return -EINVAL; } - break; case IIO_CHAN_INFO_CALIBBIAS: if (val < 0 || val > SCD30_TEMP_OFFSET_MAX) - break; + return -EINVAL; /* * Manufacturer does not explicitly specify min/max sensible * values hence check is omitted for simplicity. */ - ret = scd30_command_write(state, CMD_TEMP_OFFSET / 10, val); + return scd30_command_write(state, CMD_TEMP_OFFSET / 10, val); + default: + return -EINVAL; } - mutex_unlock(&state->lock); - - return ret; } static int scd30_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index fe33835b19cf..5ed03e36178f 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include /* IIO TODO LIST */ From patchwork Sun Feb 9 18:06:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967039 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52E311E0DE3 for ; Sun, 9 Feb 2025 18:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124424; cv=none; b=gTkEU182pJBvGGNcl3W+XlUQx4iW+jxBOR2ZO1WaTuLbFUUVkyFwUAZ3upD7VZfPHn3GcfpqRDN16xCf7fUZCrX9Ney4203yAhqQwXGK9JSaotmJWSymKYUdStaRbRLpNr6pGer3PJqAbQB95y8O89nnOO6po/rKaE4K7xzXFoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124424; c=relaxed/simple; bh=n96MC2iUeimgWw2sg+uOKbdsiUONkbRku1hmdXi3aVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWuE50CRSg5HHNfrr3Nza5doZeDe8GbKETgJoO5uJ/9jD58G61MDPDEvM5psaHkWYgIKAROl4lAd8DdxRJkzZXiIzZX6kAQ2zMmNzK49rh8auTa0ga8NnNlIfGYjp7G3Ky4xxxgmXZZ0QVf9NUSBh89Oviu8uAlMY1c6c5VygmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ISxs38j5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ISxs38j5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2B5FC4CEE9; Sun, 9 Feb 2025 18:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124423; bh=n96MC2iUeimgWw2sg+uOKbdsiUONkbRku1hmdXi3aVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ISxs38j5284wEw1Qji4FRaTfxAok2yk67+5lcqFeRiB4G6JCiHAXuhExfUXbBv14e U8LR7lBEFJzM111GrsHETXO9tHGLo8jJr3mn7FfnwZAv6FI2rqj0GV9mNLJRdKnGOt DVeGRkiv9lSIcrdl/gM9P06vJSGKtC6bk9JlURzbKfBfSIONJpDNlxSYXrCNl3n7bX QrSSxXZrxTXx0p2ET8DxYsDP8oHgQUVSbrtCXC4lyPMUXMQeVVn8NVnXgT4+Ur07Rm ZPqqgzueOEi4vAl3z4Tmzw5zVeVyLeJ9rHXvot4Pk8H5nzTN//o+dk4u8yvO2ObGLi rB6I2MePkyL5w== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 03/27] iio: chemical: scd30: Switch to sparse friendly claim/release_direct() Date: Sun, 9 Feb 2025 18:06:00 +0000 Message-ID: <20250209180624.701140-4-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This driver caused a false positive with __cond_lock() style solution but is fine with the simple boolean return approach now used. Cc: Tomasz Duszynski Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/scd30_core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c index 23ba46f7ca32..3fed6b63710f 100644 --- a/drivers/iio/chemical/scd30_core.c +++ b/drivers/iio/chemical/scd30_core.c @@ -211,18 +211,17 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const return IIO_VAL_INT; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = scd30_read(state); if (ret) { - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } *val = state->meas[chan->address]; - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; From patchwork Sun Feb 9 18:06:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967040 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE61E1E131B for ; Sun, 9 Feb 2025 18:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124431; cv=none; b=eDwrFZ2JUcIgNxqwN9dolip/KcoALpOXJw84KNOgyRyF9pyTCGHI4uPljjiGMpEDRlRsyvidIA+b31uPGo0j3tYvgNhHfO0Oajh6M/5BtXx8MtvM3HAmk/oqyQLGBt5oASwG06XjdQtBQRT2c9xYmk9TEI/ESI3BEnd45Viz4U8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124431; c=relaxed/simple; bh=OM2Rk3PF+V8cR1qNXas+EjCz5a6Nm5ozRcl4dNshXsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eTpBbU8MEuEwS3ZBVKdofOhtNobJ2N8hjD7lCHpxXV6C1TFMwQQr9a70fCgGoNIAxR6mS26ncfsjlOb1k5B6a9qcMPzubhTz7FLHvBhDRBXlg6Z8PnD21LnilLLpFmICqeIzWHC6C51Du6s4lG2cBkKJuGBdDFMioCdB+eBiWdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SA6c5juv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SA6c5juv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87369C4CEDD; Sun, 9 Feb 2025 18:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124431; bh=OM2Rk3PF+V8cR1qNXas+EjCz5a6Nm5ozRcl4dNshXsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SA6c5juvwOj5M6uQ7rGT9PsAE3+mKh5hQv9ne1OTFDfFHihIWIhbCthEJKhSTXiCL jTzrv6MXFRqm6BSWLlnMMOWMT5QKizen6Tv046GVRXs2WZPctjDp7hIgMd6GnT0vff 31ETyXAzgK3i4ty4p+W4u34vwg1nJFyh1DUh0bdSMX3b2RUpYfibjNXTZ4oEGPkAgB QfYDss50jghWSEpcRdIntxplMmoYrMgzzDopZei0dDzzbDswC8M3Z0rIaPF4JBYTW3 c3WPa6sMcUUmWik2o19DVBEvN8Y3aMN0Z/ky/Jtib4DhpsQxUQ/jKk9KUZy+r5a1Pu gE8PC0lswzrLg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 04/27] iio: temperature: tmp006: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:01 +0000 Message-ID: <20250209180624.701140-5-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Antoni Pokusinski Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/tmp006.c | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index 1998047a1f24..b5c94b7492f5 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -85,19 +85,25 @@ static int tmp006_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: if (channel->type == IIO_VOLTAGE) { /* LSB is 156.25 nV */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = tmp006_read_measurement(data, TMP006_VOBJECT); - if (ret < 0) - return ret; - } + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = tmp006_read_measurement(data, TMP006_VOBJECT); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + *val = sign_extend32(ret, 15); } else if (channel->type == IIO_TEMP) { /* LSB is 0.03125 degrees Celsius */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = tmp006_read_measurement(data, TMP006_TAMBIENT); - if (ret < 0) - return ret; - } + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = tmp006_read_measurement(data, TMP006_TAMBIENT); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + *val = sign_extend32(ret, 15) >> TMP006_TAMBIENT_SHIFT; } else { break; @@ -142,9 +148,8 @@ static int tmp006_write_raw(struct iio_dev *indio_dev, for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) if ((val == tmp006_freqs[i][0]) && (val2 == tmp006_freqs[i][1])) { - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; data->config &= ~TMP006_CONFIG_CR_MASK; data->config |= i << TMP006_CONFIG_CR_SHIFT; @@ -153,7 +158,7 @@ static int tmp006_write_raw(struct iio_dev *indio_dev, TMP006_CONFIG, data->config); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } return -EINVAL; From patchwork Sun Feb 9 18:06:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967041 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A371E0E01 for ; Sun, 9 Feb 2025 18:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124440; cv=none; b=MJiaifOa4v9t6WWYw9Lor4I6qmV/1h5PXklDu0hth9700LvHl1NXv5LlOU/qjZ49IixWqA9TtpWfnZfbwIg9LEu1lLesySCeu5GNI4/mBcT0rUR3Z/dOgD2Or5tAybfo1DtFMWU/O6UBm4RWUkdT7f7aa+eQgGJ5QOR5azrkHAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124440; c=relaxed/simple; bh=yXyP8eoChheH5LttgrfaEdzmbV8A2lU8DQ/z1oGP9V4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=snyVEd6m261wd2eoH1DxcnCDXjMMJiOmfShBuLm45o83gceEg7qbo1y7oRYA4dOx5mDQA+45YBMSbyNIxj3VSumMAsTmGGi1hjCpz60PGKTy9uWDODWv46z8FHmWPJAW7nUMAtB9pMjhYJznQB5GueTOkqsbRbY0jf2yb5J4cWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=erqfm5s6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="erqfm5s6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83959C4CEE5; Sun, 9 Feb 2025 18:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124439; bh=yXyP8eoChheH5LttgrfaEdzmbV8A2lU8DQ/z1oGP9V4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=erqfm5s65A5nZCR4hhIe8x9XVe8alUmgR+u/SQaFAYLrKU1YiI98TNyoB5Y6/uHY0 kZJKopvKGZKXW90qqLbS6yUzuIOgXytxu/eDVJAlQDfX++7bZS0jWC8Nr1e9WUVEUe bKY3bowzgWjN32ZhOLKqzRDi0PDL9AyL1NcSypVj0A4FlbJ+XEumiOcnCL/agNl8FY oSB+3NfCdGqrgmQhlqxBi+e3OVeQw1U4FT19XvjM0iuwFV/DMYYYgMJPpaTfoWfewd FcFDBdYES+uYK9D1xT24i4NWKE2zIAMBDyrUuD9D5OWPiDoLC7a6SlmuC0qThbrwyR kFZHsDE8rlwlQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 05/27] iio: proximity: sx9310: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:02 +0000 Message-ID: <20250209180624.701140-6-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: Gwendal Grignou Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9310.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 0d7f0518d4fb..b60707eba39d 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -337,19 +337,26 @@ static int sx9310_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; if (chan->type != IIO_PROXIMITY) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9310_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9310_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9310_read_samp_freq(data, val, val2); default: From patchwork Sun Feb 9 18:06:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967042 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F5CD1DFD9F for ; Sun, 9 Feb 2025 18:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124446; cv=none; b=hohE1ot50YLbJfHAJyHTiF+09fTnpoda+SBt04MnMqQr3jYUyhLFH4rndeOZvI2ZIElV3vM14J6x7nrqtPCJ/Z9WUN+h6c7KLmNSG//X+zPw20vCGLGl/JoL5hdz04CWkRC3O7AuXGIT2K259EdaCv3vP/SomSKZKk35TZBQW7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124446; c=relaxed/simple; bh=HlF5z8uFrHezw3K4M6X7Z8yJb59Y8sk5PDWTPY1oZfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBDSCpKSkhBtrlKjtnhk09J4YD2g7GAiDbhYeC5r9l6TTKbODV9THMTAKBZvRqlHY3DREh8Zzrth7zLOPmJQ3QMEkUdTwn3tYt+eLbLHKZzhVNpRbp32HrrzhKFujhtSy7Yq5GcqkfaodGsIIWYnU59brWjGjMENHsj52fvGc8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rlXeQiPH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rlXeQiPH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACA3BC4CEDD; Sun, 9 Feb 2025 18:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124445; bh=HlF5z8uFrHezw3K4M6X7Z8yJb59Y8sk5PDWTPY1oZfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rlXeQiPHliLEuM7NN78aCev/QCtzSjjwokFttbD2vc0/7KYYmSKBp2g0m/sLwdlqY rsiXZTstLAEK35smm4E3XPUqGafMFG7vzf+WGMcvyd5b70E08bqsZYATPJWYv6hw6E OXn/sYjxYToxnUNFvMD9Fq1p6rmdf1wpmtVt9rItfe7e4dkZ2y2NHcrJSCMBblLlG6 HBpawXLa/9SRlB7tYIsXSBIbgMrazCNrcopYpxZDOr68UFc5FPnec3YsOym8/UpZh9 YPlXlMj0ij9my85wXIO4dPgz4nFhtj74NqNxpFliOePQUFXdcw3R59IehlYZakNLow sGe0nWu0mx+ng== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 06/27] iio: proximity: sx9324: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:03 +0000 Message-ID: <20250209180624.701140-7-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context Reviewed-by: Gwendal Grignou Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9324.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c index f7819dd2775c..73d972416c01 100644 --- a/drivers/iio/proximity/sx9324.c +++ b/drivers/iio/proximity/sx9324.c @@ -429,16 +429,23 @@ static int sx9324_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9324_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9324_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9324_read_samp_freq(data, val, val2); default: From patchwork Sun Feb 9 18:06:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967043 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AEAA1E0E14 for ; Sun, 9 Feb 2025 18:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124453; cv=none; b=tcJ6t8H/jpLDu7YbdggwKEvM+Es62jPFoHv2are/tmSfeXu08P/aAa2QV8qRoud+gnrWXyYX9vGKQXlB0mhgErFR5GrIhnpLb8FQJLTgG1LvZ+D/i2caum1oIHhaIC/mLPEhQ0wSoLss/ELT+6i8Hc+iZOHSAZEJF+iUpgz4vmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124453; c=relaxed/simple; bh=G6jkkNvXb35keFn/+FKv0VCVhqiIl5HXp2F2/4h9VPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p3PmEvkf2oj01sfApwXEFS5QK7YxwSwupr91dW/m5clcRZWQUBNssi1Q/eB4+nukA7H0zYjYIwi2wn5ospvihZKngiNGZPTq5u1UzF23rIE52r/ukKbg7JJ7x+b00/3OwWB7H9CIup0Fy1rXHaMrmVxrzo44YBIM2wfh7qm6Nqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zzg1haYf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zzg1haYf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89E13C4CEDD; Sun, 9 Feb 2025 18:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124453; bh=G6jkkNvXb35keFn/+FKv0VCVhqiIl5HXp2F2/4h9VPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zzg1haYfl99McnwKkdPaEuDeNQrHsR0B/QaU1nXhTwNyibkQ2CzpUIoIgFh7DSNbP nGi6ksB3HGorgHfj3cTvbyYFjaYq8lbog/58d/Ap0OKuxMXK4Fd7VDwtlWk/UDKk3I QpmYIk/v+19EfokLn7mDNbyxqg/jk+0yzRb9fGxvzgOoQP0uB7glPELH/67UDMa7De Cu2IFZpaBOOTVKTlsnRcdnoJVNe2RRQEyLBopr2jDnH7Ql1xmPZ5NQ8ZCroFvBt+k5 hJQdQtLLAM9F6Q5ewPJ/vmG6Lg++ezF9lLqgTJBuKT2LURVYaVldnlA6Vn56m+YElt zkaoo1rcxmrqw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 07/27] iio: proximity: sx9360: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:04 +0000 Message-ID: <20250209180624.701140-8-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context Reviewed-by: Gwendal Grignou Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9360.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c index a6ff16e33c1e..4448988d4e7e 100644 --- a/drivers/iio/proximity/sx9360.c +++ b/drivers/iio/proximity/sx9360.c @@ -321,16 +321,23 @@ static int sx9360_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9360_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9360_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9360_read_samp_freq(data, val, val2); default: From patchwork Sun Feb 9 18:06:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967044 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C14E1E0E01 for ; Sun, 9 Feb 2025 18:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124462; cv=none; b=FHTM3MuNW7O/6j0/LzkMNlyJyHSko9sRTX76LnoHKwGeEjDMmw8g/0zw6Acqb9zqEqXrcWYiDs5qWHAANk14Gx2XWm8XGyE4MxnlXZ27pne8mM+xgGOYLBsUZY2nAVqgnXs00k6fQ5QTCH9BTgwaQaavCKVck90Ea6zB3bNRIz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124462; c=relaxed/simple; bh=yR5Rcuszco9q7qJh5bH9jJDFxXUABvUrFpU0Snzfa5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fHKN0vRIgHIDD6H8dBi+yJTg0MNZUxIE1qe2TIe7nHSZrKPNiZ3JZUYFLdOuSwC5Yf7xUxK8i4of534xOMqs2KUUwKz+l7nNS1RuEckd9mjqe1qpfHHziffqIog8oBJoc4X9TJDXfE9X0aN1e+nGSrqz9m/rh5H3mz+iyG36vQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TnxqPhyT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TnxqPhyT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C11DC4CEDD; Sun, 9 Feb 2025 18:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124461; bh=yR5Rcuszco9q7qJh5bH9jJDFxXUABvUrFpU0Snzfa5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TnxqPhyTFPzjRKdq+0MxRssDszcs1HVlL+8cZaGB9W6veF8Eco6/A/kPQVR7YSlMc gLOGEVsuv3yv5pO5ircBE8ewDXskIJ1fPsZiXQ0mVFeEQXXdxOgVt6E79r3qiOfUgg EUyGgewmGp6rvyZ22aAYSs2Ziaf4DkY0dd+HsbF60q0O5llIoZ8XNfBB2tTI5cPy0h T+J+3PSCOmurw82QHqcOSEnLsrluOzuT/6jYwN/krBhFeqy08awS/rlXi5Z7raY5z9 traNJ7ynfOSlQsVx6tygX8s4zeagWZ8BM4h0xPucnrDaRY+tkHDK7Noseb2M4xrSre 1ll0QTcwzi1VQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 08/27] iio: accel: adxl367: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:05 +0000 Message-ID: <20250209180624.701140-9-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context In some cases there is a convenient wrapper function to which the handling can be moved. Do that instead of introducing another layer of wrappers. In others an outer wrapper is added which claims direct mode, runs the original function with the scoped claim logic removed, releases direct mode and then checks for errors. Cc: Cosmin Tanislav Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/accel/adxl367.c | 194 ++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 88 deletions(-) diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c index a48ac0d7bd96..add4053e7a02 100644 --- a/drivers/iio/accel/adxl367.c +++ b/drivers/iio/accel/adxl367.c @@ -477,45 +477,42 @@ static int adxl367_set_fifo_watermark(struct adxl367_state *st, static int adxl367_set_range(struct iio_dev *indio_dev, enum adxl367_range range) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - ret = regmap_update_bits(st->regmap, ADXL367_REG_FILTER_CTL, - ADXL367_FILTER_CTL_RANGE_MASK, - FIELD_PREP(ADXL367_FILTER_CTL_RANGE_MASK, - range)); - if (ret) - return ret; + ret = regmap_update_bits(st->regmap, ADXL367_REG_FILTER_CTL, + ADXL367_FILTER_CTL_RANGE_MASK, + FIELD_PREP(ADXL367_FILTER_CTL_RANGE_MASK, + range)); + if (ret) + return ret; - adxl367_scale_act_thresholds(st, st->range, range); + adxl367_scale_act_thresholds(st, st->range, range); - /* Activity thresholds depend on range */ - ret = _adxl367_set_act_threshold(st, ADXL367_ACTIVITY, - st->act_threshold); - if (ret) - return ret; + /* Activity thresholds depend on range */ + ret = _adxl367_set_act_threshold(st, ADXL367_ACTIVITY, + st->act_threshold); + if (ret) + return ret; - ret = _adxl367_set_act_threshold(st, ADXL367_INACTIVITY, - st->inact_threshold); - if (ret) - return ret; + ret = _adxl367_set_act_threshold(st, ADXL367_INACTIVITY, + st->inact_threshold); + if (ret) + return ret; - ret = adxl367_set_measure_en(st, true); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, true); + if (ret) + return ret; - st->range = range; + st->range = range; - return 0; - } - unreachable(); + return 0; } static int adxl367_time_ms_to_samples(struct adxl367_state *st, unsigned int ms) @@ -620,23 +617,20 @@ static int _adxl367_set_odr(struct adxl367_state *st, enum adxl367_odr odr) static int adxl367_set_odr(struct iio_dev *indio_dev, enum adxl367_odr odr) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - ret = _adxl367_set_odr(st, odr); - if (ret) - return ret; + ret = _adxl367_set_odr(st, odr); + if (ret) + return ret; - return adxl367_set_measure_en(st, true); - } - unreachable(); + return adxl367_set_measure_en(st, true); } static int adxl367_set_temp_adc_en(struct adxl367_state *st, unsigned int reg, @@ -725,32 +719,29 @@ static int adxl367_read_sample(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - u16 sample; - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + u16 sample; + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_temp_adc_reg_en(st, chan->address, true); - if (ret) - return ret; + ret = adxl367_set_temp_adc_reg_en(st, chan->address, true); + if (ret) + return ret; - ret = regmap_bulk_read(st->regmap, chan->address, &st->sample_buf, - sizeof(st->sample_buf)); - if (ret) - return ret; + ret = regmap_bulk_read(st->regmap, chan->address, &st->sample_buf, + sizeof(st->sample_buf)); + if (ret) + return ret; - sample = FIELD_GET(ADXL367_DATA_MASK, be16_to_cpu(st->sample_buf)); - *val = sign_extend32(sample, chan->scan_type.realbits - 1); + sample = FIELD_GET(ADXL367_DATA_MASK, be16_to_cpu(st->sample_buf)); + *val = sign_extend32(sample, chan->scan_type.realbits - 1); - ret = adxl367_set_temp_adc_reg_en(st, chan->address, false); - if (ret) - return ret; + ret = adxl367_set_temp_adc_reg_en(st, chan->address, false); + if (ret) + return ret; - return IIO_VAL_INT; - } - unreachable(); + return IIO_VAL_INT; } static int adxl367_get_status(struct adxl367_state *st, u8 *status, @@ -852,10 +843,15 @@ static int adxl367_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long info) { struct adxl367_state *st = iio_priv(indio_dev); + int ret; switch (info) { case IIO_CHAN_INFO_RAW: - return adxl367_read_sample(indio_dev, chan, val); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = adxl367_read_sample(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ACCEL: { @@ -912,7 +908,12 @@ static int adxl367_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - return adxl367_set_odr(indio_dev, odr); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = adxl367_set_odr(indio_dev, odr); + iio_device_release_direct(indio_dev); + return ret; } case IIO_CHAN_INFO_SCALE: { enum adxl367_range range; @@ -921,7 +922,12 @@ static int adxl367_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - return adxl367_set_range(indio_dev, range); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = adxl367_set_range(indio_dev, range); + iio_device_release_direct(indio_dev); + return ret; } default: return -EINVAL; @@ -1069,13 +1075,15 @@ static int adxl367_read_event_config(struct iio_dev *indio_dev, } } -static int adxl367_write_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - bool state) +static int __adxl367_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + bool state) { + struct adxl367_state *st = iio_priv(indio_dev); enum adxl367_activity_type act; + int ret; switch (dir) { case IIO_EV_DIR_RISING: @@ -1088,28 +1096,38 @@ static int adxl367_write_event_config(struct iio_dev *indio_dev, return -EINVAL; } - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + guard(mutex)(&st->lock); + + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - guard(mutex)(&st->lock); + ret = adxl367_set_act_interrupt_en(st, act, state); + if (ret) + return ret; - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_act_en(st, act, state ? ADCL367_ACT_REF_ENABLED + : ADXL367_ACT_DISABLED); + if (ret) + return ret; - ret = adxl367_set_act_interrupt_en(st, act, state); - if (ret) - return ret; + return adxl367_set_measure_en(st, true); +} - ret = adxl367_set_act_en(st, act, state ? ADCL367_ACT_REF_ENABLED - : ADXL367_ACT_DISABLED); - if (ret) - return ret; +static int adxl367_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + bool state) +{ + int ret; - return adxl367_set_measure_en(st, true); - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __adxl367_write_event_config(indio_dev, chan, type, dir, state); + iio_device_release_direct(indio_dev); + return ret; } static ssize_t adxl367_get_fifo_enabled(struct device *dev, From patchwork Sun Feb 9 18:06:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967045 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B3F1E1A2B for ; Sun, 9 Feb 2025 18:07:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124469; cv=none; b=If3JaCZw1INIr3X6BzH6GTJtsOMl36x6K7iWVzYtTFae/9f/CAzAG8fzRjFON58v58zYLoWgWnb1SEWdXeflanwzZMsQK4kXw/KWAD4sxnMw2ZRm4pqa+C3mM4xNVUDZWtWapMrIfej/6Pb8MAyYc32hR0ZGIMl4Wy2f0sBD3hY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124469; c=relaxed/simple; bh=DLpIYt/ksN5P4PN4RcM/NnL8kBMSpcEAcUbw/tgDVSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PGtaDubK6kC5hc5J9dRbqZlbLDZHhgU0RrTf1tb6CPbgmQH54XKg/eLDzXWNVwwUkd88JgzfCO9Eg+NbU+3N8iXLHTyD+GlvY5WnfIhHsZAe10alS8CQmNH7221uWiejuAtYM/daoM/tGBqYr1ZaWizFnr/VI5JJ/Np5HXx2i8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YIPvzdhV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YIPvzdhV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0CF6C4CEDF; Sun, 9 Feb 2025 18:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124468; bh=DLpIYt/ksN5P4PN4RcM/NnL8kBMSpcEAcUbw/tgDVSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIPvzdhVANgg6/rH5oMfrRyN4NspD9tYURnDEFWa6Jcl902EYNRodAohH3Ff/Eqyr JV8qcQqeMWVc4GZMDi29wI/H/566Ook9pSO02hvj5/Cp0HU6QZkmW6NfbOjmKPhe09 eP0vOL30wvf0pIfe3/gSgIcxTjFKxTsxAx1dW6fLvAUq+EkZadsQ8Vo7gh7Lp0STIG G6l4bxwUNi8GVcESPCVnkHfsl7iRPplsyauvnMjC151XKEbrSVsFHIPPKASA0hA6Dz HrSYcUhjcrnJygjn8hbmjNDsNYDKOA2ND54aXCTdHGv/PeSD6hhAWXUXJqC7FM8vKF XdRUF7Fpptrxw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 09/27] iio: adc: ad4000: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:06 +0000 Message-ID: <20250209180624.701140-10-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: Marcelo Schmitt Tested-by: Marcelo Schmitt Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad4000.c | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c index 1d556a842a68..4fe8dee48da9 100644 --- a/drivers/iio/adc/ad4000.c +++ b/drivers/iio/adc/ad4000.c @@ -535,12 +535,16 @@ static int ad4000_read_raw(struct iio_dev *indio_dev, int *val2, long info) { struct ad4000_state *st = iio_priv(indio_dev); + int ret; switch (info) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad4000_single_conversion(indio_dev, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = ad4000_single_conversion(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: *val = st->scale_tbl[st->span_comp][0]; *val2 = st->scale_tbl[st->span_comp][1]; @@ -585,36 +589,46 @@ static int ad4000_write_raw_get_fmt(struct iio_dev *indio_dev, } } -static int ad4000_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int val, int val2, - long mask) +static int __ad4000_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val2) { struct ad4000_state *st = iio_priv(indio_dev); unsigned int reg_val; bool span_comp_en; int ret; - switch (mask) { - case IIO_CHAN_INFO_SCALE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); + + ret = ad4000_read_reg(st, ®_val); + if (ret < 0) + return ret; + + span_comp_en = val2 == st->scale_tbl[1][1]; + reg_val &= ~AD4000_CFG_SPAN_COMP; + reg_val |= FIELD_PREP(AD4000_CFG_SPAN_COMP, span_comp_en); - ret = ad4000_read_reg(st, ®_val); - if (ret < 0) - return ret; + ret = ad4000_write_reg(st, reg_val); + if (ret < 0) + return ret; - span_comp_en = val2 == st->scale_tbl[1][1]; - reg_val &= ~AD4000_CFG_SPAN_COMP; - reg_val |= FIELD_PREP(AD4000_CFG_SPAN_COMP, span_comp_en); + st->span_comp = span_comp_en; + return 0; +} - ret = ad4000_write_reg(st, reg_val); - if (ret < 0) - return ret; +static int ad4000_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + int ret; - st->span_comp = span_comp_en; - return 0; - } - unreachable(); + switch (mask) { + case IIO_CHAN_INFO_SCALE: + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ad4000_write_raw(indio_dev, chan, val2); + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Feb 9 18:06:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967046 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 651CE1E04B9 for ; Sun, 9 Feb 2025 18:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124476; cv=none; b=sMX2ETc1ybuQsfGnbxlt1krVO6/ohNoa0dLhPf+vbA+wZ+vUPIiUOD1ZpQQ0a/jf5jmqFTZXcIqTImfFFCqPO9wzHxWHsO8hB8XOw/4/q4MczHIbpzCno01ZT6bYcCPPAnUI8Iz25X/nQivFp9KmD4Biavyot7pX9iwdZ9vq6gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124476; c=relaxed/simple; bh=4IpfLRZ5I0wsh95AQTJdt9kBCJhifdBhs6msRsfrKbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MFHBZ0ebVee3lvL5DifY5r13xz+FSZxq+vuHW/DZtMr6bNARCYbXP8TnHCGXVHmg8XkIhoUKU/xJLRcIBXQ5Wa7iNLSafrstHACzJGh6KMgRg7/6biTjmkLV+C+Y4XuOAku//XsX/wQH8FN7e0cqDeJYlq4or1pCt7C0QYOlRfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k/RLcYs9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k/RLcYs9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31065C4CEE5; Sun, 9 Feb 2025 18:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124475; bh=4IpfLRZ5I0wsh95AQTJdt9kBCJhifdBhs6msRsfrKbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k/RLcYs9/0m6wJb0y2v+vi0lZeEuqyvc6DrWvknuMkvgHaLFHpnKZj5XiG6ZajA/7 DhYef50MHr51eQDsivddsWtSh9jZk7ZKmg3Xb89m4tTZ6cBnePEKPJOA7en/tWqoCY VewnuCGHsNXZ7JJtElVQ7d30sK+BthJPaX9hpN8KmVWG1MxD4NyK/FB92G6Hodcnzz tlTTYj1qjYCnqMkxGNZGitsILg8c9mPePOt32XAtPRHghoiHxtHtViPiCOHGUiQ/WQ Ddf0pMrEPOw/u6lYSiHkOGZJPThWRHHdZSdpGZs2dvC/U69PqBDHF+V4DYk/991zeZ iK4KX4t/LnbxQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 10/27] iio: adc: ad4130: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:07 +0000 Message-ID: <20250209180624.701140-11-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Cosmin Tanislav Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad4130.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c index acc241cc0a7a..061eeb9b1f8d 100644 --- a/drivers/iio/adc/ad4130.c +++ b/drivers/iio/adc/ad4130.c @@ -1067,13 +1067,11 @@ static int _ad4130_read_sample(struct iio_dev *indio_dev, unsigned int channel, static int ad4130_read_sample(struct iio_dev *indio_dev, unsigned int channel, int *val) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct ad4130_state *st = iio_priv(indio_dev); + struct ad4130_state *st = iio_priv(indio_dev); - guard(mutex)(&st->lock); - return _ad4130_read_sample(indio_dev, channel, val); - } - unreachable(); + guard(mutex)(&st->lock); + + return _ad4130_read_sample(indio_dev, channel, val); } static int ad4130_read_raw(struct iio_dev *indio_dev, @@ -1083,10 +1081,16 @@ static int ad4130_read_raw(struct iio_dev *indio_dev, struct ad4130_state *st = iio_priv(indio_dev); unsigned int channel = chan->scan_index; struct ad4130_setup_info *setup_info = &st->chans_info[channel].setup; + int ret; switch (info) { case IIO_CHAN_INFO_RAW: - return ad4130_read_sample(indio_dev, channel, val); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = ad4130_read_sample(indio_dev, channel, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: { guard(mutex)(&st->lock); *val = st->scale_tbls[setup_info->ref_sel][setup_info->pga][0]; From patchwork Sun Feb 9 18:06:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967047 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D54051E0DE3 for ; Sun, 9 Feb 2025 18:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124483; cv=none; b=sPLmcq/quZ9Y9bsCEDU2QPKCIWYdGKvPl8FUQnbVZtzeBHD5vLabyJTFaIhMEpXoB3riR7f7Q4VQYDAyn9TTW0qgKXPs+oKfG5yQpM6NvFdtHY8A339V2+n3ZLhtS/n47pPRahlehWgmeQJJCDIhN5QJqMxEaxlIISXp9uRvKfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124483; c=relaxed/simple; bh=r06e45w7y/RPqT4Lo6jKZ9NpHEA4wvNPwLkvlBKkcXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XDhO+fN2WnO0nUfpdx7otwseamFhQKeyNQRP+F2wMKeLXH9GMpVore63LAILILkVQClRXuD8MJH95EgYd69j9EkB7fiDHdyifHzSPLdXrokqHPIGdiZ4PCS2IEfHtK0wanKL2J2lWtuquEyoxZ8iXbLHnmMvgQg2+yi3QRCiEO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aw9IIqm/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aw9IIqm/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C119C4CEDD; Sun, 9 Feb 2025 18:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124483; bh=r06e45w7y/RPqT4Lo6jKZ9NpHEA4wvNPwLkvlBKkcXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aw9IIqm/93DH2ybNsA4mffJVb+VhNxVbPhXDCBRVd/6vk16A6K5QtjmWhSTJwq5ak fJwB/veFft9N5Ja4oly3w8yV141nOkTujpUS1LFPGMyRf7C5eWwXqkUsCo/fYftl7W TQ8w0x4lUknq0lnsKsFa1qxaqiQXB3hFsXXxQN0TKRkbtwDFVWSdYnoAV8qWwQenBr AgUKP0+xXYruVdbGlSAv4TPN3DL+aEkb+Z8aNaG7xyY7QCAqcryDlCAV9XEO2vsMYH 3oBIxwvXs6N1uAm/HpjVRIvsBci/jpZ50L3xz8C2kO+loqsqZJhpq9Z8KTgokJO+uz DZXTb3N7kauEg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 11/27] iio: adc: ad4695: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:08 +0000 Message-ID: <20250209180624.701140-12-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. In some cases code is factored out to utility functions that can do a direct return with the claim and release around the call. Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- v2: Typo in commit description (David). Note there are several sets current in flight that touch this driver. I'll rebase as necessary depending on what order the dependencies resolve. --- drivers/iio/adc/ad4695.c | 240 ++++++++++++++++++++++----------------- 1 file changed, 133 insertions(+), 107 deletions(-) diff --git a/drivers/iio/adc/ad4695.c b/drivers/iio/adc/ad4695.c index 13cf01d35301..4bb22f4d739b 100644 --- a/drivers/iio/adc/ad4695.c +++ b/drivers/iio/adc/ad4695.c @@ -738,6 +738,25 @@ static int ad4695_read_one_sample(struct ad4695_state *st, unsigned int address) return spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); } +static int __ad4695_read_info_raw(struct ad4695_state *st, + struct iio_chan_spec const *chan, + int *val) +{ + u8 realbits = chan->scan_type.realbits; + int ret; + + ret = ad4695_read_one_sample(st, chan->address); + if (ret) + return ret; + + if (chan->scan_type.sign == 's') + *val = sign_extend32(st->raw_data, realbits - 1); + else + *val = st->raw_data; + + return IIO_VAL_INT; +} + static int ad4695_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -750,19 +769,12 @@ static int ad4695_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = ad4695_read_one_sample(st, chan->address); - if (ret) - return ret; - - if (chan->scan_type.sign == 's') - *val = sign_extend32(st->raw_data, realbits - 1); - else - *val = st->raw_data; - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ad4695_read_info_raw(st, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: @@ -800,45 +812,45 @@ static int ad4695_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_CALIBSCALE: switch (chan->type) { case IIO_VOLTAGE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = regmap_read(st->regmap16, - AD4695_REG_GAIN_IN(chan->scan_index), - ®_val); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = regmap_read(st->regmap16, + AD4695_REG_GAIN_IN(chan->scan_index), + ®_val); + iio_device_release_direct(indio_dev); + if (ret) + return ret; - *val = reg_val; - *val2 = 15; + *val = reg_val; + *val2 = 15; - return IIO_VAL_FRACTIONAL_LOG2; - } - unreachable(); + return IIO_VAL_FRACTIONAL_LOG2; default: return -EINVAL; } case IIO_CHAN_INFO_CALIBBIAS: switch (chan->type) { case IIO_VOLTAGE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = regmap_read(st->regmap16, - AD4695_REG_OFFSET_IN(chan->scan_index), - ®_val); - if (ret) - return ret; - - tmp = sign_extend32(reg_val, 15); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = regmap_read(st->regmap16, + AD4695_REG_OFFSET_IN(chan->scan_index), + ®_val); + iio_device_release_direct(indio_dev); + if (ret) + return ret; - *val = tmp / 4; - *val2 = abs(tmp) % 4 * MICRO / 4; + tmp = sign_extend32(reg_val, 15); - if (tmp < 0 && *val2) { - *val *= -1; - *val2 *= -1; - } + *val = tmp / 4; + *val2 = abs(tmp) % 4 * MICRO / 4; - return IIO_VAL_INT_PLUS_MICRO; + if (tmp < 0 && *val2) { + *val *= -1; + *val2 *= -1; } - unreachable(); + + return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -847,64 +859,75 @@ static int ad4695_read_raw(struct iio_dev *indio_dev, } } -static int ad4695_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int __ad4695_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct ad4695_state *st = iio_priv(indio_dev); unsigned int reg_val; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - switch (mask) { - case IIO_CHAN_INFO_CALIBSCALE: - switch (chan->type) { - case IIO_VOLTAGE: - if (val < 0 || val2 < 0) - reg_val = 0; - else if (val > 1) - reg_val = U16_MAX; - else - reg_val = (val * (1 << 16) + - mul_u64_u32_div(val2, 1 << 16, - MICRO)) / 2; - - return regmap_write(st->regmap16, - AD4695_REG_GAIN_IN(chan->scan_index), - reg_val); - default: - return -EINVAL; - } - case IIO_CHAN_INFO_CALIBBIAS: - switch (chan->type) { - case IIO_VOLTAGE: - if (val2 >= 0 && val > S16_MAX / 4) - reg_val = S16_MAX; - else if ((val2 < 0 ? -val : val) < S16_MIN / 4) - reg_val = S16_MIN; - else if (val2 < 0) - reg_val = clamp_t(int, - -(val * 4 + -val2 * 4 / MICRO), - S16_MIN, S16_MAX); - else if (val < 0) - reg_val = clamp_t(int, - val * 4 - val2 * 4 / MICRO, - S16_MIN, S16_MAX); - else - reg_val = clamp_t(int, - val * 4 + val2 * 4 / MICRO, - S16_MIN, S16_MAX); - - return regmap_write(st->regmap16, - AD4695_REG_OFFSET_IN(chan->scan_index), - reg_val); - default: - return -EINVAL; - } + switch (mask) { + case IIO_CHAN_INFO_CALIBSCALE: + switch (chan->type) { + case IIO_VOLTAGE: + if (val < 0 || val2 < 0) + reg_val = 0; + else if (val > 1) + reg_val = U16_MAX; + else + reg_val = (val * (1 << 16) + + mul_u64_u32_div(val2, 1 << 16, + MICRO)) / 2; + + return regmap_write(st->regmap16, + AD4695_REG_GAIN_IN(chan->scan_index), + reg_val); + default: + return -EINVAL; + } + case IIO_CHAN_INFO_CALIBBIAS: + switch (chan->type) { + case IIO_VOLTAGE: + if (val2 >= 0 && val > S16_MAX / 4) + reg_val = S16_MAX; + else if ((val2 < 0 ? -val : val) < S16_MIN / 4) + reg_val = S16_MIN; + else if (val2 < 0) + reg_val = clamp_t(int, + -(val * 4 + -val2 * 4 / MICRO), + S16_MIN, S16_MAX); + else if (val < 0) + reg_val = clamp_t(int, + val * 4 - val2 * 4 / MICRO, + S16_MIN, S16_MAX); + else + reg_val = clamp_t(int, + val * 4 + val2 * 4 / MICRO, + S16_MIN, S16_MAX); + + return regmap_write(st->regmap16, + AD4695_REG_OFFSET_IN(chan->scan_index), + reg_val); default: return -EINVAL; } + default: + return -EINVAL; } - unreachable(); +} + +static int ad4695_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ad4695_write_raw(indio_dev, chan, val, val2, mask); + iio_device_release_direct(indio_dev); + + return ret; } static int ad4695_read_avail(struct iio_dev *indio_dev, @@ -954,26 +977,29 @@ static int ad4695_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int *readval) { struct ad4695_state *st = iio_priv(indio_dev); - - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - if (readval) { - if (regmap_check_range_table(st->regmap, reg, - &ad4695_regmap_rd_table)) - return regmap_read(st->regmap, reg, readval); - if (regmap_check_range_table(st->regmap16, reg, - &ad4695_regmap16_rd_table)) - return regmap_read(st->regmap16, reg, readval); - } else { - if (regmap_check_range_table(st->regmap, reg, - &ad4695_regmap_wr_table)) - return regmap_write(st->regmap, reg, writeval); - if (regmap_check_range_table(st->regmap16, reg, - &ad4695_regmap16_wr_table)) - return regmap_write(st->regmap16, reg, writeval); - } + int ret = -EINVAL; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + if (readval) { + if (regmap_check_range_table(st->regmap, reg, + &ad4695_regmap_rd_table)) + ret = regmap_read(st->regmap, reg, readval); + if (regmap_check_range_table(st->regmap16, reg, + &ad4695_regmap16_rd_table)) + ret = regmap_read(st->regmap16, reg, readval); + } else { + if (regmap_check_range_table(st->regmap, reg, + &ad4695_regmap_wr_table)) + ret = regmap_write(st->regmap, reg, writeval); + if (regmap_check_range_table(st->regmap16, reg, + &ad4695_regmap16_wr_table)) + ret = regmap_write(st->regmap16, reg, writeval); } + iio_device_release_direct(indio_dev); - return -EINVAL; + return ret; } static const struct iio_info ad4695_info = { From patchwork Sun Feb 9 18:06:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967048 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B86071E0DFE for ; Sun, 9 Feb 2025 18:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124491; cv=none; b=UKoljh5f3+Jnp+gCxGRkRdgCipJniZTlEo2e1SPZvRGvo4ZtIj+4uGNx+tfTMoqgC5UxBqAIfcm6Sba3AgJCbBKSlZ0tDNkzr+B8U7tl1jWSMMWDBpzKib/fVvmkQQcmpBUASOFcl5uGndQG+GqaiWGw402LGkMn9KpRE7OlOPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124491; c=relaxed/simple; bh=glz/mK5s3rwAtTfjyYCokd/AaG+capxlzhjrVi9toGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NHD99valNhqGwcitao4oIl0+0prZ62vqzUmtVyo3O4EY6KiLGL0Uot+lJC+ehbdqvfj08NErmp+CWojzzzoSfv99uBCUC+RF4dn1TgIppJRwrLgiLSgFzOTJ67EwKf0s6nU/uUJ79gLZ++KJi411SeVzIyVaSN7H8XPyt2SjRQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G6JRQJlK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G6JRQJlK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C130C4CEDD; Sun, 9 Feb 2025 18:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124491; bh=glz/mK5s3rwAtTfjyYCokd/AaG+capxlzhjrVi9toGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6JRQJlKTFQ3P9lGw114kpUGGc1gOJrVUSVQr0IO3kfnfturpCHbVkftBx+yo+TB4 yRw4/oVIaLyH8F8RAVl4n5BaPJqWxRJfc37dcYp1v9rvCg1xCgy/Ngc0suh4VsuzJ4 t3vh+pijcTWafCLHzqyNDggWIlNTztLgUU/rX/DU5U/y0B4TfnYLB1WLBeJWIJbDgZ nvRdLikN9yZmJ0VfBlEXqNDliO7isrY8YCz8RooxtW3oig1YjugU4jSPGLAsaGAiDt C9oko7y2nGMWK7Ts0WkAQaluprFdkpoLn8hhaLBKyf94zH/1y068d6GfibUYQ0JcrO gea3wbUdDw8uw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 12/27] iio: adc: ad7606: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:09 +0000 Message-ID: <20250209180624.701140-13-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Guillaume Stols Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7606.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index d8e3c7a43678..39b5bf09e46d 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -752,13 +752,13 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = ad7606_scan_direct(indio_dev, chan->address, val); - if (ret < 0) - return ret; - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad7606_scan_direct(indio_dev, chan->address, val); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: if (st->sw_mode_en) ch = chan->address; From patchwork Sun Feb 9 18:06:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967049 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8D621E04B9 for ; Sun, 9 Feb 2025 18:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124499; cv=none; b=fEIbTcv3Gz9o/9ts9BAhEvrmuW+yR8BKiD+10BuXp/33az91fT50uTCsgdwbwmW4+78iyGu9UDu1hq+vBzQHzqWg/DtTWy6XAIatOS0kOT+UVyrVOowDG8TeJ5WQk/M59o9HYGvAa9PdQsSJdUEYEjXDqdEa2cP9Rmx/8dEzzpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124499; c=relaxed/simple; bh=LwIB0QjFiFttqsmzzseL4XqgAFsdKiLMYtEI0rnsli4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WB0+aT3H6P5iHkc6XKHRWcZRwZuII74y8qFYC2wb9Kw0Bx3aAn/T6ohgHGYaFAWX2Lyhv8TvxIVzMuxIcvMdKu0RgfJRSXtY0S/Rs8McqFnNW+hzGxdBYrtVR7ksZwuE3IJKzIpG+jIv3C+b0pFwBWuEaz7aCgTnQTT4mlCz0H8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=khl3bvyO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="khl3bvyO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 527D8C4CEDD; Sun, 9 Feb 2025 18:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124499; bh=LwIB0QjFiFttqsmzzseL4XqgAFsdKiLMYtEI0rnsli4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=khl3bvyOsTgr//1j2NkEC/YcUUBn6vZ9YqRy9ba6uaOu1CCsoa7jt3pQVvWDMyymg hWXIUYYOfyztlMv8UcI8TsLTU4WazOlt7oo9jmvyjFNUdb2RSkYldDKZRi00vq4ikv xdJ3TRJK4fbBaUc/OIi55T7giEjkkEvvV9kWI8sz9pjZRcY4i+zuY54gaUL5m1/6V1 rQOr+SdHopnWe9XR3WrlDiqerXhx9Wuljw2ZDvCk4dr/pUfXtCL1G9H4hYlmrWCZXf xgpFahvN3WC/Y9zV3x5x0lIPWKuLvdNWvIHGU5tafyJRh91TG9zczP+JmIDN3Rmew3 6cjX18OuWjnUg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 13/27] iio: adc: ad7625: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:10 +0000 Message-ID: <20250209180624.701140-14-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: Trevor Gamblin Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7625.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad7625.c b/drivers/iio/adc/ad7625.c index adb4e25dd7ea..0466c0c7eae4 100644 --- a/drivers/iio/adc/ad7625.c +++ b/drivers/iio/adc/ad7625.c @@ -248,12 +248,15 @@ static int ad7625_write_raw(struct iio_dev *indio_dev, int val, int val2, long info) { struct ad7625_state *st = iio_priv(indio_dev); + int ret; switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad7625_set_sampling_freq(st, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad7625_set_sampling_freq(st, val); + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Feb 9 18:06:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967050 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03A821DFFC for ; Sun, 9 Feb 2025 18:08:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124507; cv=none; b=hzx16KiD3j8KR8hffHQiFMN6iv79c36sv1E5nqrZVZ9CHCJxlTqik4/0rj39Ztwua3NTUAlJX6Cfb2URLfS1dZf9Ohv+8Eawbs/8AGHfxadBCy/SZpANwhD/UjyXS1X4AoI3IhyOi9hqif8rN2vpINKI6obPMoxc6LYtkQgkd4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124507; c=relaxed/simple; bh=DW8uzfPqEnxUX9IBGunQvIjVtRRub3vUZUhwubMZZZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gGQpevTEekcXtkZrxVqMmwtCd1/pIbRXfNVfF6sGGE2op0pgSHJIWfgln8jUHOyTQfEZPVSY2Z4OT+mWFOG+9LiCsYnlZb2BYIMqXKYExp04oOITsgK7uahcp5z/vFa8k6gIZKf3YbuPq2ibX9WTFybr6pf9tv4SSH2wXkd6WfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rekn3A5U; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rekn3A5U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF976C4CEDF; Sun, 9 Feb 2025 18:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124506; bh=DW8uzfPqEnxUX9IBGunQvIjVtRRub3vUZUhwubMZZZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rekn3A5UuKebb5HwqdZ5kSEXOi7jL+9TMel+6JPl2Psn+0gFkiqrfJna0Wcucqaa1 fhMLWhizW4SxVT09jqHgDc38WbAj8C2kaLVvGfNBhB/eRocYP0ei5R4I9YoZbQd5Vl wPkohbgZxvX8V9klF50Dv4zx8dmxuKJS8uOoKAl4im44zKidA+TS7R05S4wl+mZvuI Isma4JwC4ACnzAWTIKvoza6ycCpYobVurn737QFkrIO/Afj8eKmsPGXw4RGOabYNjv k0l/ypA5rfluGpRUHI/2EzmRX88muius60x+HMjVE5fD589tCJtJoRE2O5FpvOZv3Q fDs/NvUuIdpmA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 14/27] iio: adc: ad7779: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:11 +0000 Message-ID: <20250209180624.701140-15-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Ramona Alexandra Nechita Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad7779.c | 101 ++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c index 2537dab69a35..a5d87faa5e12 100644 --- a/drivers/iio/adc/ad7779.c +++ b/drivers/iio/adc/ad7779.c @@ -467,59 +467,82 @@ static int ad7779_set_calibbias(struct ad7779_state *st, int channel, int val) calibbias[2]); } +static int __ad7779_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct ad7779_state *st = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_CALIBSCALE: + ret = ad7779_get_calibscale(st, chan->channel); + if (ret < 0) + return ret; + *val = ret; + *val2 = GAIN_REL; + return IIO_VAL_FRACTIONAL; + case IIO_CHAN_INFO_CALIBBIAS: + ret = ad7779_get_calibbias(st, chan->channel); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + *val = st->sampling_freq; + if (*val < 0) + return -EINVAL; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + static int ad7779_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct ad7779_state *st = iio_priv(indio_dev); int ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - switch (mask) { - case IIO_CHAN_INFO_CALIBSCALE: - ret = ad7779_get_calibscale(st, chan->channel); - if (ret < 0) - return ret; - *val = ret; - *val2 = GAIN_REL; - return IIO_VAL_FRACTIONAL; - case IIO_CHAN_INFO_CALIBBIAS: - ret = ad7779_get_calibbias(st, chan->channel); - if (ret < 0) - return ret; - *val = ret; - return IIO_VAL_INT; - case IIO_CHAN_INFO_SAMP_FREQ: - *val = st->sampling_freq; - if (*val < 0) - return -EINVAL; - return IIO_VAL_INT; - default: - return -EINVAL; - } + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __ad7779_read_raw(indio_dev, chan, val, val2, mask); + iio_device_release_direct(indio_dev); + return ret; +} + +static int __ad7779_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, + long mask) +{ + struct ad7779_state *st = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_CALIBSCALE: + return ad7779_set_calibscale(st, chan->channel, val2); + case IIO_CHAN_INFO_CALIBBIAS: + return ad7779_set_calibbias(st, chan->channel, val); + case IIO_CHAN_INFO_SAMP_FREQ: + return ad7779_set_sampling_frequency(st, val); + default: + return -EINVAL; } - unreachable(); } static int ad7779_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - struct ad7779_state *st = iio_priv(indio_dev); + int ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - switch (mask) { - case IIO_CHAN_INFO_CALIBSCALE: - return ad7779_set_calibscale(st, chan->channel, val2); - case IIO_CHAN_INFO_CALIBBIAS: - return ad7779_set_calibbias(st, chan->channel, val); - case IIO_CHAN_INFO_SAMP_FREQ: - return ad7779_set_sampling_frequency(st, val); - default: - return -EINVAL; - } - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __ad7779_write_raw(indio_dev, chan, val, val2, mask); + iio_device_release_direct(indio_dev); + return ret; } static int ad7779_buffer_preenable(struct iio_dev *indio_dev) From patchwork Sun Feb 9 18:06:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967051 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 044931DFFC for ; Sun, 9 Feb 2025 18:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124515; cv=none; b=o6WQJJ04TnqZDcj3yOp9Tc+9QhdRyKUpjHoE9zfJWBZrEBgCYfdp8UYkWWEEq51JFZoBKrOWabrNtWgI/jCXk74SzE8SGzeQo7ZCBSCGqFtDEo9yVj4S4iyM5TdrYHlqKYlvSmsD+2RXsON+ziILCDivkyu8sQTzcLsDgKDkMSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124515; c=relaxed/simple; bh=H8Qoi5JGWNco+pJKwEX35K+WMSKStp1uKF8dogDrK2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XdAFtjSArzcMjrkF0TPS2FrBQsyq9s3dEXeFvD1drqFkyN6ri/JfrO6m9M3nKJh+3ANLsJ3FGKzZ0CxAFliUxKNoMDRKiXt8otK+V1OPYK0fIeLSOlnJfpG41eqvTh/Rgd6GIWU2/U78Jw4HiRhqIEGGMbbYGMrF0lxFhgAAwNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RHkDvCGv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RHkDvCGv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA8E0C4CEDD; Sun, 9 Feb 2025 18:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124514; bh=H8Qoi5JGWNco+pJKwEX35K+WMSKStp1uKF8dogDrK2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RHkDvCGvppmbr2N1qSjL5QuWBiz+tvCekgHngLVr9n1v6xfnLBJtgZ7t5P99XRK+Z GqwHGpxyDU6bYGi8n4Prby6DrghcbktNKW7mo3AX/wDCXEl7AxGeUVH2+b43oq/8Nz Ps2zhNfu3n8A1996ag1+Nycrw1NkIeedL/KZUnFxfxDQqCUDzd88V+vV3GCmTYq3ua Dr4bDGR15Op17dSEbXK3+aIo7AmZY71ins/ol02HppR1PTNQJIxgKpEHI3bGE0gsDI 4l9p2CQk4E9PF1UBhflM1EVo8wqA0G8WCmJRIJXvBW+Y7s+liSYZYSUSEsjVqaYRQR tYGtLNLQYHxCA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 15/27] iio: adc: ad9467: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:12 +0000 Message-ID: <20250209180624.701140-16-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Also use guard() to simplify mutex unlock paths. Cc: Nuno Sa Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index f30119b42ba0..f7a9f46ea0dc 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -813,6 +813,18 @@ static int ad9467_read_raw(struct iio_dev *indio_dev, } } +static int __ad9467_update_clock(struct ad9467_state *st, long r_clk) +{ + int ret; + + ret = clk_set_rate(st->clk, r_clk); + if (ret) + return ret; + + guard(mutex)(&st->lock); + return ad9467_calibrate(st); +} + static int ad9467_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -842,14 +854,11 @@ static int ad9467_write_raw(struct iio_dev *indio_dev, if (sample_rate == r_clk) return 0; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = clk_set_rate(st->clk, r_clk); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; - guard(mutex)(&st->lock); - ret = ad9467_calibrate(st); - } + ret = __ad9467_update_clock(st, r_clk); + iio_device_release_direct(indio_dev); return ret; default: return -EINVAL; From patchwork Sun Feb 9 18:06:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967052 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05A001DF246 for ; Sun, 9 Feb 2025 18:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124522; cv=none; b=E5Bvut/+w8iYGIb5VhqRdHtQgjPkZOJGg7ED4fB4L4ogdBRARNDyXxSD9XLuBwaCfyy6c0eXrFZh3Mh5IdiNV+e2AZwRxdl5/yhY+su4L3bAJNjLJsEK3G5CT7af9pqxWB1dMYGqjaXk+lZqjtbLDt8WkhDNpGI0QnZIS3ES6S4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124522; c=relaxed/simple; bh=vlIVdcFjOD1HV6+8hcQX5v9gLxkgwEUAxZCN5GGzy2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h4i+roy03AN8B20uj7syZwaDv/4PuvLry1yJauiRjBYVuz0sfCsL5QCUzgrjQu6U1I1/13eJLve3FJpSPH0iqS4K/k2MFWYES1VbopgCBN3k7zb1IEfETxNhZP6Es0vK7hGAS5WYnAIvXbKiiRvttKobqKDhr+LT+3JF3Xnwpjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TiS6DVUx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TiS6DVUx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 448F7C4CEDD; Sun, 9 Feb 2025 18:08:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124521; bh=vlIVdcFjOD1HV6+8hcQX5v9gLxkgwEUAxZCN5GGzy2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TiS6DVUxqhfqMBJgn2EU+sKeRL10IAU6oObquvuKTfZYuqigbID5zpwwznFz8ZpBV ExowLStfEn9H4Padsn1abMgfcCq5TcM9i4gDqMNgUmOImgpYSO9sJg9TWzPVm3di1s DYqPR+6XwzoG7l/mB/DosIAUvhhb/tYrkh60/dutijStmPF0TK7x1+D+4aBCKJ1JeX Di8GWI6SQnJBIFPb3DmhVY0kGJv6QTuYxZQVaFceVuAahHpnuoWGhv7+xKlQ47UOkk boujVohGVydrw+vp2+gtalFCY12Us2qBuKkT7YVPu66abGDrd0kA/2nXW5szLPyWrz HvBDlGETkHrOw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 16/27] iio: adc: max1363: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:13 +0000 Message-ID: <20250209180624.701140-17-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/adc/max1363.c | 165 ++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 76 deletions(-) diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index e8d731bc34e0..35717ec082ce 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -364,55 +364,52 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, int *val, long m) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - s32 data; - u8 rxbuf[2]; - struct max1363_state *st = iio_priv(indio_dev); - struct i2c_client *client = st->client; - - guard(mutex)(&st->lock); - - /* - * If monitor mode is enabled, the method for reading a single - * channel will have to be rather different and has not yet - * been implemented. - * - * Also, cannot read directly if buffered capture enabled. - */ - if (st->monitor_on) - return -EBUSY; + s32 data; + u8 rxbuf[2]; + struct max1363_state *st = iio_priv(indio_dev); + struct i2c_client *client = st->client; - /* Check to see if current scan mode is correct */ - if (st->current_mode != &max1363_mode_table[chan->address]) { - int ret; + guard(mutex)(&st->lock); - /* Update scan mode if needed */ - st->current_mode = &max1363_mode_table[chan->address]; - ret = max1363_set_scan_mode(st); - if (ret < 0) - return ret; - } - if (st->chip_info->bits != 8) { - /* Get reading */ - data = st->recv(client, rxbuf, 2); - if (data < 0) - return data; - - data = get_unaligned_be16(rxbuf) & - ((1 << st->chip_info->bits) - 1); - } else { - /* Get reading */ - data = st->recv(client, rxbuf, 1); - if (data < 0) - return data; - - data = rxbuf[0]; - } - *val = data; + /* + * If monitor mode is enabled, the method for reading a single + * channel will have to be rather different and has not yet + * been implemented. + * + * Also, cannot read directly if buffered capture enabled. + */ + if (st->monitor_on) + return -EBUSY; + + /* Check to see if current scan mode is correct */ + if (st->current_mode != &max1363_mode_table[chan->address]) { + int ret; + + /* Update scan mode if needed */ + st->current_mode = &max1363_mode_table[chan->address]; + ret = max1363_set_scan_mode(st); + if (ret < 0) + return ret; + } + if (st->chip_info->bits != 8) { + /* Get reading */ + data = st->recv(client, rxbuf, 2); + if (data < 0) + return data; + + data = get_unaligned_be16(rxbuf) & + ((1 << st->chip_info->bits) - 1); + } else { + /* Get reading */ + data = st->recv(client, rxbuf, 1); + if (data < 0) + return data; - return 0; + data = rxbuf[0]; } - unreachable(); + *val = data; + + return 0; } static int max1363_read_raw(struct iio_dev *indio_dev, @@ -426,7 +423,11 @@ static int max1363_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = max1363_read_single_chan(indio_dev, chan, val, m); + iio_device_release_direct(indio_dev); if (ret < 0) return ret; return IIO_VAL_INT; @@ -947,46 +948,58 @@ static inline int __max1363_check_event_mask(int thismask, int checkmask) return ret; } -static int max1363_write_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, enum iio_event_type type, +static int __max1363_write_event_config(struct max1363_state *st, + const struct iio_chan_spec *chan, enum iio_event_direction dir, bool state) { - struct max1363_state *st = iio_priv(indio_dev); - - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - int number = chan->channel; - u16 unifiedmask; - int ret; + int number = chan->channel; + u16 unifiedmask; + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - unifiedmask = st->mask_low | st->mask_high; - if (dir == IIO_EV_DIR_FALLING) { + unifiedmask = st->mask_low | st->mask_high; + if (dir == IIO_EV_DIR_FALLING) { - if (state == 0) - st->mask_low &= ~(1 << number); - else { - ret = __max1363_check_event_mask((1 << number), - unifiedmask); - if (ret) - return ret; - st->mask_low |= (1 << number); - } - } else { - if (state == 0) - st->mask_high &= ~(1 << number); - else { - ret = __max1363_check_event_mask((1 << number), - unifiedmask); - if (ret) - return ret; - st->mask_high |= (1 << number); - } + if (state == 0) + st->mask_low &= ~(1 << number); + else { + ret = __max1363_check_event_mask((1 << number), + unifiedmask); + if (ret) + return ret; + st->mask_low |= (1 << number); + } + } else { + if (state == 0) + st->mask_high &= ~(1 << number); + else { + ret = __max1363_check_event_mask((1 << number), + unifiedmask); + if (ret) + return ret; + st->mask_high |= (1 << number); } } - max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); return 0; + +} +static int max1363_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, enum iio_event_type type, + enum iio_event_direction dir, bool state) +{ + struct max1363_state *st = iio_priv(indio_dev); + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __max1363_write_event_config(st, chan, dir, state); + iio_device_release_direct(indio_dev); + max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); + + return ret; } /* From patchwork Sun Feb 9 18:06:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967053 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31696243368 for ; Sun, 9 Feb 2025 18:08:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124529; cv=none; b=iT6CPdUiwGoebc2eC3t4VAPDTdD/kror1tNdnXQujGf+LVwIQS/XtI8u0Hp37EkGc+BIoJnpp7lAIZuX2XT2SzPgpDZOjQR9vCzDq0YodDL+dTpmyE5y55n/KWLyCX6CrWN4HBP61o/oIfqKkGn57Bk4W8ljv01/zCHr/pm3Chg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124529; c=relaxed/simple; bh=TwBZho0KVpGyvfn0cH4C4sxkvYc7O+Eft6oo6sJyZj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EdDR/HT2JIM+Z/bq6MkEMOtu7HYnG2XPFtack5wJE2AMKtcYqnMe2h8BGqWfZ8BwsMOJWjS9nP+AoFuqSTj9pdgqK2SxMo6eed2cP7RRWVn+726T+mju6RMv/Hbr20GToKZ+8ymGJX0/lWQjd0A/X/wxQwcNewO7hFvP4adEdhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NTgvFTRA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NTgvFTRA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB5DC4CEDD; Sun, 9 Feb 2025 18:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124529; bh=TwBZho0KVpGyvfn0cH4C4sxkvYc7O+Eft6oo6sJyZj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NTgvFTRAkc0PTXefVhy4q0jFyFKDzK8H/cdg6XWGIqhR6jGVKWFKou5bZabblvFkr mFJf7KR77aIcZjzM+DYDOl6ZTO/fXMxh11Lkwcv+tC6wLOpEc4NvJx8BoP33/uzl7a u5aa7dA/CBlny+6CBDTfEvoDeBDIlr/A3t1hcfs287oK94SVhD5t3Sz9tJdjFDx5EP V+UB4/o+5sPeEagGIhhoo5pUacd0X4ewKfOF8/S9llqGZGNxcu6Xo/Lb84Q95PBPxy lF8u1IU2rpqTDw8QxNIqwmR9MbOHBcHbw3aNycG8S8JULIYhj9cqI/1yACGq0QJk8x PaP8kGsmdNdDw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 17/27] iio: adc: rtq6056: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:14 +0000 Message-ID: <20250209180624.701140-18-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context Reviewed-by: ChiYuan Huang Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/adc/rtq6056.c | 46 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/rtq6056.c b/drivers/iio/adc/rtq6056.c index 337bc8b31b2c..54239df61d86 100644 --- a/drivers/iio/adc/rtq6056.c +++ b/drivers/iio/adc/rtq6056.c @@ -514,26 +514,37 @@ static int rtq6056_adc_read_avail(struct iio_dev *indio_dev, } } -static int rtq6056_adc_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, int val, - int val2, long mask) +static int __rtq6056_adc_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + long mask) { struct rtq6056_priv *priv = iio_priv(indio_dev); const struct richtek_dev_data *devdata = priv->devdata; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - switch (mask) { - case IIO_CHAN_INFO_SAMP_FREQ: - if (devdata->fixed_samp_freq) - return -EINVAL; - return rtq6056_adc_set_samp_freq(priv, chan, val); - case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - return devdata->set_average(priv, val); - default: + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + if (devdata->fixed_samp_freq) return -EINVAL; - } + return rtq6056_adc_set_samp_freq(priv, chan, val); + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + return devdata->set_average(priv, val); + default: + return -EINVAL; } - unreachable(); +} + +static int rtq6056_adc_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __rtq6056_adc_write_raw(indio_dev, chan, val, mask); + iio_device_release_direct(indio_dev); + return ret; } static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = { @@ -590,9 +601,8 @@ static ssize_t shunt_resistor_store(struct device *dev, struct rtq6056_priv *priv = iio_priv(indio_dev); int val, val_fract, ret; - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; ret = iio_str_to_fixpoint(buf, 100000, &val, &val_fract); if (ret) @@ -601,7 +611,7 @@ static ssize_t shunt_resistor_store(struct device *dev, ret = rtq6056_set_shunt_resistor(priv, val * 1000000 + val_fract); out_store: - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret ?: len; } From patchwork Sun Feb 9 18:06:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967054 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05FBC243368 for ; Sun, 9 Feb 2025 18:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124537; cv=none; b=BvXIUq+8gdrtGcyaB7raC7oLqAD6caqiejhpwvZiADthXuaPcJkgIAgNbEruXBj5rDNljHQzupeWMj1i74BIgeJg8qul4Lm5nQ1q176WKW0t2sEZ3ZIvmAMSOAkhWuUFzV0oO3LoeVRSI+eY1ruF6AhW7vQU96EAzaTdUgAczOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124537; c=relaxed/simple; bh=HNNUFCABRUtOp1yOV4w7UniDWEHM1s91NTJTJAjSvAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A1L3fhybbbTeoswoXYv4M+VKIPwXFFJEQEx4JDHQodVnZpTXg7tKGylODqyXFQTqa0OFGIT2Z0nd3irsUTx3+c2Ic7xbsSOTMl9z1Pi9gO/1fL3GbGIOOCXKTqIm71KGNxNMWqUiA5BbQjJ/wGEmv8//XU7W0gVwsc6c5o68yoU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WJrml+Pv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WJrml+Pv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8BABC4CEDD; Sun, 9 Feb 2025 18:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124536; bh=HNNUFCABRUtOp1yOV4w7UniDWEHM1s91NTJTJAjSvAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJrml+PvDIs3+Uej9s3T9S9OhpFZvDotZ45lZ0btJm5HDTK9KoROM0wLGe1NU5V4V ATAlPmlKxHfFtuljNSLQSh94oggkT5DNqyRQDVcacnmM29/gkRtXxY+sE/46K1eXrD SNuBIbLAXa3ZE9/fKyvPeN+rp4nhb2WmQpz+SpR94jgGCYzF76TavLDdYnuTyQt3xW 58qbWSbYK5qyWOauLr8dqu5M4nuKm+MWEgORh8Jtq9Em3G/hWSVyMg5TrmpD8efCbF Z/BlIWm31kF86Y938KYjWADunHXwqAN/Bh5OTfoFy2XW/wbTaYcvNsbGkyRQydCKpi Io/Kt67S+oNHQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 18/27] iio: adc: ti-adc161s626: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:15 +0000 Message-ID: <20250209180624.701140-19-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-adc161s626.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ti-adc161s626.c b/drivers/iio/adc/ti-adc161s626.c index 474e733fb8e0..28aa6b80160c 100644 --- a/drivers/iio/adc/ti-adc161s626.c +++ b/drivers/iio/adc/ti-adc161s626.c @@ -137,13 +137,13 @@ static int ti_adc_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = ti_adc_read_measurement(data, chan, val); - if (ret) - return ret; - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ti_adc_read_measurement(data, chan, val); + iio_device_release_direct(indio_dev); + if (ret) + return ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: ret = regulator_get_voltage(data->ref); if (ret < 0) From patchwork Sun Feb 9 18:06:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967055 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E796243368 for ; Sun, 9 Feb 2025 18:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124544; cv=none; b=VorLvHKnYkho4Lv+RXDlruwoAEK36h16Pmo4sbSTpSe0pfbiciQ0yVoVfFfkAKe2sCX+cHmiBvE1pMuiSaxkwuJHolCXw/TuwGgGeDsFTC4RmT9jV/jhIA8ND7ar3OQX4vT3RaysUWn4CPOahNIBBP/YjW6xmgIb9ylh12jOA0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124544; c=relaxed/simple; bh=Ilw3bhepF3JuY6FM1vMKHMhrhwxF5uDqtVL265Ma1vI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OCExtYcTEYa0avXniEW0aQOyVonBrTtPk3RImLjvDInDk6w+LyGX1Vo/xNc2VkA9qooGQEWO68NWODXeyfNTojITtV1+fG+2RFYww9oqqaaKf+HDaySBUZbdGu40nUr0HLMiUE86zpNSe+XNFrfA8bnTU3B432DLAo5jdftd810= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d912ebs1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d912ebs1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F9E3C4CEDD; Sun, 9 Feb 2025 18:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124544; bh=Ilw3bhepF3JuY6FM1vMKHMhrhwxF5uDqtVL265Ma1vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d912ebs11BXcjOMbL2/waIi8x1RwepMDlx5lzPCYnM3gGA3IwmHG6jpfuztrY7V0a ouSCeKhIEmeT4UbRWv9zq+a3DZB/660nng6QFPt2RVODQPll5MVm0CJYtMTgUaopuX VIyn5ymUiSHYp1TFv8fnMs4m2iHCjfHEuTuLTP7YH7DzCEEk7i+BO8ADTzzqzVTYVw DHMBi4mapmr/PyzdfpAy8eWDbXJEMZgFS2PqrKrCR7LFIk0ZgAPXNuEaiMyx2UYcir GWKBR8BZSQf67o/nI2lCag3UUyzM3P2USx8ghTsahI/7wQkuLTjHCOMhTwo4/GA2CQ hW/hNfWfUAHrA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 19/27] iio: adc: ti-ads1119: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:16 +0000 Message-ID: <20250209180624.701140-20-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: João Paulo Gonçalves Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads1119.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ti-ads1119.c b/drivers/iio/adc/ti-ads1119.c index de019b3faa48..f120e7e21cff 100644 --- a/drivers/iio/adc/ti-ads1119.c +++ b/drivers/iio/adc/ti-ads1119.c @@ -336,19 +336,24 @@ static int ads1119_read_raw(struct iio_dev *indio_dev, { struct ads1119_state *st = iio_priv(indio_dev); unsigned int index = chan->address; + int ret; if (index >= st->num_channels_cfg) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ads1119_single_conversion(st, chan, val, false); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ads1119_single_conversion(st, chan, val, false); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_OFFSET: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ads1119_single_conversion(st, chan, val, true); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ads1119_single_conversion(st, chan, val, true); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: *val = st->vref_uV / 1000; *val /= st->channels_cfg[index].gain; From patchwork Sun Feb 9 18:06:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967056 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 897F91E0DFE for ; Sun, 9 Feb 2025 18:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124551; cv=none; b=Fp93mNzuQXlN7CJg+xf+cvqg6HEYhneFO326RjViaRtTCBiK8B6KmFFmtBTn8eEHqqgWhJ61KPaXryfyeSpts99Jne7P6m8jl4InFyMYPO+f23V64PC4wmmszWdXyypo6cS/IHvkZjQ3bfouAp0O1735WmFJxbVDmOVkoRnGknA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124551; c=relaxed/simple; bh=bmwY4eYPSPwIYEQE0xzFBYW4Vk8fPKHIWAts6VBI7OQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ztyahhvjet79lxHXJ7y09fCZEa2uy0JVYv7bpq1x+t3j8Rrk0wlX3d08sBt4bLXfz+o/IaPCTdTum/npmRfIDmCaNOq5xw/qBB8DXJ+x9ODgWo+pGYoESE0hPg9slrGbdfd4XCEHfhe3SPmLNKe1BRQ9PzK5Ca/Xmx47raOM+18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z7Q6GHO+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z7Q6GHO+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D448AC4CEDD; Sun, 9 Feb 2025 18:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124551; bh=bmwY4eYPSPwIYEQE0xzFBYW4Vk8fPKHIWAts6VBI7OQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7Q6GHO+RCIqsMYWLLiw5sEcnd1bvWzsMOF/EGf+F6UpflwbZz8eEq7T/umj4oL5e 8lDBcBxno2+5TL5DFi3hvdPOpYI5KKvQZh5J6xBo/GmtStx324AicYSLIEHrZWCwNI ISToBPtHuQQRItrJTgveICJSXtpD4rvWMrMlN+i4pC2RLdoGhhPOl7+dlXZs2iaCE0 Y/qYKEQBiuh2KFcpDZHCwfE3ToaaFvSg1AwnnFH3hsLwnZE6K5YTiKVJ/j99Z7TtYl S9EDuvNEc5WTJmSehNMTfDR0IhJUMnQn4uxUC7f/WfBs8Ol68IGg6+iz0UVm3/uMWf 5M8iXMsZ8IWoQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 20/27] iio: addac: ad74413r: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:17 +0000 Message-ID: <20250209180624.701140-21-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Includes moving a mutex lock into a function rather than around it to simplify the error handling. Cc: Nuno Sa Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/addac/ad74413r.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index daea2bde7acf..f14d12b03da6 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -826,6 +826,8 @@ static int _ad74413r_get_single_adc_result(struct ad74413r_state *st, unsigned int uval; int ret; + guard(mutex)(&st->lock); + reinit_completion(&st->adc_data_completion); ret = ad74413r_set_adc_channel_enable(st, channel, true); @@ -865,12 +867,14 @@ static int ad74413r_get_single_adc_result(struct iio_dev *indio_dev, unsigned int channel, int *val) { struct ad74413r_state *st = iio_priv(indio_dev); + int ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); - return _ad74413r_get_single_adc_result(st, channel, val); - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = _ad74413r_get_single_adc_result(st, channel, val); + iio_device_release_direct(indio_dev); + return ret; } static void ad74413r_adc_to_resistance_result(int adc_result, int *val) From patchwork Sun Feb 9 18:06:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967057 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE2A11E0E13 for ; Sun, 9 Feb 2025 18:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124558; cv=none; b=ZUKm88IEtYGaqM7pg+P2aVnMrtwHsAzKy/pHLD3IHZGIOdYYy7VVq6jbZTYSydXvMBBn6vZoco6UimgnCdd199mZLnVrh6lP+HbYWijYW+FTX5nrWKZHnUVRsYA6lV/XXacTCcxznsyDNaBawXjho0wT4bWM+pfU38k+SabUyNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124558; c=relaxed/simple; bh=eE+Ah0HZqrYQQuVZav40kxZxdhk2oOU0tkAlSJO99Bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ifpQWjrwieDci9dfd8U38vwagaxqPYO7AifOANRIJHrVbRZSm1WX7wbCBfmtUbsDPRTmH8/+fConX9ha/Lratd/wIVfeH85lqacbXSyRijh7BC5ezGsFz0pAnAWgg47kjogUS329D6bQ6l9eQkQ0SF07OvNVLNYEo8xFGFuSBlY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lw/2WY6p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lw/2WY6p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC81CC4CEDD; Sun, 9 Feb 2025 18:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124558; bh=eE+Ah0HZqrYQQuVZav40kxZxdhk2oOU0tkAlSJO99Bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lw/2WY6pHhfR0bKzbksZM6I3kUf8+Yqa+X99G9Hn15RJ6nTRMqxZ3eKoULhZyu/zt Lrv2Ha1yHw5gskkwLTrh0E+AQm9eAvZoj/V9mePqQ4Fyy+VYALXZu5QLrCUvgvsaUK 5qCKgkoSD0ceJl7WztY+HBmwfIOb3gEhRjxLMlfwqIM7lGIsiEzb4zG6PqR5ysgZWF 00hh9Ic1kLXHHMC1bmYxzHCjmvYTIe6fEtpwR38XK5l6XcHxSErMJTlHEn6UxF4TB1 v38Eoryqc5KWpRibOo2UiAiHmf6ShT5pXRjPr/RNmVwgAP7feTjVezRaz3lmuHPX8f yLbqIk5ewCqww== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 21/27] iio: chemical: ens160: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:18 +0000 Message-ID: <20250209180624.701140-22-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: Gustavo Silva Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/ens160_core.c | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/iio/chemical/ens160_core.c b/drivers/iio/chemical/ens160_core.c index 48d5ad2075b6..152f81ff57e3 100644 --- a/drivers/iio/chemical/ens160_core.c +++ b/drivers/iio/chemical/ens160_core.c @@ -100,25 +100,35 @@ static const struct iio_chan_spec ens160_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), }; +static int __ens160_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct ens160_data *data = iio_priv(indio_dev); + int ret; + + guard(mutex)(&data->mutex); + ret = regmap_bulk_read(data->regmap, chan->address, + &data->buf, sizeof(data->buf)); + if (ret) + return ret; + *val = le16_to_cpu(data->buf); + return IIO_VAL_INT; +} + static int ens160_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct ens160_data *data = iio_priv(indio_dev); int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&data->mutex); - ret = regmap_bulk_read(data->regmap, chan->address, - &data->buf, sizeof(data->buf)); - if (ret) - return ret; - *val = le16_to_cpu(data->buf); - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ens160_read_raw(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->channel2) { case IIO_MOD_CO2: From patchwork Sun Feb 9 18:06:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967058 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73D6F1E1A16 for ; Sun, 9 Feb 2025 18:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124566; cv=none; b=EfwXG1JPDsH8WPbWimMMvCikXygy4cepzLnLauC6AqF96PaYRBEzrBWwnghC3l1NsUg39JHdWCpdpJb8CNiTXCtFpMbNGqnwU2VFaANFT10uekezKBxAnkVBGhjtKGvT+txJCg7wW1B7OImwwvBpP26Oh5lJ8ner9k7QQBzG2CI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124566; c=relaxed/simple; bh=/rH9YMnwk3UQjIgoczlcYCk5sn5AQkhffS+8xH7qVRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jtR2cxV2oQ/Y9a8imqH82gOPtfvPSCx06UZY8jRXKZn82VRt+jjwoUfCYX7GmEGvjF0pqNrn0JF7KgTpzuWUIlvbgmBQCqetWAdvEGdf34+npbL0xoQuXlwgxdd0LF1XTzDjs39kACI6rXPTS/1VxKYrEWOWqSIs+WSiZljcsdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aizonGWl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aizonGWl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33745C4CEDD; Sun, 9 Feb 2025 18:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124565; bh=/rH9YMnwk3UQjIgoczlcYCk5sn5AQkhffS+8xH7qVRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aizonGWllaxgNqfMNfWCMeriXZ7A7dCfNkeTZhTmUb/C6MKdsoqJ6i3b8atc0n5QS 79dcdPZV4s3QphblvCGR4USd4hRsWyDb6IHwEE8c4arJoICqPJmaGMcTONTXGb9TTO argmUl1vTROaFug7AwpCpkdBeoCuzuz/0BWX8LEcRseTclgfrjUPda02DlSP1hyl7l HvZHblXKT0fVcKT7nY/Mh50Q3REVH+dmsbYaAqfEpUAj24mXuZHJothujT7eEo73OX eJjN3NEnbiEgYz95LguWk2QnOT1v06ulNyT8q5CZJjYk1ANpDUc4vkox/yeIM/pcKm JrDr9E9p7OCbA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 22/27] iio: dac: ad3552r-hs: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:19 +0000 Message-ID: <20250209180624.701140-23-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Angelo Dureghello Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/dac/ad3552r-hs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/iio/dac/ad3552r-hs.c b/drivers/iio/dac/ad3552r-hs.c index c1dae58c1975..cd8dabb60c55 100644 --- a/drivers/iio/dac/ad3552r-hs.c +++ b/drivers/iio/dac/ad3552r-hs.c @@ -129,16 +129,19 @@ static int ad3552r_hs_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct ad3552r_hs_state *st = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; /* For RAW accesses, stay always in simple-spi. */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - return st->data->bus_reg_write(st->back, - AD3552R_REG_ADDR_CH_DAC_16B(chan->channel), - val, 2); - } - unreachable(); + ret = st->data->bus_reg_write(st->back, + AD3552R_REG_ADDR_CH_DAC_16B(chan->channel), + val, 2); + + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Feb 9 18:06:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967062 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64E851E0E13 for ; Sun, 9 Feb 2025 18:09:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124573; cv=none; b=GAdggfrAC7XHyFCA4Na3wo2JuLxyVWHTWvYuMjdthDq7QDy8DaEJ58V47aNFOCI3u/xVre4PLw/lpgaFHkRsAhvnAKKqlyHaKS9g3uSopHvurN44eNsJeB4PL62++l+djrNtkSisaYSF0ESF56piVtaCSAts3AF71/HUU/wELIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124573; c=relaxed/simple; bh=HbzHUSWGqEwHmxnERyrztbXeNCSzu/58kFPxC6FdP3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qootLo/TYfVZkycMPyvAIYs5c8ZBkug6Jp70qh6CPVvGQl5BTx/00gqWG7kf8xr/qe/GOfM+jocOh3OyWDsQ+WKUxas7LXP2ZXSz7orrSUd1i70dc2arunzH49BVORH5IoyUlE8ECt5wq8wqyYPesBl+uH3/aQBThsHse63Wvg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ejoSWlTm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ejoSWlTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7AFFC4CEDD; Sun, 9 Feb 2025 18:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124573; bh=HbzHUSWGqEwHmxnERyrztbXeNCSzu/58kFPxC6FdP3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ejoSWlTmb16BpEbWlC96Nl6LbL4n+p57IRL2r0GspjXKsy5bJ22XT8JhmSsaGIJsZ UVElIhKNMXR8Hex2Kj1Cs3AdtLV6NHzYre4+YqVdk38+MOAkbd/nrySKxrHzvK76iM H3HdbARkyQF0LLYMQD1CAx+3zVlGGfoASfiyvwEOGbAkgjeAsqgxRCzVpN1xKZdqZc /UQkW8dn3Zn/4iGbfouS8WTAjVQMdqP0MoXvWFdq1BdA913ay0kZMngT96Ag1Jlj6H ZGCPbh0mZCXaftqEoC7YZ0UkS/GnOSJSdissoqBfMfp6DbeiQw9rIYxeLZrqHIlO09 phTntwqSg4l1A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 23/27] iio: dac: ad8460: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:20 +0000 Message-ID: <20250209180624.701140-24-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Mariel Tinaco Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/dac/ad8460.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/iio/dac/ad8460.c b/drivers/iio/dac/ad8460.c index 535ee3105af6..6e45686902dd 100644 --- a/drivers/iio/dac/ad8460.c +++ b/drivers/iio/dac/ad8460.c @@ -264,9 +264,12 @@ static ssize_t ad8460_write_toggle_en(struct iio_dev *indio_dev, uintptr_t priva if (ret) return ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad8460_enable_apg_mode(state, toggle_en); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = ad8460_enable_apg_mode(state, toggle_en); + iio_device_release_direct(indio_dev); + return ret; } static ssize_t ad8460_read_powerdown(struct iio_dev *indio_dev, uintptr_t private, @@ -421,14 +424,17 @@ static int ad8460_write_raw(struct iio_dev *indio_dev, long mask) { struct ad8460_state *state = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_VOLTAGE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad8460_set_sample(state, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad8460_set_sample(state, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CURRENT: return regmap_write(state->regmap, AD8460_CTRL_REG(0x04), FIELD_PREP(AD8460_QUIESCENT_CURRENT_MSK, val)); From patchwork Sun Feb 9 18:06:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967063 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3DDA1E131B for ; Sun, 9 Feb 2025 18:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124580; cv=none; b=gqRmcFuP6BH9ynDDDQZdcm2muWx8SPyRP4jY947AyaIrUIZhEIyfu+wE4IRMDKW/h5XWVb3eXk7NQY5VBb8ki8/yURTQq27rn6dbtSeFzE90sxTAolBQfm7uWcxkWyZFb+rVmD0+JlAq44kOeQDhmTW3zcQphX/nU5577tGfhlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124580; c=relaxed/simple; bh=lpmiQ6ZqV5+1z3vuzUNE3z4JM/4o2n52jOqHUYUbhkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DoUEBzLLusCXjj9aKnTenFwDcUb4d0RtTMIHXuYRoxK52wEMMNGUwiIhqs12dvXeCzw0XriQX42QskNe74Xh4rbX8iKqBrurzh+LT/j6ya80KWUc2v5aIwocvlxNwfeCNy+bc4NB+XaDISRco4j+xcuRTki0biOicIj0/kfdLSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ggvAryew; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ggvAryew" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E84B7C4CEDD; Sun, 9 Feb 2025 18:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124580; bh=lpmiQ6ZqV5+1z3vuzUNE3z4JM/4o2n52jOqHUYUbhkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ggvAryew/jtFQHIM1Y+qOjHrfNlACRdBsFVBFmXiqXZ6axJZitbCE9PLsuDs8Y59D Bd4vDn9bwapWi1z/oIZAEbSckQvXrgYTxKpUHk/Cu4PSOsohNWxXzaaVcVEuDH3rlS 90N60n2h2vV4jkE4xpQMFiLaay2Zo4XQGsdJ8/L+YKBC1bWP/BtgamZwDkyjPhPQlN RQUnkM7A28Z/+cxqvgmCdoQcCS444xXh4WzDGPATEckWOlXBRoKiCJoBfXsk9Pkeuv 7zhoK6q6x0fZ+Yw6GwNDp0ZOdheBzL386as8Cs4scm6DxVUuxiUv+eZQUbYi/3dbEn 9MKoDKbYaQ1Ug== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 24/27] iio: dummy: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:21 +0000 Message-ID: <20250209180624.701140-25-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Introduce two new utility functions to allow for direct returns with claim and release of direct mode in the caller. Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/dummy/iio_simple_dummy.c | 119 ++++++++++++++++----------- 1 file changed, 70 insertions(+), 49 deletions(-) diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c index 09efacaf8f78..8575d4a08963 100644 --- a/drivers/iio/dummy/iio_simple_dummy.c +++ b/drivers/iio/dummy/iio_simple_dummy.c @@ -267,6 +267,65 @@ static const struct iio_chan_spec iio_dummy_channels[] = { }, }; +static int __iio_dummy_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct iio_dummy_state *st = iio_priv(indio_dev); + + guard(mutex)(&st->lock); + switch (chan->type) { + case IIO_VOLTAGE: + if (chan->output) { + /* Set integer part to cached value */ + *val = st->dac_val; + return IIO_VAL_INT; + } else if (chan->differential) { + if (chan->channel == 1) + *val = st->differential_adc_val[0]; + else + *val = st->differential_adc_val[1]; + return IIO_VAL_INT; + } else { + *val = st->single_ended_adc_val; + return IIO_VAL_INT; + } + + case IIO_ACCEL: + *val = st->accel_val; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int __iio_dummy_read_processed(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct iio_dummy_state *st = iio_priv(indio_dev); + + guard(mutex)(&st->lock); + switch (chan->type) { + case IIO_STEPS: + *val = st->steps; + return IIO_VAL_INT; + case IIO_ACTIVITY: + switch (chan->channel2) { + case IIO_MOD_RUNNING: + *val = st->activity_running; + return IIO_VAL_INT; + case IIO_MOD_WALKING: + *val = st->activity_walking; + return IIO_VAL_INT; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + /** * iio_dummy_read_raw() - data read function. * @indio_dev: the struct iio_dev associated with this device instance @@ -283,59 +342,21 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev, long mask) { struct iio_dummy_state *st = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: /* magic value - channel value read */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); - switch (chan->type) { - case IIO_VOLTAGE: - if (chan->output) { - /* Set integer part to cached value */ - *val = st->dac_val; - return IIO_VAL_INT; - } else if (chan->differential) { - if (chan->channel == 1) - *val = st->differential_adc_val[0]; - else - *val = st->differential_adc_val[1]; - return IIO_VAL_INT; - } else { - *val = st->single_ended_adc_val; - return IIO_VAL_INT; - } - - case IIO_ACCEL: - *val = st->accel_val; - return IIO_VAL_INT; - default: - return -EINVAL; - } - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __iio_dummy_read_raw(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_PROCESSED: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); - switch (chan->type) { - case IIO_STEPS: - *val = st->steps; - return IIO_VAL_INT; - case IIO_ACTIVITY: - switch (chan->channel2) { - case IIO_MOD_RUNNING: - *val = st->activity_running; - return IIO_VAL_INT; - case IIO_MOD_WALKING: - *val = st->activity_walking; - return IIO_VAL_INT; - default: - return -EINVAL; - } - default: - return -EINVAL; - } - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __iio_dummy_read_processed(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_OFFSET: /* only single ended adc -> 7 */ *val = 7; From patchwork Sun Feb 9 18:06:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967064 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CF151E0DE6 for ; Sun, 9 Feb 2025 18:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124588; cv=none; b=PVzUsEOvDFw4e7elSn+9wCZ8fDjHuKkrg0RTb9Vh0DacvR1FsJA2udLJxu8kX2X9QpAXzvV9rywC4b6CUdf0Wtfy3x1r3leio4Sj3Itf+JJTJ9VNVksroyWr97MgjY1tfKzjivYrv7N2UwWZUgwHrYFD6Huv63jkaW6uFg8i7xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124588; c=relaxed/simple; bh=j97hnJi67W+aUnVpUiP5gT5/9CUBBP3r74hVPSZJU/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oaiXP8CKLsAJO5Z+VTArp+C4vj0bKIackqzgK+fLZQcrNSFFDbmVBKyfEUwX/6bmV06a6kSjhf1bTlSn2drbDkjYrs9v25V3xdpctNGT2HQijUGCQqbbMZFaimhU4lvjVN7/EtZyprmfLoOylSf89lcmAvCTlzmVFuvJbBLtXzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CD5tQrY4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CD5tQrY4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8109BC4CEDD; Sun, 9 Feb 2025 18:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124587; bh=j97hnJi67W+aUnVpUiP5gT5/9CUBBP3r74hVPSZJU/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CD5tQrY4kanxmvwVBOEVbqB7fxOeMOrCc0xND651X6nLiAhc13WTB0zc0dYYjzAN5 LAZJc1LrjghuUpLg/1kqtGcCldWlQvz5K60PMAD6kkWERn/e5q+kfCJk2+TOCUvb0Z YGaaPmS9nIASHIWBenL2yfnuFLMqfOC5Ivk4ni2GtLj6sNLT5IX1tXQJ2ZD/LKTwth 8MBU6em4v2mwCOS786r0N3ziXcp6qnYc0XoTgj2aQSHVc3CVIRUJ0WeV0ONGDNgOdj h9TJVjCS9AFzUr1aU23r+U7hChdgCJB1Q9OK/6xNSGumtRr/pgG2bCx6IlpCLZf0IR XhizaPdJJ+Vhw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 25/27] iio: imu: bmi323: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:22 +0000 Message-ID: <20250209180624.701140-26-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Cc: Julien Stephan Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/imu/bmi323/bmi323_core.c | 44 ++++++++++++++++------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/iio/imu/bmi323/bmi323_core.c b/drivers/iio/imu/bmi323/bmi323_core.c index 7f386c5e58b4..fc54d464a3ae 100644 --- a/drivers/iio/imu/bmi323/bmi323_core.c +++ b/drivers/iio/imu/bmi323/bmi323_core.c @@ -1702,26 +1702,30 @@ static int bmi323_write_raw(struct iio_dev *indio_dev, int val2, long mask) { struct bmi323_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return bmi323_set_odr(data, - bmi323_iio_to_sensor(chan->type), - val, val2); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = bmi323_set_odr(data, bmi323_iio_to_sensor(chan->type), + val, val2); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return bmi323_set_scale(data, - bmi323_iio_to_sensor(chan->type), - val, val2); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = bmi323_set_scale(data, bmi323_iio_to_sensor(chan->type), + val, val2); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return bmi323_set_average(data, - bmi323_iio_to_sensor(chan->type), - val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = bmi323_set_average(data, bmi323_iio_to_sensor(chan->type), + val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_ENABLE: return bmi323_enable_steps(data, val); case IIO_CHAN_INFO_PROCESSED: { @@ -1747,6 +1751,7 @@ static int bmi323_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct bmi323_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_PROCESSED: @@ -1755,10 +1760,11 @@ static int bmi323_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_ACCEL: case IIO_ANGL_VEL: - iio_device_claim_direct_scoped(return -EBUSY, - indio_dev) - return bmi323_read_axis(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = bmi323_read_axis(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_TEMP: return bmi323_get_temp_data(data, val); default: From patchwork Sun Feb 9 18:06:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967065 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CFBF1E0DE6 for ; Sun, 9 Feb 2025 18:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124595; cv=none; b=h4j9WEcyOuziUwpelFPDbjemq2ldTAdeBn4UxiTOyKhkKDYGZY4MA36hUj6gGO4s3Z9BoDpNYoJ3eV6dCJdCl1TtFGkmouOGQsHHbP5IQYM9Mo1JjgzLKr+UW8U9Zg8QvdUjhAI2aGpZC+oY0Jyz93Wy3B6wDr8O4nL/kc4qLL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124595; c=relaxed/simple; bh=FKZuWyaR6hBvkkbrWZS5xyem7htiAp5aQX2oALu3Exk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vonti8gCot3HUzqmdnjZnPuhMn+3Ukgm+Ih3wSRTKNu4e9834N0Q5Zq6c1P5boYIwacQquqz252GbTrISVevtx+pKZ4eanKxZOvO5X63I0ekgaOd82kaPGU2d3dL1gtOj1S/GQe8kscbs3h1Kuq06GFpvRgLH/SGmmunNG2mEtA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oWLfRZV9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oWLfRZV9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB1CCC4CEDF; Sun, 9 Feb 2025 18:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124595; bh=FKZuWyaR6hBvkkbrWZS5xyem7htiAp5aQX2oALu3Exk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oWLfRZV9rF4dULLoI4A6FUOFMj5q8ku23xLjVZtFJKrxG4/TDYqtvZxelx4qbzyb9 6fg+J+DBFqtlXODMlx4w9Ha+L8/s8yeebWDr9rVw35yo2VkH2q3/ZeoELnTjST7Ck5 ai67HCy+SnOQ6CfP5hCZpYkmvFDirk1rAXWsOLonVDID/9kRFAmIjgsliw9nBJvV5g BGwHZKS31+Yx9UvuxRVt+B+xrZXw+DtdzG8lnKkgPit7LOzAImxxsrvQRfmneI36iu 21P44YWZdbLZxR01hm+2KeY0vvrfM+6SAslPpEkaBFIYOt7BuuBX0B7vKFXa360kHx 6u3bM4MXKYZWw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 26/27] iio: light: bh1745: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:23 +0000 Message-ID: <20250209180624.701140-27-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Reviewed-by: Mudit Sharma Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron --- drivers/iio/light/bh1745.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/iio/light/bh1745.c b/drivers/iio/light/bh1745.c index 3b4056be54a0..56ab5fe90ff9 100644 --- a/drivers/iio/light/bh1745.c +++ b/drivers/iio/light/bh1745.c @@ -426,16 +426,16 @@ static int bh1745_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = regmap_bulk_read(data->regmap, chan->address, - &value, 2); - if (ret) - return ret; - *val = value; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; - return IIO_VAL_INT; - } - unreachable(); + ret = regmap_bulk_read(data->regmap, chan->address, &value, 2); + iio_device_release_direct(indio_dev); + if (ret) + return ret; + *val = value; + + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: { guard(mutex)(&data->lock); From patchwork Sun Feb 9 18:06:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967066 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C73181E0DE6 for ; Sun, 9 Feb 2025 18:10:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124602; cv=none; b=ohaDewu0OIYk1a3kCjTKc/+J/GBRF31XQqNdkc5GNNwAJ2qyeGB7SVrSn0f5jgoOqu2sdrdbXXEAvjYT7AGRsb2zhR8YNJoHTao4m9qtoZJBa0lLx83h99LMKeGFL4+EFGZBT18BFwGnCoAIfzcZPkmAxQQgGNsT6r9z/iI/zjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124602; c=relaxed/simple; bh=fY6hpho4foOpaaWUGmCtoNz30s9hMcjXQlHYpoZRKQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hBUfypDTIkXJE2VjjAmGlrk3Duza21+8zGVDOncLxNztAPEon5nI315KUt22TCfjbK9JSwAqv+p4P0qkklkeKBQVG+0sQ6mL+7A8ZfeC/6IdQuMwR+H86SHz4clyG4EVOlI9Ufw6zWkjQOCadnSxQEwexnrMOOEK+UBaOj8wEQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IlTmbiJI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IlTmbiJI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2BDC4CEDD; Sun, 9 Feb 2025 18:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124602; bh=fY6hpho4foOpaaWUGmCtoNz30s9hMcjXQlHYpoZRKQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IlTmbiJI4Pt7nlkIvLrpb+cWTn7zp7erRAJoqfSQF18aMvNKOEpwCP+4sMg0JB4TZ CYGwqpy0idOZsSo6IoVWA5j+eCNoO4Rx3gVooNccNmlMIIO6Y2KtSOGOdBuAeweH34 j/i3VkeocqPx+ePAq8E+QawawfVfiTjjxJooLywRfgvBJlbnsH22YfbYuDhsjUpIKL caZj7jbhIEwbH7OfoH7FSCjQzCqNmoiytcKpoyiUlR+9kEnUXCe6F50+mUadGrGS90 AW1gBn1wLbQg1AwQGVchJnmdbuwUU9hM9jA/dFF5yHaNEs6GDxgyogerjjQBk5OPFO HPhxOZeoyJBaA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 27/27] iio: Drop iio_device_claim_direct_scoped() and related infrastructure Date: Sun, 9 Feb 2025 18:06:24 +0000 Message-ID: <20250209180624.701140-28-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Scoped conditional automated cleanup turned out to be harder to work with than expected. Despite several attempts to find a better solution non have surfaced. As such rip it out of the IIO code. Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- include/linux/iio/iio.h | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 5ed03e36178f..07a0e8132e88 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -688,32 +687,6 @@ static inline void iio_device_release_direct(struct iio_dev *indio_dev) __release(indio_dev); } -/* - * This autocleanup logic is normally used via - * iio_device_claim_direct_scoped(). - */ -DEFINE_GUARD(iio_claim_direct, struct iio_dev *, iio_device_claim_direct_mode(_T), - iio_device_release_direct_mode(_T)) - -DEFINE_GUARD_COND(iio_claim_direct, _try, ({ - struct iio_dev *dev; - int d = iio_device_claim_direct_mode(_T); - - if (d < 0) - dev = NULL; - else - dev = _T; - dev; - })) - -/** - * iio_device_claim_direct_scoped() - Scoped call to iio_device_claim_direct. - * @fail: What to do on failure to claim device. - * @iio_dev: Pointer to the IIO devices structure - */ -#define iio_device_claim_direct_scoped(fail, iio_dev) \ - scoped_cond_guard(iio_claim_direct_try, fail, iio_dev) - int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); void iio_device_release_buffer_mode(struct iio_dev *indio_dev);