From patchwork Tue Feb 4 20:02: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: 13959755 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 C64C81CEEBB for ; Tue, 4 Feb 2025 20:03:08 +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=1738699388; cv=none; b=Qe0pGBPMXoFWvSE3lQHdknSvwZueoLxX8IAaBinRbjgPNQVHzKvBYSR42w/qz+v55tjCJG4/9dkxVce2Xy557jWQWefNWYuu97+EC/1Q/2NjT4iTpOAkuxLyy+331I3BEH4kOnjw6RpYxhmdjs3EnZftNU+LWw2gbECvkfJYs2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699388; c=relaxed/simple; bh=IQXZ9uesiy3SKg/FgVYHBeGKICU2SVFd1r1iTn5DSwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Di/Ttvc61CE0+rsXj90fHWaCk9JYKpYQXmdOEaWEg9r+nquviNUis3uLajiueC556DqYL+tKJ1KnoF7XDtSK6tg9lhL6TKVymprEmWu8veXTTrZgNZc1VC0v9Hv6geJOtV+6TuhlF8UZon8OOmLeHD3vF0TyxGYS1scj9Fz5EdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tzvbGM7d; 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="tzvbGM7d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6FF4C4CEE2; Tue, 4 Feb 2025 20:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699388; bh=IQXZ9uesiy3SKg/FgVYHBeGKICU2SVFd1r1iTn5DSwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tzvbGM7dLi5DIkUExtl09itx7N+/jGpQvQYS9RLahapKxGyGZZ5k0N2c/nhPALUtn rMTaZOvvrHpOgeOBlBUEwhnkejDT8sWfg0oh2yuNMKvolmVvaV2obXkicIsX6Opv4F ecdoNLaQ3DX0Umfrri5DlrRsjdLd9ROOCu96WVPyT9pNayabebeMP17fUsmTf5vuAn qxrhis9SD7X9NPpOqC8lQGpQ09eeeX89KKQ3HJnQXLLfwbMHlYtnzkTQpJaPP9vzxE RB1JhtgvTuhNOoxqzCwf+w2k5hvAdvJ6E6+Wdr82/8sM9IvSEAmas8d95DjqBn3bqx SKXu5X3KsCZNA== 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 01/27] iio: core: Rework claim and release of direct mode to work with sparse. Date: Tue, 4 Feb 2025 20:02:23 +0000 Message-ID: <20250204200250.636721-2-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron --- v1: (Non RFC). Drop the __cond_acquires and __releases markings as sparse support is not yet available. --- 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 Tue Feb 4 20:02: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: 13959756 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 97DBB14B094 for ; Tue, 4 Feb 2025 20:03:13 +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=1738699393; cv=none; b=JT1JLo8PvHDUx0kisHDI/MxM+vWYKeLnhn9K4WVyQmfG/v9H1dduNPgn2alB4+VgOi+c72II/KxBaV/ylzBXvoBrLw3E81/VHYhI5e659HeNX0+ksgfXDFO+y+0kUdYMlOoj0/NokPLXbuVFYqbT5UBiNOG3GgYCU0EMrMvbR2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699393; c=relaxed/simple; bh=4XpQ7+x9bi8nk6ozv376eH+cFSKOzVefVFmWGSraiL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lWf0gs/RyWHC1uSMFmrI/1rP7B5wX4Bpn0hreWR33p9W+3/ShourGz9fAwSi8BNUP9kcPDYrVn9hKyaQ1gVxJWv2eyaIBLhloKnbIAWguaSF/yVHjDeUwrWvqjekrNk3YI/nlW8gCy3sO3dGiTdJgXUgX9K35YT8Z1qIyGp5yD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lL7+agg+; 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="lL7+agg+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB1FBC4CEDF; Tue, 4 Feb 2025 20:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699393; bh=4XpQ7+x9bi8nk6ozv376eH+cFSKOzVefVFmWGSraiL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lL7+agg+CtYO5VfAi13HUe0KLhIVxfz7jQ0UnhV8DowFNpokSagd4kVF6Dm7XT8aJ ge8mWgXFLRXrjdyfBZqwa9Jpxf3udkSBJQXCSwZRUYMsuybCB69nSKJIlGY/GD7KKN vNY4lC32fseTKVkSCwCxwq7/VMg2qLK9m091obqgJUFXTu1dGH5iykNH3x8Btr/avG zY6piccDt930rKviC8iRcIqynJP4bE6Mun/72lwA7eJVw7iYTCe425+VDMv5R1TW7W y3aDCXqqkMXIBotbJn44aaJVFq6GeVmnbrx8AoljWiGN1b9q5SNJc2b0JNrMrWhNLk HyE9xKqtJ0YPA== 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 02/27] iio: chemical: scd30: Use guard(mutex) to allow early returns Date: Tue, 4 Feb 2025 20:02:24 +0000 Message-ID: <20250204200250.636721-3-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 Signed-off-by: Jonathan Cameron Cc: Tomasz Duszynski --- drivers/iio/chemical/scd30_core.c | 63 ++++++++++++++----------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c index d613c54cb28d..7a864b52adf1 100644 --- a/drivers/iio/chemical/scd30_core.c +++ b/drivers/iio/chemical/scd30_core.c @@ -6,6 +6,7 @@ */ #include #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, From patchwork Tue Feb 4 20:02:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959757 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 EEAC814B094 for ; Tue, 4 Feb 2025 20:03:17 +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=1738699398; cv=none; b=sGGOtDJS7p2QpEnYlgEHmwpZx1Nqp2EwRXZHaTN6QYjmNqS8o1YyHQtwiMgtsqZSQJOhMF5o9zTPGpD817woG2C8llAlmiZ1+3spH4s9kma2GQvmpmOJuiZ2s39rLdzjPMVTVQCXRlKuYi2nq/kAxGIMo7ZAcP+U5sLSDHKo6Oo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699398; c=relaxed/simple; bh=71NqriHyNtjrjorq5YuMiGlNrNWo4FgWarmoj+f4WZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pI5eCgCMch24Q/Xc0CsuolTZ/8Xl+h6xMP0Q+HElkaEx+VpurNZNt5K6QFj4BbXSIAvtJb2kQ8o/rV2R/69V7/CK2k2Hr+y8FY4h0gWY3UiJzmCMZc2qnsRw9Z9zdKYQemEJ94e6UJ60Uh2Cge9lT8LfCk3SrpJyV2pVSjVugOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F8OjJBhE; 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="F8OjJBhE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E390C4CEE2; Tue, 4 Feb 2025 20:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699397; bh=71NqriHyNtjrjorq5YuMiGlNrNWo4FgWarmoj+f4WZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F8OjJBhEje+h1df5LTpMuWwD4mH5KXnOIvvCbFCNcOAlNAZXaHnUJ3y7X9wCU3waJ wJY9Avy34UQ7Iyszzy0+V3t28RM+Q3bhCJo0c59UIrmfgYKduRKfXTitHH9TSeZfpi kIV54eIXnRtFfJGWgB5v51idoywQC/ALAZZPVh070B3lc+lJRT/fC9qBaNVx9fCFLP 2vHEmNu9xwvgAHNlM3MoMHQq2SnfJ/LtE0D3DtJmqZReS268PwKIgdXD2wpnzH8Apt YPvq+smsvlzzs5CIfaFYGTz1Qv4mLzlOsaYI8ZFLZkEjrXs6daPM404kWnSJ+1fu9u HZ0lVXWszV9QQ== 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 03/27] iio: chemical: scd30: Switch to sparse friendly claim/release_direct() Date: Tue, 4 Feb 2025 20:02:25 +0000 Message-ID: <20250204200250.636721-4-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Tomasz Duszynski --- v1: Adapted due to new use of guards() in previous patch. --- 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 7a864b52adf1..82859a66c91a 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 Tue Feb 4 20:02:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959758 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 CCEFE14B094 for ; Tue, 4 Feb 2025 20:03:22 +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=1738699402; cv=none; b=TO1hw9iUBKCDnBpx3zZKA4kCV16P2t8A59rMEQr89Cm23J6OvEW9rCQrDvTl4yNG90HlNLvcPWVZJbB6vBxLxFP3aBmJWWJU1f5af6z57J9E7HI5A7rFJKw7/Vh8UQ3TUFJGFfYxNBKeZkfCKtcMuKk5ShGTqT/Iee8xk4kN12g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699402; c=relaxed/simple; bh=LFvC6+7XlIWvd3lag3thDqoCGYYvwluNlCYt7ei1jUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oJMweDspZNy2PoQ/qBphM7n7yXtbqJqsu/uyisG8lhOMfdCmLH4sIFiKb7wGQt4E26wEUe0icdljCpcmNyoa1WgBcUgL6kAhO8PoDkkoMiv+qH6VyHsYEQfNuzh01poi/X5G+3lcBbnfVs+MmEXpw6NPA8vZNnJumC5grVYYuko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WKcFW5Fe; 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="WKcFW5Fe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F911C4CEDF; Tue, 4 Feb 2025 20:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699402; bh=LFvC6+7XlIWvd3lag3thDqoCGYYvwluNlCYt7ei1jUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKcFW5Fe7GxpqSGjrinpD9aGnzvkpsnYN85eBXC5BUPEoXjjSJyOpC8hwRecECX89 qNJqcaRXU4M2N6r3fZze82IRHMM16ex1p4fwrgVQanMQ1KoNTAivXnHMzzv1NxhKWM alHEkQw4FH6k4S43owA35P5Fj1xf/bUihYQMHXkZQmdd54pKqX2wm8YLs28gKlWnZA aaAsQgCrnbyh+5Dw+CNf8zFzqN//HgbiztG15LgCjy2FF0o07oAvz2SnfyIu5h8zqS 4OknkQQC5Jt+k54sMB7XMNmBH5M0IzlA8pIbeGTCqm3uVS/D7G8xBV/h1jol1pbh+t IYFeb009D+KrA== 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 04/27] iio: temperature: tmp006: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:26 +0000 Message-ID: <20250204200250.636721-5-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Antoni Pokusinski --- 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 Tue Feb 4 20:02:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959759 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 950B414B094 for ; Tue, 4 Feb 2025 20:03:27 +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=1738699407; cv=none; b=p7r4oMKegkdD0aZkVBhe9JFDN36aIXn3Jg+Pz7vmruJw8jrPz3HXIwhnFg58rEjy/2yQiXLeA9WtDs1C9uQ2zrq5fX0dxdTrLQFPrJALpa21BIcJs5EnTrkL8qBI/7ZgwrHgB1Q7la+J1ucr/31Fm3yOOKrIcD+yk7rsPq89zMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699407; c=relaxed/simple; bh=/OGZR6yc7Rs+FpGVtY4XwYosR2D9X1bvqwbA+vxDDJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j1xw5B2Gr9f2Uff4xLAQUF+R4UHLklpe47y1+IRvvAIs2cSTvSeYJacSrpwiXxVF4e+tMXfEXo3+IsyFk32SzYVKuyjUFJ+HQ9CxUhG7BlJURI8CY2KkYznVx2dyPC3SNz3rlTJJs1M+yxkgbqUkuOcFRPwurIdgsaAJHNQnshw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I8lF4dDD; 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="I8lF4dDD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F88C4CEDF; Tue, 4 Feb 2025 20:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699407; bh=/OGZR6yc7Rs+FpGVtY4XwYosR2D9X1bvqwbA+vxDDJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8lF4dDDAqJYJLYHzAXSvUKN7NraLfNU0h7hgOzEBvchSWQBJOAbuIKpEyBG/4MtP 7h8Olpm1v4ODRbxbihv0aAdXnpCWIkQzxwie0yb93iEf9ZtjsF/vTosxYBayj/KZxd bfI7FPo5RmdKS1dkiKA2LOGxGAB9SZZhRyLFHfxAp2JP9KnTin8ikHudhjFRLwdCuZ KEe+gv7tMUdc/GwvoBEjP5P5h/CcDdFR/ObNNYzL3ype46RBJqOmNCtu5Duk0yWT5H U4cwcO3a2IC62CHZivqTZm+KYsNJRLj6gQzNc1CCA5j0Rm6EE9QDUe3pGPMREov1qw pNw3bY6/rDWKg== 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 05/27] iio: proximity: sx9310: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:27 +0000 Message-ID: <20250204200250.636721-6-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Gwendal Grignou --- 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 Tue Feb 4 20:02:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959760 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 4AE2514B094 for ; Tue, 4 Feb 2025 20:03:32 +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=1738699412; cv=none; b=p+cHwEuxHc31poVG4oyTGxrybHWPwum+F5sUlbA7yRDOZrUqpnnx9MV8AUr1PV8Y28Nv9AWxjdP2wraomcAV+I0268tvnCnnMS+33uoBhDgS9uY8T9cYNPdpwKD8LYRWvZk6LAZpSROF0QYKThMuJNZrD54hkk1XQ7z92e6Hbd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699412; c=relaxed/simple; bh=bI9IJB3nieW8XS1BBdqTBl3IRvqhP07gqqzbGKME3sA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sMVvgKc4PjUxLEgo8WuUN2HHNcE3Z7fl/C3v3ySL2tab4Oel3mcSmGSFS2FAtJ6rXYcxwA8rSYwOcSAn/VAzz53/GFZTKlPdubvEuhKVGC8YJ7JxJK44aqsXW2oVAi88B5w7f4mm8HNAKLnESLa/ZXwDKFQi79ZiubeyilnHJmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ssZW+F4w; 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="ssZW+F4w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF68DC4CEE2; Tue, 4 Feb 2025 20:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699412; bh=bI9IJB3nieW8XS1BBdqTBl3IRvqhP07gqqzbGKME3sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ssZW+F4wZkKCK0vpI9e3b3r3yJXoIh/6qBQFn7DHC7zifPA11gJ7gfQa6Kk2VxIfY MyQYg+j0iI4nEwkWNVHJFngeJVBtBXQte+Udj84lSiGeOfqVpZNYkbY7+8zPirwAfw yfYhoYLXYKcVsId+z+ytzwFoTZxYHxUa1V7j4xeGq7KOBqBAUStm6niXeCO+vHKKX8 545j6FkFdlYAnz+pz3OICU9RSY5kfAhUXmiJW4CevfaT1CbZXuI94HbrrbAnJYjnV/ qt/3EkS5ij0L20DKGEyBQECDHP/vkVggkzXHCk0loWidlkCt6IxRbXXox4p/XrocQ5 Ero/XWFNpp4jA== 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 06/27] iio: proximity: sx9324: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:28 +0000 Message-ID: <20250204200250.636721-7-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 Signed-off-by: Jonathan Cameron Cc: Gwendal Grignou --- 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 Tue Feb 4 20:02:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959761 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 C47A114B094 for ; Tue, 4 Feb 2025 20:03:37 +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=1738699417; cv=none; b=XKVknPZv3ZlxJEfHd7/gkBUYqiotoOpjnatofspUBbbp2QdiAKlBlaLkC7Vb0JrPUoIy/XS8C4jplczczSDbnXG1/0w3qF4yTxWHoMKElPIMDKReGAp9LSWIahUnuZ5g+Dy2H70FY9yt6pAGCVWcXAjN/1xPdpFzAz40wGBhtqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699417; c=relaxed/simple; bh=/2z/DF+G9tiB//ZmP8WuK3FcWPMA/e4kZKCwyw2chkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q2TBtgTf5vYFdQM6sOhbW6fQBS/QHkBekuderMUmrHifs8NP551rc11I7DjAUQ7C2Kk61J5/V8aj71dt8B4sD/Uur8s2+NyK7mD1RkgVbNK8UmlgD3zLBBJ/FSWo+jE+BvEoSj7g0e7durg7keyb884EKMMvW+aMVvrTJCtlzrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GlVCavjb; 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="GlVCavjb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99997C4CEE3; Tue, 4 Feb 2025 20:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699417; bh=/2z/DF+G9tiB//ZmP8WuK3FcWPMA/e4kZKCwyw2chkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GlVCavjbOPMDAEOsZReBI+a44MFcMexO4oYnwPPJNRX/FpfUB2Btu5JXAQuSWv4Ua g7vCYDxf/vzPCi+A1Kl4GieheN0gQjQxPUOV3yPVOvwwU9qX4tjNW5AxVWWbs8b2bi suXZ004w5mRUzcUBcKNvZDBaWkMZub/tC5jzHOOqHrOEB2AQc1js8YCYwx6A8LX70w 2CTa2i6/UanmJc3N9SmPc22nfThJt5WeWiOtrpKmmDfAGbxhOC3yw2pn5dYynOegcX 9cd2QTb0HJOjxCajlQNptutPrwuslUc9fuT1JaU0fuIvpJ6w1ic34F5JVFC05qa/6L Fze6yFXN/knGQ== 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 07/27] iio: proximity: sx9360: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:29 +0000 Message-ID: <20250204200250.636721-8-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 Signed-off-by: Jonathan Cameron Cc: Gwendal Grignou --- 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 Tue Feb 4 20:02:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959762 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 69EA82040AF for ; Tue, 4 Feb 2025 20:03: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=1738699423; cv=none; b=ez4DJ/v9h9JG/plVfLfHJ1e50LCfXvCCBLH8Y1VzOs/p5G8Gxc9rKj6WrCPX3ljfjURW7BOc59sSu70+J31F6L23k1qANaJMCYrOkDkAAIlaaq3TXRXnGpJ5pUFbL5LnOLq/JUU72p8sbhkcoEv0QyQuNFvCjZvy9bg+ECC/UsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699423; c=relaxed/simple; bh=Nm+9CD2nPcl5umV5fVKARPQZiuoPeHnOb9ZJmZVWEh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJ8dID8UcKn+XbDeMXb2MyQKKpYeuhGR0v7vHUXbRCNoCGmnaTBrV+pII8h/VkAM/B42uIJBstG5yw30R11IJp+FSuJn+a68c3eJ/o/snNEYi76/+x+RkKc2/+u1Kknle6Ur3LZDVbMJyTkaP4yogSGA88ULVV33VY6epa8AmaA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J75HbVh6; 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="J75HbVh6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CF2EC4CEDF; Tue, 4 Feb 2025 20:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699421; bh=Nm+9CD2nPcl5umV5fVKARPQZiuoPeHnOb9ZJmZVWEh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J75HbVh6Z6LtCHxDgPbAvM8qYoJNn17MULK7JSB23zFtspT6Ek4PqU8tY5PjzCC/S Ue8Vh/UCdPxYwaAALu1ASZ86wZgicJwvl9c9DXOGIuMctsdwmOOd2DY0IoNpp/fhLG +P08uAgsrW7Apf8qSSVtuOCfyQNCBtfbb3dxYAZFoRNFUa7AmU8ZfEDwDONYhqaOXn 0ExAFu8wvCJNZ2c/o/S4DOUi/C6wGVjSn08/FggR3Sq5D4uVyti0eSepoRX+j4uZAT XV1uGqSE0yoIEpOPmHKNTGKdsRq3Xpti/ypvPPHFuoyzQlCgZnqPihwL4VnwUiRRw2 QAIRM1cFW+I0Q== 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 08/27] iio: accel: adxl367: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:30 +0000 Message-ID: <20250204200250.636721-9-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Cosmin Tanislav --- 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 Tue Feb 4 20:02:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959763 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 CF3C62063CE for ; Tue, 4 Feb 2025 20:03:46 +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=1738699426; cv=none; b=aSmdDM3PTsNH7jTIXt9rhy8BsEww6eOV4eoZBeFGcMBmzDygck/yzHqNuj86PCxQcTVeyvsmiB+tJQBMP5I+gEudF4jb0m9/kXPo6A0CWLKjgolR+ZuvgnKP/K6JF22+o9K17XNAiF61PXR76Za9W8pcfs8KDLrAwdY1W/lonj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699426; c=relaxed/simple; bh=KLbzuszROh07IpUQxuuCuDxrci8rkTiLCFf3ahhd4C4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYgeuZMdlK3RpFvGSFX2Kd7hwJtYF3S2pFdEWZEI7K/BBx+/vhrx7XBN0MR1AUIcDN2rsrsZN3QCbGvzqDEj0judJ0UzIh7f1DUulrkkL3E7UHRMs5fUPh/ctDdFa5CbAVA8e8CUb4eLWyf3TVdhGRXh22HIYbDit357Vjcov/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yv1Na+uu; 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="Yv1Na+uu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F55FC4CEE3; Tue, 4 Feb 2025 20:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699426; bh=KLbzuszROh07IpUQxuuCuDxrci8rkTiLCFf3ahhd4C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yv1Na+uuyinpiLsBG9ZrQ4Bwth9kwbhS8Y7xeRSQAxbncU/aMqfPLtx7PXDPnOHZm dC/TZvfMavB17yN4NBADYSW8NttITsornC8r/R54pi+XUDf3kyjupP3n8IQiVX+LuH nhWAqYBFdWGRhZhsi3LpBlxPcVY/0OFr/uYQOpuRiwoYoCz9zrcba1WJ3C59OlIqs5 jrqc49N9VmonRu7UpfIVjoNVl7Wt6fpVHHGtxjjrl79SKESnlFc9EUZZiInnEXOa5z V76fs5JgG+GVrg12e1HdOybcN/rUOITJ/BS7uEnjoMdcnRcvi+enHESDsn83NfbH/P aHFVZSpkCdh1g== 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 09/27] iio: adc: ad4000: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:31 +0000 Message-ID: <20250204200250.636721-10-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 Signed-off-by: Jonathan Cameron --- 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 Tue Feb 4 20:02:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959764 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 908FB14B094 for ; Tue, 4 Feb 2025 20:03:51 +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=1738699431; cv=none; b=m+fSmGfxc8Z5OoqCTqeUGX+XeTvOnJqpo6NstKwdI82/Ynxd3DEKGm0AVIPwbYuwNUnO+rOVtcEIvIzfVPdqHKckgQEf1XTovRmqnts9xPpWhmYcD5PkESWhrHjFP0k7AMRoIaAhelR9xMlElsIUUcUOOgsn2Gxyobj6vlz1BGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699431; c=relaxed/simple; bh=5X2E1m0lJQ8mY2eFcoGegOEVVKa3ldQCRFOxhKwmSuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HTVjTe6Mh7U9AK5o3Ib1Hm6XT+qmR5lsoKnC877pvYk94ePqfai9vkjuukcexLgPx0s9MkRUa4KS0IJZDneyAMf5auBDCjBvVLVHt5AQ2+E1WzmJTkTN69crLgNqKTzP2A/H8QLjquxgacDE0210NAhN7nxX7KhWx7S5QyIYlPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qQ3rq2oI; 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="qQ3rq2oI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 289F2C4CEE2; Tue, 4 Feb 2025 20:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699431; bh=5X2E1m0lJQ8mY2eFcoGegOEVVKa3ldQCRFOxhKwmSuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQ3rq2oI8bj0GhvRVPEgUkCgIpF66MdmVWSz0LtOgDBzEvxzq5ci1ujxpWvxy0Ckg Qjj88jbNbhglUu6g3RJQG2SkC5Vi5JuFm0CoJiwhs8RXfZnoTVna6oMIyE0RUiEIHu cw1dULGresUwy240/S8cxUIBmE3/QY3QIFSfo7ywHNPo/Fx1u+TNrPpMjIxPCjzQRn +XixAAIunMGa1wwSYnl07qrDi9uslrxNL9UDoEAXOxAkYF6Wp9Mr+xCSFsjEJmR/cc TY0AffKLTn67iqyeXlEbVR5Opokb1RM1K+bjgMQiCSWikAljeY7QMBbQaJggSlUJvE 8ZR+UP5lYwRqA== 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 10/27] iio: adc: ad4130: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:32 +0000 Message-ID: <20250204200250.636721-11-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Cosmin Tanislav --- 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 de32cc9d18c5..1a38b52abbe4 100644 --- a/drivers/iio/adc/ad4130.c +++ b/drivers/iio/adc/ad4130.c @@ -1060,13 +1060,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, @@ -1076,10 +1074,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 Tue Feb 4 20:02:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959765 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 455EB204C20 for ; Tue, 4 Feb 2025 20:03: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=1738699436; cv=none; b=BWr72JOftOXnGf9pllWNVG2zl8vNTPiN1pO5l2xo26imY4/ffJbu0pHLyfYL4LXD+V1f2HN79vtor1+3Tc0XQ+5o2ZU6Kf1viFLg1+eFU3AE4FbyeSg2JIK3u44v9IO8LJ3vjJ3sqhsu6P1nLWfJUYuAGy6CiKJR63jWiuzpYbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699436; c=relaxed/simple; bh=FGFF9acb4h/zHpQ8mS/4HyarxD4lApfWvQ6IdD31nHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bgb/ShB/WNtwPkjPspuAJ9iUBrFoowUGaW1SDG/tXVHsSEfJf15WWgjPm+IdIDVYgjEMUAUojbw5ePPAEBH8L/xBHDDUXQNptQhpBe5MtnqosUQcJG4+N6A7a4/lAliBm7dvAVpXEYZqzvsyX7B5OxY+NNbVf0mQ5pxQKo2Eqqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gbcklVdq; 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="gbcklVdq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D60A6C4CEE6; Tue, 4 Feb 2025 20:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699436; bh=FGFF9acb4h/zHpQ8mS/4HyarxD4lApfWvQ6IdD31nHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gbcklVdqatmoLWA06rACzK4CwniEIF3VTo3XRiS9suLfbSJXI69zkzvMJt1ZIkpB2 46uywLH7b05I18DEO1XxynHLxQ7B/04V4FcJnaOk6gij1qwRiTrdGtFFR+KLLDy/y+ Ve8bebNJZNsDJTLa8pUzkzDjWFsFaM1mM2LcD59Icfh3+9sQ0ubyFabRUmjBkINTdJ YINc4Vos7rfBamYe3TnSKYP9rLYefv2yaKVlUJozgDGgVN4sSpNdVCk07sBfX3e0eb rWSid1wHzb08OMk0yBs6IQ8pe0ryVv2qZt0QcWY91Wa+Ctb5nK1kKv7LkKrSoJcL3O l062C2hBCjGzg== 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 11/27] iio: adc: ad4695: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:33 +0000 Message-ID: <20250204200250.636721-12-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 direect return with the claim and release around the call. Signed-off-by: Jonathan Cameron Cc: David Lechner --- 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 Tue Feb 4 20:02:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959766 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 4EAC1204C20 for ; Tue, 4 Feb 2025 20:04:01 +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=1738699441; cv=none; b=m4ky3tJsnND2gwJlBiPbMtS595YsxcLNaOVAihQIg1nlKPsj58aYAUdgbjFEv8cmFKFHWa+/Cotg8EKiSNynQbcXJwi1v+s2i1De5D2OmQGMDEeK0tNXKgLN0Wo+DPStg/TSb0WAOKG2JEjCeMGtGZFUlIJMOlRc+v0ythDicek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699441; c=relaxed/simple; bh=2dTHhAQ7W4Jn3VIiB5zMo/UE4SG7HJTqZFkCfsIkJk8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YJfrzDECIxNjeo187k8CtObFuvGldOBdm4f0p1teBBFXh0Pw2KbMfDKMa//cuwF2zTa4nEJ+f/mSuYCP7GpPo+e6CmhDq8zSWDOXx0DTtzFts4dRAPeE+s9XaxoKAJ895Kd6TRM564ABvBDIlphveNpagOd2g2AeaZw++ndH9XE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VXeBNX9v; 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="VXeBNX9v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1D13C4CEE3; Tue, 4 Feb 2025 20:03:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699441; bh=2dTHhAQ7W4Jn3VIiB5zMo/UE4SG7HJTqZFkCfsIkJk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXeBNX9vlP0YxGGE8B9jzYvAk50AAwkopBZeZjf2/T8qKaKZvWYQvZ6AoCr6CGqSf drU+x8sEspkd7O5XnEOhCMAdxLIr8gcy6wrTMhB1debyH4EaDMmnCVU1OEAji6U+0I UEc4u4xgqjLV7HMG5UFPnBbDETHlQKHwYyRj3dGWF5lseYA9AzEcBsFv2Kpoqkz6sl PSjZ0SyvKVUtBMfJtCSB5+k0BkzM053YPm78xAudktMgvvBNng1abjPDcVaRcA3D+E N+0Lj0kEHIptth5RAtpc1LJ3z8KI22Mn6YMmjWAVbN31yEunUWlW3UvtT7VmFuhqRn UhvzN/36zxsFw== 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 12/27] iio: adc: ad7606: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:34 +0000 Message-ID: <20250204200250.636721-13-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Guillaume Stols --- 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 Tue Feb 4 20:02:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959767 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 7AB5914B094 for ; Tue, 4 Feb 2025 20:04:06 +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=1738699446; cv=none; b=C3F2+iR6iMhFvL3MKb9RS16zH1IjIUDzxKfvjzb4uvJSwJsIhD5zjdBm6PHjAAyqsBn1ET1KvLDIudrtXnYdYSzxn+5Hg2FtPBt/4N18t3VI4fWE5ihi2GLfsak4hS3s8Zza8FdZZs2Qvve+OOQdffyixIhIrZXp0COyEAPkC1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699446; c=relaxed/simple; bh=gS/HIVU5XFKWydq5BDZfCCZHpWPqZUALxuaSdvvXK3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T/lCz6nkzXIAI5SradMpJ6T0879uiGhCGriBB24u+V4bb8GG+L7TKjnlHYtfcfZVUAU7fuXDFZmXHYkz6difcu5iQWA+UWkhaHw85e+ZHCLvR9LiQeDkGrGRfg+KVZuIh+Z42cYUrUF+I8hMpdsRuEwug0TQhSQqPyOD3ALyjaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kLKfVlWg; 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="kLKfVlWg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACDF3C4CEDF; Tue, 4 Feb 2025 20:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699446; bh=gS/HIVU5XFKWydq5BDZfCCZHpWPqZUALxuaSdvvXK3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLKfVlWg/o+jyL93nKzYrP/pIQw9L7lcKXOqIDaIN1BQlZDWHJcctHaEghbTAa40V E9oL00OHt5NBQVfjoZrkeOYhwIi/xs22whjW+KyjcKYTlI1RQ1rCouwDTePhg0RTE4 xcIDbX9TNnth/WSLOyflPdaRZQrUMNjsSolv60OePvryOTW98WZuHIn4pLzImXGbEm 8zRR+LhzdVhPEM2SQ6xvbxBzZjpJl5qptK0WaYwvWLVyUS86Gu65J/lfORwjB1XDug a1mG3o7CcOoaZ567tNu3SEs6m1Qyg/vLS+j7KQCMy5aztWxhmfBO9jl4hqdUWDptMM 2nbwNFneHgRYQ== 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 13/27] iio: adc: ad7625: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:35 +0000 Message-ID: <20250204200250.636721-14-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Trevor Gamblin --- 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 Tue Feb 4 20:02:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959768 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 67FB914B094 for ; Tue, 4 Feb 2025 20:04: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=1738699451; cv=none; b=qCWsyk2+0k+fblruRVZO1xU6OTXEFXOX31bVJXiPXrMzx6udiOyhx0KWXYlsRZ4BHpECyhMcMHDj+aEccxNVbB5BSnt9yr6SvIcu1ph/643EXSplIG32Gv1TB+mTFZNZ7edjPs0DF0/VVsdcZCezW+AkIsmjmLTJDJtmIMYUHME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699451; c=relaxed/simple; bh=VQQPgCb9Kml/QSbS6VX5xic4hEioTxLUCGnQvVzAHlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nszm0Z/qAvfyAEUnb9CRoza/7loC3HlT2MK6h/WI6kehY50HFqbaCJz8nbGXsUVby7BNODqc0zkwVWMgB6grBV9015Lxsi8deyF3AbGn2apjsdeqgp/5EDlLoVJ7X3Dy+T5x1kB5g7LlZPejh6PPKysSWaik02ij5ZeHN2+xq1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lsxqUqgZ; 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="lsxqUqgZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD97FC4CEDF; Tue, 4 Feb 2025 20:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699451; bh=VQQPgCb9Kml/QSbS6VX5xic4hEioTxLUCGnQvVzAHlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lsxqUqgZTkpnrk4fG32OAjeu/6eNuCDFqQ5xhtlXkJQhzbdjnj5XymrZIw9+vW1Gv t8R2V22TsVjjlhRxmjEB37H/bX6yV3mcPyx2BgfAeOnBnyVETzecrQjaUVd/A7p0az PNXlvihdmkx1cfA8vuvxYiPBQRa2ivJLnUkyfSFQZIgisW1PEMPQU8yphjgTRoEMsm LFjrt0nukkiQCTTFEEACufzD7FO5KgklDfo8z60FFzW2EVIDuwAHqkR9aT3jTe/cFO Dh1XTnXew6CT+MmkZV17OVS8ZttWTBVeEKvXeqYZtIw//Nc9oUb31IQyPqJwkk17rn JIovAbHbZOsxA== 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 14/27] iio: adc: ad7779: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:36 +0000 Message-ID: <20250204200250.636721-15-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Ramona Alexandra Nechita --- 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 Tue Feb 4 20:02:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959769 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 9C86D14B094 for ; Tue, 4 Feb 2025 20:04:16 +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=1738699456; cv=none; b=ragxj79VoMJIVkVjLTHWAFQLfZO2rSpwJz9uuugYkXmra4d9teSLlIxcam5mui2u90dvYXCO4Qg4GcYgYTZ3zAKIVVOzE+efU4N9wvYkLeALi0AmFJXO3M9kjvm2CNeR3pfbKn+SHF9cCHY2EVjiWr5c5u/Ju0foEtmBgd/DDQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699456; c=relaxed/simple; bh=k1sSmD8TAQxzuIv3y0ozlSdOLdqo/Whqicok0tKloIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X1wAbXD9nDLdV30Qg6nIaYqRa2uoO+9Qdtnl5UemhPUEg3TZcoOuN7Zr8lURWn/gSzxMrUF9o2Dea55dHPyJNDZTOF/wR/K8fmP2xnd6FUVRuKUQCPJZ8MMeq5ntIFDvwq7bwtyf6iVUDqj/lSZhz3LXdb1WXTC32lGHPabvVzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=knYiWF/E; 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="knYiWF/E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF015C4CEDF; Tue, 4 Feb 2025 20:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699456; bh=k1sSmD8TAQxzuIv3y0ozlSdOLdqo/Whqicok0tKloIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knYiWF/EgaDdV8DgQJKzgD1QprB5LUh4VzDR/tR/KM+QhyfXFplnKnqEXeBLcr+mq 3Twsrnpz6ntWvsac+MumtkHQbhw7gIp14DW/9d+VupHObvn9FTL6AHI936b/R9xI0p oyKZnPVo9yc8dvOxbaOx7Hb5b5V8pbL/IxGUjzR9XDljJVK+WbU6ORowj/mVtuQw3l ec6rx+Dy3X1BdTAjg02vFE4oilA3Fqrr4VYo8+6BkW8m2QYhlw1WSnbRUqNPeMNYWD 0AzxVQDS6vF59OAvfvlsbJ/u5VGKNws0zFVNWtThwGsC6vFByXckpn69zt03LgLBuk Sva60u29FC+Kg== 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 15/27] iio: adc: ad9467: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:37 +0000 Message-ID: <20250204200250.636721-16-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: 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 Tue Feb 4 20:02:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959770 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 1E6EC14B094 for ; Tue, 4 Feb 2025 20:04:21 +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=1738699463; cv=none; b=aGxl0c7hpf1+Id918osCqfubnwvXlItY7g4WcHHVSh9IWda7Z3t+ZAhkyYm5F7aE24Wvu3ochvEzXdCaojoJmRj77TS9tg3Dm7m6vF/VKLLQLM/5qsfXi2cZE7uS6sEmud3bPPu5BESiGbxQyulkgdvlprCM2EcC12vsVvX3z2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699463; c=relaxed/simple; bh=SY1tV3JYtB2adhbNbqinw55+2pPxbREzHzGcSCKcSyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C0YC6KeZb32F47M7RDMrEVQ2A0SfPPOvXo4Gdif2G6T7hLitC4h2Krg8V+SGNMYDBv1JHnmaVfABwUHci5ShHEEOUjnWIRZ1tIbowjNPuYxLXDUtf1qh4uQGuFrAhULJPs0B//rb6EDcyozOrhtEDE3VxZv3dUHbuT6DP0rxCjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ACZojCHr; 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="ACZojCHr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 296CBC4CEDF; Tue, 4 Feb 2025 20:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699461; bh=SY1tV3JYtB2adhbNbqinw55+2pPxbREzHzGcSCKcSyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACZojCHrTmdICyUc93/JHzD6UcXGIhhuLOORENfdLDgnJ3mPDZpXoyM0fsEjTezi5 ep0P2tGndhHPWHyyfBpWUIDBxNTW45WXwurrfOE2gS1y1PjPVVj1C0+S5mVf5LL6TO PgqPls72948s2cNKt0L8Q6Z7bmESRxY2W+1ssQLjmazpRVHrOoVnQ67TyW5/cHvnab a91C73GGLXKUuvrygiuwjPatvHBXg2xbxRF4u4eZbzBC4ozeoz/LLR7rnKkhDxkqAj UjnSmZmClW2tyZHvYY3JUyHxpogbvbigadgYFIb0G+zg3+Z28oPk1nC8u2+zu8JlIv /0HSY5DUp9bKQ== 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 16/27] iio: adc: max1363: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:38 +0000 Message-ID: <20250204200250.636721-17-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron --- 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 Tue Feb 4 20:02:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959771 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 46D3914B094 for ; Tue, 4 Feb 2025 20:04: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=1738699467; cv=none; b=sHX3dyIclbtlm4mGdaciUFAxMtwqtCq6ka/5oUsCTfkgPTpuuy8fkoir2DBeobA0XBTl+nFFTh21LCBsRB3iKFyBn32cRYZ55yOewuUGyA3qoDFDpxISbX7Tis6XE1SDM6qYLC+R+cU1hNGJ/Y5xekn/pvRX81CsLgoosGoFMTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699467; c=relaxed/simple; bh=bj9PIC4AWiBUVxir3ZC3gRE/WktjUBdVbtpguc+sHy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fkAtdWt5VBXdlVx/1sG+zbv8JVT/JOFEEyL7vQUBWum9/7JZNsahdjuslpOtci7MED/Tjjje2Q3C78WQar44nLA6JfNGTGB9hYbr20SXuwj8VIBPjXtB3nmQlZw+L34eYOQ44Gzw0aGPL0xBWR05UDByYVjH3uv/OhctMsWPuAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l1PKT/df; 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="l1PKT/df" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14A7DC4CEE2; Tue, 4 Feb 2025 20:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699466; bh=bj9PIC4AWiBUVxir3ZC3gRE/WktjUBdVbtpguc+sHy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l1PKT/dfJqUyt0qDAwtPMljgHR0/9KLTAM0cv6U+tNJn2suohQdNysSbTlFoLdpcx P4N/oLEhRyixSMqALXqvZNJc32m9AcSnEe/ZXrpmhDn9Qf5q1j7SBFTKWr60qorFN4 ciT/VA3f2i6RllBBDvssgfT0lsOaLePCFjMr27qcYPW2IzC1w4p/TEYpDf84vKmTmU 9kJBvMejG/nj8MkjGSdvAzdoZYTrUQ+JVxZrYGH8n2yKaLr2V6Sn0/HRI+8xoS10RE mHABBezalRqbktg0gz2vtW0Jq0Uoc5atQxzbD8RqOQdiDR+tJibHDQLXjm4jEZdkXD WUw6maINMY9gg== 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 17/27] iio: adc: rtq6056: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:39 +0000 Message-ID: <20250204200250.636721-18-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 Signed-off-by: Jonathan Cameron Cc: ChiYuan Huang --- 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 Tue Feb 4 20:02:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959793 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 32F2014B094 for ; Tue, 4 Feb 2025 20:04:31 +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=1738699472; cv=none; b=ASgpsO7QAuRh8PnfbvphNrezQvgCiYKHMapYhzqTS9m/0Y7T2f3czyVN0daGmdk1vFYGK5XMH4ziKxm84vcDpRxyW/2/gdjPBOH9WSQdi1W6xAF//3kaLihSjnbh5nVWIbGA1IXuInfzWAnfxaJTYQedn/3zW3EjtnlrxS54+e0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699472; c=relaxed/simple; bh=W1+YFF4zGS62LITFamYUxaCTZ5xJP5oBTswhyMteZAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RhNAEAzAClCtBUxZYoWQ3gWxqxmeioX5/96n14eUCjCbhck4AGkRSOoT8XyftD7GTQgzKWtVvDbCiFSyrvw7cbKyNqKD4oJggeCir/DHfEAE0sUG/unsmzAc1w+KGLh1PRZpqVbVb2f5ntfqsvaeRlNqBI0+XexG+9S6JM1O28o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E9XcCsqF; 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="E9XcCsqF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BC29C4CEDF; Tue, 4 Feb 2025 20:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699471; bh=W1+YFF4zGS62LITFamYUxaCTZ5xJP5oBTswhyMteZAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E9XcCsqFihWNwRynVzgt0Ug4frxvypt07YL8c4KGLgJEbdtUhSPhIu9EJDi/ww2tK YFrUwU/SDKxwlWzLhpYz9LNwmdc/e4JEHsdDSFq+vbd2tFm6OT7TiPGhaGahMK01F9 73KETFz4qI0hq1qeNN1JQKV60QcmECQf5qYn8oS0+1d7P7z1WCpRAETdrCKeBjQFl7 1TCxQ7AfHrSBqRyrU9Z0ukIaPP1XIZSu5Jpi+eqGQEAZevWIW/9oTkJ0tJVhMoVhP7 nS8xarDtT9cNiaESBId6cRR96b5Tz4L/ioRxie0PbxJHf3W0O7+91tVl08fASDxu4L GN7Xb6IdlegOw== 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 18/27] iio: adc: ti-adc161s626: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:40 +0000 Message-ID: <20250204200250.636721-19-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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 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 Tue Feb 4 20:02:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959794 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 C6BC714B094 for ; Tue, 4 Feb 2025 20:04:36 +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=1738699476; cv=none; b=qTIUzek/44UbC2Qu+ECe52M38KMhhKgQV1r8eY3GZumDi8NvtP8hUFkV976uuJz24cmYs5rXXV6v4SVYebY+85HHySvMXCIesL/BculjOgu28xovY4kdeNgIHCvs6JDFj1R5acAGDxHuCUpt6kq6snITP4YUast4FqxX4raJAl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699476; c=relaxed/simple; bh=OhJ14cf56WuSmCqfPqK9cbdK/PH6cPuZELLteOo9BYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hOBF3QrAAdLBSpD2QffVEztM9p+/6+i46j34muw9JXUinHxuMCBxRb1/AW/udv2pb/vi51cFDlf9hxSzVw0nx/CH1fldjDJEeiK78jKi7t8sStAe5L2waUW0hIwEH6sdSdpr33bGRSd7G4WRZRRzwEo85sm3fo6tVLakpwbyAGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q1bTVmvU; 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="Q1bTVmvU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 370EFC4CEE2; Tue, 4 Feb 2025 20:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699476; bh=OhJ14cf56WuSmCqfPqK9cbdK/PH6cPuZELLteOo9BYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q1bTVmvUaNqsPFsqTK10CyA02TQ4zGMw7DU+YJzu87f4uou21gtdkPVCd/6xQz3VK JhcI+kOTUDiBA5qGt6WvD5GnnI/h4CL8kNX87L/pvPywkoqewaTdufmEyZV3kpHYXH 1QsW3IzKxHUOJQi2k3/uEId+3jTgccfQi0DG1W18MP7FKz6haRKecMDuxDs6VuG0Xw /pp1esoeeI7AlziWJDHP4f2/Ax0IajH7RSjTa0Yvkh2aq9FpvenlU9TtuqTQxutQK5 uc1lVQf3lqJ/W8M5XRGEisZABbZNnErS7Hj7CNVhlamsvZU9aoCPOoLJCuDJLWwMMF XUMCccb7oOr+g== 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 19/27] iio: adc: ti-ads1119: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:41 +0000 Message-ID: <20250204200250.636721-20-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: João Paulo Gonçalves --- 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 Tue Feb 4 20:02:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959795 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 D530314B094 for ; Tue, 4 Feb 2025 20:04: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=1738699481; cv=none; b=Pui/S3zd4X3PE+8GQrcops1y6qQpe5dbbbpmRyY532VeWl+qZ6/IbkEqyR7PTxuMmiHrTvP0DYbhyK49bjzCuGCB4YWBK4urV/DtxklXPqyFalSQ56W1Y594LxPQuGXucyU2jv19PprgB4FbF1h5mhQxo5QV/Nm/f7YqbhzlFIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699481; c=relaxed/simple; bh=b8qf5o8/lc7Hbk5D9Hk0uqj6i/6AWvOGVFKenRdE82s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hyO67J5vxMPmd2GEkd79UDVHMGzaMZ5vDSf70d+8bBtWsNqwlEIvw6oxN0dOFae2jQmGwesXaOqimxKLq+eZl7EUr3kfjAcPlSnFN3c/ISN+BGAzTHFhhCqKBT8/olFbFIoFY2BBIcxg3elwcIcicnWEeJTO8SHidDP9PgOr5Aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hwF4eYGu; 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="hwF4eYGu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22857C4CEDF; Tue, 4 Feb 2025 20:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699481; bh=b8qf5o8/lc7Hbk5D9Hk0uqj6i/6AWvOGVFKenRdE82s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwF4eYGuOckxkaR9o0STyD8vs0TMfeItqk6S+/Q8Qmi6CcZFsb2fS1jtN6vAOAiL1 VwOkV6MsYmVi+ROXPL9k3r4r1//9O0i5LBlTVWr+sKDZNWEx2/PRD6Ds7dxH18cNV+ jwQd40dqVOgJteZ648US6nGk6Jf5CEvg7Fwlz+4lAx5LpZDdjg6T/lhQ6sCNc8FBvQ 8cOSlNksUGXX3aDwnnjt9iNCpJGlboncYeESKNgyg7n6qu+qmruGOZUnO4yrcBUpRy LJ14jhv5iS1MAc7dCCM5Og4UUt3bYeziHkEZXoCIMW6M47W7eNIoqMvUyc5MoeOd6a pRnSoigxrLvKg== 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 20/27] iio: addac: ad74413r: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:42 +0000 Message-ID: <20250204200250.636721-21-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: 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 Tue Feb 4 20:02:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959796 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 4164014B094 for ; Tue, 4 Feb 2025 20:04:46 +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=1738699487; cv=none; b=m7MOa8IDrtQr0DIkrW7bO+9M6bqGTvRFFaZEPleG6yGtVipJZvFhzONYKwhaHyDuxjB0t97ijVv9poCLu25v8pQb3VVqnOVrA+bUNL8u9nUORlaihiya7jfL3K7omew5UyDhM4VEcDxkSyPkFsuqTtlAhC/4itrivavtzVv8S3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699487; c=relaxed/simple; bh=naa36Kw/w9Q2w+OlD+qDpDcinPo6Sk3StWJlaf/fk2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMfkAhS6kKUmbQY3h0VnFT4P0nk/DIQpd2fSodB7eSU7FcACMrvGh5N9sBa0Cq3l8zgehsdmyjqhvo1ylrqWxK6r16A5tUSN6vOiMI2O1gaA5+9Ew/b4S//ktWPru4KqGDZGhJ33sKRCWyZuf/A8mP28GBkC7MelN+BYEOcldUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m0WNONTR; 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="m0WNONTR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26C1FC4CEE2; Tue, 4 Feb 2025 20:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699486; bh=naa36Kw/w9Q2w+OlD+qDpDcinPo6Sk3StWJlaf/fk2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m0WNONTRIEqcbbxDcM6Gkbp6YHtxtziYUyFgLAuJmht/RWB/8H0Y1NDeRt+pRys6/ LrBNo0AHUgmhk2G28NCpyopzXrsr6Pn4gozQUPzABsn5bRg1zkqXa/ML6hbhqEeWV/ 36oE2+G3xeNOOGm24A2CmYjZ2xT1XWovEszQ1rTXwMpHi0phAstb5hbXylnXw5wHLJ 5cueNY31wmFb2c7yRSxB74s1IIM44YEInt7rEFOVgZSebH1QZlAak6bcEYfTAL9AkE cxHYX2IAEInKMqTH1E0D3Fq6zM51KIdGVM7nfv/6MEfJh30/ICwj8/o1HzxvSgLw7O dc1qrJKaq6g0g== 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 21/27] iio: chemical: ens160: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:43 +0000 Message-ID: <20250204200250.636721-22-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Gustavo Silva --- 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 Tue Feb 4 20:02:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959797 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 4F2D614B094 for ; Tue, 4 Feb 2025 20:04:51 +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=1738699492; cv=none; b=HbE9wIFUxjQ4YmJcHbc2H4x8LNURQrwEzB0MroQPFIwvGy1xCchZNwQdBV3Gey+dXF+rd6oENcowC6ayYQ9JoReVkPW4Ee8QJs00RQeNn1hWEomlxxsY3XJpXCRE042LXWmWT96UCJpJjiEHFDebkyUvoWFALwVjNpmMe0TsSnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699492; c=relaxed/simple; bh=Nxp50hUA+/KtmNZKJDIGXuw9CLN+asgaJyDs60V6Fa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nzyTh+ZoKt3U6b4u7550rqFOXhILKQWF2g3k0z2c6TZ7xlWg16Xh09x7IrnDxlPfZSt8IJF1EqKCZOJUwOq/ShGFIs+wxfF9DVY7z3KSuODEZkeN/0pmdnbEfwB/sU+cxK2c652PRdN1rK1l+kAPU4XVwyIrh4Q3riZ0rgQoZ+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nojIAGML; 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="nojIAGML" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43C96C4CEDF; Tue, 4 Feb 2025 20:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699491; bh=Nxp50hUA+/KtmNZKJDIGXuw9CLN+asgaJyDs60V6Fa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nojIAGMLJJVV367hrW3yIUZbDCDHbRaZ9G0jP0JSq50+1Xa4Ik0n2y6w1KIyulD6x Na6OmmZjgv6dPKGBRsQruTOC5NFW8XVOkaHGSTr6m3GlSzjRLH0uySwflDOcOOEtJr MS4E5WbW5nojaTh77/fEYTxLh3tKl2HhVm0DA97aN7uF+HSzHDgCbup+gAKPYkr2e7 YujTyY/uKsT5J9LMLTI2iVwoSlU1XwhwNbsgY4FJR7gdiM9Q/Aaix8z8IpO+VStFIl JEpkhIgjOQv4GfZpVdhSEesE9zDeTiKathxTLm3iS/bzo5LY1MiSwwEQLggdZvr4Hn hKGcNpbi6N4nA== 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 22/27] iio: dac: ad3552r-hs: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:44 +0000 Message-ID: <20250204200250.636721-23-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Angelo Dureghello --- 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 Tue Feb 4 20:02:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959798 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 5227C2063FD for ; Tue, 4 Feb 2025 20:04:57 +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=1738699497; cv=none; b=C9HWNQZg75bhgytAEttOX7+7EDQjTem1LzO4yONOA2TM4XUnD6WQ9RCCoWXW1G1T5R1I66EePztboeotetlJlxW76ZibYTbHUIMKGrfNp05bIAO7MaJPUXOYoM/LpKLY+TyjsJSsgw2IptLsZSNm/oVRYJeIlLGvNQKZhXVMWr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699497; c=relaxed/simple; bh=IqM7rr8s7Lgno6Y5qG0cYwimP4qr7aOPjOp483MBSbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nNrez/BYERctFGHEOnUSj5QuxhtgyEIgB/pnC+7IR25PNqW4u+av7nr6jap4xgEAXZNJMBouSkz2fjpxsmkojdUHrmBzMUlncbxfp1eEUP8zRSNp2HJyucnyhQyrhZJ17+/nuIZDRrokAtAuJG+YfdJhAFjf6EY66u7xd1NUrW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WDTO68TT; 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="WDTO68TT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 611DCC4CEE3; Tue, 4 Feb 2025 20:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699497; bh=IqM7rr8s7Lgno6Y5qG0cYwimP4qr7aOPjOp483MBSbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WDTO68TTVeSwAUYIat9Gx+j+E4zU7B+JF2cyvPUhImo65OC7BTTdk9sIDuLW36pUd VtR1oBDmEzhlWQVZW51QmH23dqRAYxV92+aWDGIb77TluzIIy4pj+BwGM0b9D4OuTu QUhor2VBFtoXTi/JH2IXpiCMec+wCRwzT0ktlDQpCoUweWuc7Xz1mj8R9NgxZKydxN 7begCqIJgilbyS4dfBq6hVKGMRhUZbrGkysm1wrIKEG607WdaNJC1djlO/31qb69bk 8wlqSq3gaPIacM+8Yq/x7SzS09ebGBzkfuF1IZjRbqG7PCm5+d29SF0oMB3I6GZJET 9oKPzDQDHDO/Q== 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 23/27] iio: dac: ad8460: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:45 +0000 Message-ID: <20250204200250.636721-24-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Mariel Tinaco --- 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 Tue Feb 4 20:02:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959799 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 D1191219EAB for ; Tue, 4 Feb 2025 20:05: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=1738699503; cv=none; b=GfrALmhlqNYb6nBf9PPL9MImqYW7t9M0mVeyKxb+vNLoGNYug9s8TArtYdLOdfioUHFeakhjd5i4StBGBa7DIVMAQe93fCD0eWnL0sR+v1qtOZtDzoywH5nGHoI9y2YjZEBcaVWt+MrLifi3FN7qK4SMUA5GOpNw8SMnLQnuw08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699503; c=relaxed/simple; bh=q5GYZSR15YdatvrqvGQgioN5BJYDjW+MBstI2u2suQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D6im5Pl1fT1h50sS4Xk4Ye8CqjcCg9J/nYXl3BhRLTY6S/GqzyMbkYNG/puIA7ShPEsvREpf94rKBen1ffJdhYS/WT/Renc5QR3aqOll5qpKigqxMCIsGkPoLWx/V8pKSAM/+/MdiYxtEx3K/b1mWaql1nPmITNU5EmHpsubaMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=imp9RwNV; 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="imp9RwNV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFCD9C4CEDF; Tue, 4 Feb 2025 20:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699503; bh=q5GYZSR15YdatvrqvGQgioN5BJYDjW+MBstI2u2suQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=imp9RwNVrqnId2eOB8fQelsycRcUHFA+YFuTfD5sjy1LiPSkLcO040u9sfxvZ74Ny fSQ632Oyk9hnV0jLFZjdJ1Rj6ihnBy6JMzwbTGQ8k8QS0nkE2tkZZTHfYkiuKbTy/Z zwsaPim8IKYP/uNSUONuktgjZahwwSLFwHzKJxTO0J/GyULi58TpcLiJCfCyVWzFcG Pn9YeNAOpil9uAty/63JH2mg9NqfR5zzCHcT1DXdj7Po8RJ+i+gQi6F8Pr26Mis69u CUrJuevbxibqHXnGACgr1+r35jGH/tC+r5B0Nekz+gvSz3eoOjbGr4ivn8MKkiDGPo cVok8+0EEEDWw== 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 24/27] iio: dummy: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:46 +0000 Message-ID: <20250204200250.636721-25-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron --- 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 Tue Feb 4 20:02:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959800 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 1CD35214233 for ; Tue, 4 Feb 2025 20:05:10 +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=1738699511; cv=none; b=YZUwCp6n1FdBqg74ZJSuca2Z49WrHd15SlW3iK+s4zTE6yYWuU1XOqbFlob1cwwgqlxkFK1gUii6YngY2zOOpw7FrppLN7KI8L1zOBvXq4CUIACOxrqq8Z/CfS2yI6ziUZoMmTHSqqCYVbcIpSi3KtKu8Dyi26Z6kvcreuYR6oE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699511; c=relaxed/simple; bh=BEUJh2oBdBlqp2ozGWkf82WukJcYhtRL9vauOpsoi0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eniy5Jn9sOkASQCKhb9gDFrAkGHnKr6NZupkKAYUIjbUMobbrF1hc+wOmUv5uK4HZDI3sCpuuZR+Z1XiDI81fzFJhCbMMEwOkj+qCLTGctJ2WLvIZLiQugnU+GXdCz7L6AHU2wZ6zZJbLStLjrtopW6ZO7X4Bp/T6etxFw6Fm/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ltcCzivh; 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="ltcCzivh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75939C4CEDF; Tue, 4 Feb 2025 20:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699510; bh=BEUJh2oBdBlqp2ozGWkf82WukJcYhtRL9vauOpsoi0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ltcCzivhYB0L/1mTxok4vQeRdqba0Zh0BxYEGpPVHeGrSdhWYgDvlCgg7bK01G9yY Tlge7nlqB+OOw6kfXX1W0GWo6pRcJtN2BoP5ajpSoBpRiaOCTq+uOaSMMZbZREspG7 KFCtqkGBxogIano6C4s0Gm0FSENZMumRayAaXD8mNPpVIDVSAJzU5lvlCbtAuYbaAS smo11lbCTf1KJWjYwWcq+rFbhlmeQCTo/QGec2OwRs5rEHl4xKNyZcxi0n3IPdhEFk JDj7GuxVoZ+2ucsB4IFkB+2dTIlwTQvfiEOPX7HM1bFxtwNs/3BNRIEJt9WG5JIxb1 7jVndtK/J6TvQ== 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 25/27] iio: imu: bmi323: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:47 +0000 Message-ID: <20250204200250.636721-26-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Julien Stephan --- 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 Tue Feb 4 20:02:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959801 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 47B2E2040A8 for ; Tue, 4 Feb 2025 20:05:17 +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=1738699518; cv=none; b=l8UFQHKpdDpR8fG38NTaD3iPjyUxYbaYSWFSlH3X61YGbYBigNhM6BEIereCwayf8KksBse4bHAiVdtJkMrTXkUiTn5gxxN6AuOZ6H+XvMzva7UGOaOYqrOLDQvsbxAx6McZNBXA8P/tdrtz0wo8dk8zzpjzj9ygUykyDYCuTrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699518; c=relaxed/simple; bh=nTDvAiR+VPxLXANH/DY0hOcnWcZs8ukFjSZU4w2M5H4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TKLsrr80PihiUJqLLemY9DL68agP/m4AlNhjczEtVngwdnZTXN6aAkrapLI188c1vyros/h7fL54A6sBfHPPPT6cRPQdyU2jaIRbVY556yxwwRSeOBe/OIErkh2bb33aGsLW44Xfjd8A8IbOOubZwnobFAcZbnWmyB2P2KS/ZQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SOtt8+3v; 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="SOtt8+3v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ADA4C4CEE2; Tue, 4 Feb 2025 20:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699517; bh=nTDvAiR+VPxLXANH/DY0hOcnWcZs8ukFjSZU4w2M5H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SOtt8+3v7CCmVS0Fj5hgMKcd5TDqYFcAQ/qH93FioERQYSzPedFUGYk9bp8F/9eEh llsHFfF9gtQFrjwJwDYT3TurEhQSHXCrWXkpIDw5bMw/TdeYKrSkhHvGondXgXcGGt Jg8uGgKnMcxozAjXfRI4eTRQS3+Swytfzfnxl+OKMlBnr3crv9IOVN3k2A3SZVAuhi WMPqMlsu4V29qkbf9JW3qUXcjnHNw8Az3WNElwK0sBrJwb5xIQizRxMYAwAV914lL4 5UCvobkJJ0Cw1Z5JGfsDWLv3Q57K1yL5jYOJsbv6Ef8dTe5U7AcBw2duUKdQimoLdG Qj9Wy1a29mwEA== 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 26/27] iio: light: bh1745: Stop using iio_device_claim_direct_scoped() Date: Tue, 4 Feb 2025 20:02:48 +0000 Message-ID: <20250204200250.636721-27-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron Cc: Mudit Sharma --- 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 Tue Feb 4 20:02:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13959802 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 69DBA14B094 for ; Tue, 4 Feb 2025 20:05: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=1738699525; cv=none; b=K31KOkuuaIZ/iBzU5sTH/2KbTSEdnUaI7GS/QeXHJxHEErqzGQplIan6saCsSIVFqVVOti7wQN/glhz+jmHH0ANlqWMnCIXOWK2da3MVRa8I2rrz2UIvFy3bVupsd1Aj6jq6QU3SaAhYf6lN/MsKYGretzop30JS3dDxHAssiEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738699525; c=relaxed/simple; bh=j704jEM6zRl8dthwMF87HDqSIh2q28YaY8n1BVqvnxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qw0NmM4++a//BgT4nI6qQELOMbD+pSQQWmp3jzYSlxwAHc2SKCupsBzPHae+wmCrzE0tl3IEDoTc3n5hkaY6hOEAv1KaSbklAta0JYZ/JzDCCH/1Llb4WDbJxwt3fRwoy9dD0QMdfs43Ddz0nUTU3Cws7zs8Qf6kbCNRdgoIMRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ijjsQbCL; 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="ijjsQbCL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1F2C4CEDF; Tue, 4 Feb 2025 20:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738699524; bh=j704jEM6zRl8dthwMF87HDqSIh2q28YaY8n1BVqvnxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ijjsQbCLbSYa4N+/U4AUW5PuTkzRsZ9BQQ0B6mRvM4FB148/YWt8LccharDb0i5RU RwuRBkGQPBANyFCz/5h3HpzsfweWaRJBZfFSIccvAiXRjhB+KREGqcsxF3mtUezLYl 0ST4XfyfDPh8B4VLG5nnRVqNIRpjzbZJ+iqJyHDyCsGBeT+FAVNt8uDLro+prERfIf BDyoL/k/EIN0VDfJEDeawLixn8x/ZQXlvv2fwUKGnEwpNR8JaTaSUDfEI6pIOF5bWC Y4AqLVa7+DYAs9g7f4a6P7fNZBwXfwxZquwV5dKqTungZoNDvXaK8eviJMBViDokCu Fyl00NkUdLcjw== 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 27/27] iio: Drop iio_device_claim_direct_scoped() and related infrastructure Date: Tue, 4 Feb 2025 20:02:49 +0000 Message-ID: <20250204200250.636721-28-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250204200250.636721-1-jic23@kernel.org> References: <20250204200250.636721-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. Signed-off-by: Jonathan Cameron --- 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 fe33835b19cf..f8541468d391 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -9,7 +9,6 @@ #include #include -#include #include #include /* IIO TODO LIST */ @@ -687,32 +686,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);