From patchwork Sun Jan 5 17:25: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: 13926666 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 B422C8F6C for ; Sun, 5 Jan 2025 17:26:30 +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=1736097990; cv=none; b=Hr2s1AaJ6oQczPVTWiA+PI2x08yj0chzEExK2aU0YqAmPPwyk9uxGxBWC36jo/xtFWuWZtegCCcUMO0ba3iTdVVTrX/SP59SrjcShtWKRZYeB753/CINy178L9U1iB+YVa63PvaT8DO9DmAf3+2uAT59lUSZ2VD/nWCLWoc2n/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736097990; c=relaxed/simple; bh=uEy7XfVyKiylyEn4Evs4DnAOBsFPscv+E6YjKvkF2ZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c16zRhYXWYfLDw+zlSJDh1yVBD2aV2AJT3Ib283H4cSzGTVvVXCsbaE3EQpBevVCxbYKHZOO4bQo3xystlAZiphcF3VKrGKDRW1T8AgeYT4TbeK96wFexSe9nCgezO97w0420H4W+uB2nT5EPM85o0O/dWUkO24aBURTFZ3uxXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EiOFvpHC; 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="EiOFvpHC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54685C4CEDD; Sun, 5 Jan 2025 17:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736097990; bh=uEy7XfVyKiylyEn4Evs4DnAOBsFPscv+E6YjKvkF2ZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EiOFvpHCe+094RCe6z3zcQ1jFk5jhqgj2FivvaBt4kwMe+Ce9qobHdoBwDy/652I2 7RCPu/dgLWqbtK6SR9gGwvJm6NtOJhvSXZh0a4u++CNuTJDpzOqasdsRoq0dXdnYZ4 8ZpNCpOLcVXY6gNu/99o1/Ga+g3vax3N0mpJhH7Eb2j9WECQkS3GGvSMPoCLZrUrMp 8P+Qfu3yUHowaCwPRwK+mhzg9e69PyosI1vv3Z49e3pL0xJrwGQY71ZoaB31rSXG9F CEY3VS3FFmG1qcnmPNoJVdiAmv78RjIi+kuVevdT0UhUTlFujL6nVQok1A/fImqOw3 Ejm93QgGRRkfw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 01/27] iio: core: Rework claim and release of direct mode to work with sparse. Date: Sun, 5 Jan 2025 17:25:46 +0000 Message-ID: <20250105172613.1204781-2-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 no 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() Signed-off-by: Jonathan Cameron --- include/linux/iio/iio.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 56161e02f002..4ef2f9893421 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -662,6 +662,28 @@ 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 false positives from sparse. + */ +static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) __cond_acquires(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) __releases(indio_dev) +{ + iio_device_release_direct_mode(indio_dev); + __release(indio_dev); +} + /* * This autocleanup logic is normally used via * iio_device_claim_direct_scoped(). From patchwork Sun Jan 5 17:25: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: 13926667 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 653838F6C for ; Sun, 5 Jan 2025 17:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736097993; cv=none; b=MgsLTlSEQNsOiAGOG7BQnE4lyp6feWNJklbX8Om4fIEwLAM3Xj7cL4eRXQTIL80VX0SIT/f2lOh5Pn3C6cAvsbh0pDMj5+JyGuWTFVCLdBiipEL+RNsVIvU01stouxwSXD8IfCkiMUwybrycirh0ynNEtHGDyu7/jr8XvznNx7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736097993; c=relaxed/simple; bh=tXARHx0nU+EFgnfS5x8+8xk5+/ZqqRKljBqydqynMrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fCxeqBtHfsR63U/CO+LUhIO00lirZqj/3tgYrcGcQm3cYvchKqGH3AEnidUR5KOGrING/WIJBr9wIVReeiC3bJsvZjNADLRvxlGwTVnfnAbI1dKNg1uTlCLKP2izGGcE5gi3yFFk5HI58g8MtyPA0vuCVATbXH+H7tlrA612E6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F2iyfiCN; 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="F2iyfiCN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 020F1C4CED0; Sun, 5 Jan 2025 17:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736097992; bh=tXARHx0nU+EFgnfS5x8+8xk5+/ZqqRKljBqydqynMrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2iyfiCN5QTz+r+TXJXhj4Tf4BVl/4bw3/oSp5Q366uxKYAbtuyi5pZ5xPNzbuHkO 3eWjBKOf6Fmmk1aayG027L+1x6VvF7tfZZFAggQslV3VlOFTe/O6jYq/8v9A2YJqaV k+2Oo6RCwdX/OgTG1L/715vK1E7ErAHiqUvdysBJr3KoMvvmbZUPbLglwamnG8CrkY NmDQ6tTwlt3kC42LdyuL8sffBhpTDJOWK5zyAxTqFY+Ucr8n99e9tFz5wRI0l42Jn0 vXNVMtLcESjSdPsWc1zr/m4p5fPqBr7uD0vu7U3y8hnn6SFbjp8mXaE5xOfH+5mYiq bQiajDomCsWug== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 02/27] iio: chemical: scd30: Switch to sparse friendly claim/release_direct() Date: Sun, 5 Jan 2025 17:25:47 +0000 Message-ID: <20250105172613.1204781-3-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 --- drivers/iio/chemical/scd30_core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c index d613c54cb28d..cfbf2f5e9443 100644 --- a/drivers/iio/chemical/scd30_core.c +++ b/drivers/iio/chemical/scd30_core.c @@ -211,18 +211,19 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const break; } - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) + if (!iio_device_claim_direct(indio_dev)) { + ret = -EBUSY; break; + } ret = scd30_read(state); if (ret) { - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); break; } *val = state->meas[chan->address]; - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: From patchwork Sun Jan 5 17:25: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: 13926668 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 94C198F6C for ; Sun, 5 Jan 2025 17:26:35 +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=1736097995; cv=none; b=Fb6rpAZCeVfJs9ANh3/H7ZPllZDCe+lbwTra9Evg4XnFQw/bKyfO/WXpjbWFyvc3DJpJvYWDMuDvO826CAC759A8Iw4Nv9pSEDvfOCgw5yapAi7m1w51oAzx5AbU0/HbTgHfERwSxhfHWddWvmDKFUNxuA5hB9LJwQNXNR6Jyl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736097995; c=relaxed/simple; bh=aKpFi2CFiqxwRwNoe/t7d/hwfIUVBzlXfZDW199DHIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UalFnsH4Kc4Rt8YLvoENooWCGUfC7TSJN4Qv6j6UMta8MAkw1yEwQsKy0muKa08RovLSGgQq74z/oQeymP6VzsF35RJx3oy4vpZX5WrtO2uAv4PWDj8AlCXAmQvcPaLnCm6TCJ2CC5DycmwD0ogFs9TknukMSmXNwCVQer/8vIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IAJvzoGt; 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="IAJvzoGt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AB05C4CED0; Sun, 5 Jan 2025 17:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736097995; bh=aKpFi2CFiqxwRwNoe/t7d/hwfIUVBzlXfZDW199DHIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IAJvzoGtkMEP19awp6Rtna4bGzu2LCJuvefdfHWIova9Wm1xeOJ6fOICE3MgVepCZ AxMLtCS/2Sqozd2r2UzH/UGG3lYHFPlK6eZt+f+74Ik9NATd+oQh9uKmOhT8pylr+Y nz5Uhnt6s57MJw1/6W5gXTrjylkPgmzO1kJ2b0Yxx+26Qr2RImEkC7wvkB3CJDt3o0 WKURSzDyx3V+c4bjewuvAeF/1x3iagaE85Y0B0t91ZlUFyUPnBYrTqUUrrXJzuQVr0 CcE0U5RA0+JSEuqocaVTydzjAZOXAxB+SKthH2At7HkdpNMg/9ttIF5fBPJ7cp/a4b 0AIewNE/rgGQg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 03/27] iio: temperature: tmp006: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:48 +0000 Message-ID: <20250105172613.1204781-4-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 7beaabc9ecc7..4b3a90538eec 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -85,19 +85,25 @@ static int tmp006_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: if (channel->type == IIO_VOLTAGE) { /* LSB is 156.25 nV */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = tmp006_read_measurement(data, TMP006_VOBJECT); - if (ret < 0) - return ret; - } + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = tmp006_read_measurement(data, TMP006_VOBJECT); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + *val = sign_extend32(ret, 15); } else if (channel->type == IIO_TEMP) { /* LSB is 0.03125 degrees Celsius */ - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = tmp006_read_measurement(data, TMP006_TAMBIENT); - if (ret < 0) - return ret; - } + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = tmp006_read_measurement(data, TMP006_TAMBIENT); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + *val = sign_extend32(ret, 15) >> TMP006_TAMBIENT_SHIFT; } else { break; @@ -142,9 +148,8 @@ static int tmp006_write_raw(struct iio_dev *indio_dev, for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) if ((val == tmp006_freqs[i][0]) && (val2 == tmp006_freqs[i][1])) { - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; data->config &= ~TMP006_CONFIG_CR_MASK; data->config |= i << TMP006_CONFIG_CR_SHIFT; @@ -153,7 +158,7 @@ static int tmp006_write_raw(struct iio_dev *indio_dev, TMP006_CONFIG, data->config); - iio_device_release_direct_mode(indio_dev); + iio_device_release_direct(indio_dev); return ret; } return -EINVAL; From patchwork Sun Jan 5 17:25: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: 13926669 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 C3FA78F6C for ; Sun, 5 Jan 2025 17:26:38 +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=1736097998; cv=none; b=MXpQthPLwHdxUaz3jWwRlvGkYD+I2L3/HC+RTj5kq3za07AxpY6ncmbhXo3Fuxzt6sVk1KAwOyYQPr51V9gAE7k/CyRg242qypZqL1jqjUCy+Exgp1Nu4BTOzU5nUcKi+pkRjvKZ0zDvqvn1Pn+BiBtuxc/WhciusLvAercgeRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736097998; c=relaxed/simple; bh=LvzCMEjAWQibg2zyOeH1mejoQc6abULYuWOuDF4cXx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GQ+ArsXw2Kmw4XRzpSAQBTKnCogzmxNfP0J35gSlGfBGStA5erl+Wz09DxfsWJLaaEU7wE5FDVAKLK2jhtsW+7R/Ts05ph7EzqmylJmYDQJK7zMOpbbbFViIWtvlyMKgZW84w5kwD21lF5LDAYjCxT3cUGpTNQImYdOW9RnqO24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qituKUrM; 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="qituKUrM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 389E9C4CED0; Sun, 5 Jan 2025 17:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736097998; bh=LvzCMEjAWQibg2zyOeH1mejoQc6abULYuWOuDF4cXx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qituKUrM6EInLLd4pJVomSXawLyTIYUGji7xARuj7xRpT5whoTHeqKrQk9DG/W9B5 uVzvObc2aBFlNaak+BIlrXHguYz+bxtwPO1HLNaXu0eoFOt2SR0yCTrLf5HAhO3nXI 9LyCyLEa2AJVD0tdd6BSEOTtX6UioW/Cga5mCDwTrLyQ5lFMmJOdyr+myv+Mlovx2v oqHXso/vlmQYE/C7IJ8JT7sVbgqTfFibsX8y1rFMLJQsj6xRfZznLDTGUITV0KTo7S Uit1Y+Cr6LnYYUiRHMOUf2BxMBIUx0w+nAxuPFtOJt5F8GcsMNdRG9I/HuP4xf4bTd qY2ErySFmPzsQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 04/27] iio: imu: st_lsm6dsx: Switch to sparse friendly claim/release_direct() Date: Sun, 5 Jan 2025 17:25:49 +0000 Message-ID: <20250105172613.1204781-5-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 4fdcc2acc94e..cc7a62198982 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -1804,12 +1804,11 @@ static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(iio_dev); - if (ret) - break; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val); - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); break; case IIO_CHAN_INFO_SAMP_FREQ: *val = sensor->odr / 1000; @@ -1836,9 +1835,8 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); int err; - err = iio_device_claim_direct_mode(iio_dev); - if (err) - return err; + if (!iio_device_claim_direct(iio_dev)) + return -EBUSY; switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -1860,7 +1858,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, break; } - iio_device_release_direct_mode(iio_dev); + iio_device_release_direct(iio_dev); return err; } From patchwork Sun Jan 5 17:25:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926670 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 B13278F6C for ; Sun, 5 Jan 2025 17:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098000; cv=none; b=Q02tNxwCwsy3SeOQuCcIVFpFhRji7JDfvn+7p6xZ+fRjRC/8GMhl0WBpBmYrj3U2OeUrhpf94gFZg/+ZLH5B7F8Ta5enah4HC6ir/588JpRe5fusJ8GEmGWaBdRNr2GBa1OTkXV8eqITTiyIWmckOegp14jaAtbjIYtmWqaIGt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098000; c=relaxed/simple; bh=qW+WNsCk0k9TgZH5MNCkGmIc/dJmpaJSC3LUHheT+ug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSdT/rMqD9xnJ/bfIcp28A9AItW9DKjTYuY+PJfsNuWcwCVGA29s7mrJPRzB0amP2L5inma27eE3kk7eK1jzULW1IsxrxjS+lr4XmWUUtEOsqJq75wBZS5RqJurw5eaIJ3PCiPwT+SLxYEapBR+2BoHAOMoEdiix/J2iSl2V50I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pPa0+001; 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="pPa0+001" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 192EAC4CED0; Sun, 5 Jan 2025 17:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098000; bh=qW+WNsCk0k9TgZH5MNCkGmIc/dJmpaJSC3LUHheT+ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPa0+001B6vvuXa49Xwsaq4brW+IV8GTvWqFNsW68sbpQZGTbYbwxpmQECKXpFj3z F528FJ03TuHU4BdpRLFgdlWWtDkriYSf2BC34L7KC5qNJmpu6CTMi8+vc9jPh5/nWs s6GoNzbVzFU2Eiio4d4frHrg6weL1ZkXcB3VFxp/IdOae7sTJSaUwZE5HEc3wyLadn CsWz3kIEgvaBYvSUP+54chcERndr8GHDuAFHsuBVyNrq8OaxfFhnTXeplJbrmdu1Pf lzptEn4iEXe2vgo//FBCSDss1faWl7UzzOffCGn2Gv4DneenFUQf5fZOES6Ed7vEb3 W/fNzCdfKwMwQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 05/27] iio: proximity: sx9310: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:50 +0000 Message-ID: <20250105172613.1204781-6-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/proximity/sx9310.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 0d7f0518d4fb..b60707eba39d 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -337,19 +337,26 @@ static int sx9310_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; if (chan->type != IIO_PROXIMITY) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9310_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9310_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9310_read_samp_freq(data, val, val2); default: From patchwork Sun Jan 5 17:25:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926671 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 787EF8F6C for ; Sun, 5 Jan 2025 17:26: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=1736098002; cv=none; b=rk+HBkrGhkPDhSpPWLk5cH672+J1y5U6MPyyKp84OosNU18bdrCD/AUAUbAGIgEy+mwfyuH9LoelP+MBpEImIYEiJRAJ8nWf4bqcn/kjqCp5btOYJxcmPolGZVH44L4Af+YEp2ACb5SGy6oUMm0v+2DCnlyclOkWsjeAnawrF6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098002; c=relaxed/simple; bh=bMTpZJQO8uXn3yP0hbnGzyBggb+IDRFNYYEyj20fiZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fo6SLSIc2DFXQhip50KSfGcs8fL2cE1iF84MC0pLbRHatpAOMZqVmHwCDUYO/3JAgAmdSyj5YsmvjrDBYnnmuYhCpHQMAsmG9miKDJl3mbbd6zOH6OyTpww9ywRJuqNg4Hz/1JhEam3Yp+MYiuV4z81Q3n0oJvjzc/LbRMNrGDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qVmU+VGe; 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="qVmU+VGe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B850C4CEDD; Sun, 5 Jan 2025 17:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098002; bh=bMTpZJQO8uXn3yP0hbnGzyBggb+IDRFNYYEyj20fiZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVmU+VGeXzWqbfgDWO8Rhcj20x9hkCqKhxls/Fi304/FikbHBVTTNHV4Jb55uezpN eMbVVXVvdiQgR2ZqUqIBcqlb3ZKcVYX0Kk1o5bUDuDDgnb9FaLeMRFqDNlqydy1ZFY fNaq0wfy2oitpJ1IcfF5wy7CWqWxk+hwONCoU+2XZsC05o9oL6vHWrEEDw+copvSZR 9mN6oF7MiBi7s8XoE1MEbBT1w1iNPIzEPW4BKPfF8rKoRRwyvReEnk883RE2TJXYzt uCe4PIn8XFaw3Hws199A/rVGVSRkyxax2TzzHLtu9kxzTtEJCNydUGSNqELt5gNjhM WBD7or4kZROQA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 06/27] iio: proximity: sx9324: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:51 +0000 Message-ID: <20250105172613.1204781-7-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/proximity/sx9324.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c index f7819dd2775c..73d972416c01 100644 --- a/drivers/iio/proximity/sx9324.c +++ b/drivers/iio/proximity/sx9324.c @@ -429,16 +429,23 @@ static int sx9324_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9324_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9324_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9324_read_samp_freq(data, val, val2); default: From patchwork Sun Jan 5 17:25:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926672 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 7B1468F6C for ; Sun, 5 Jan 2025 17:26:43 +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=1736098003; cv=none; b=ANEpIHsb9Asx8/6SrWhmQ+S6opukGMe4ithsMtgcVbYdBotpLFtx49GC+WxBI1HHTj/P066QnrHgaooE3MzhMWfv+Z66RYTMNSJPnBsFcpr3697BXhDgW+Zx3sHV4akWfG1rD101GAkw2Y5tJBprpsvm7w0OV86vKC1bHHHw1tE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098003; c=relaxed/simple; bh=Q0/WJ946MqD0mFVd5xBXELbDxbs0v37GbJ8NV+S5cTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N0X9SAPxoQHaH3bmeZXW3JONX4YYC4mu4HDydOlD+a3q1pEcy/FjljlN7RgY1po6G5/zYAeiW/s12JCUEHuktHpvo1iDQ9DzOUsOpbaYbRHZepxd2qmY8R/DHYneY6Ildy9OW8jCSl1Cl1lrjidGqvElsc+pnTY7U5YLkqj7Z6Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ECZ6Xkch; 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="ECZ6Xkch" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E89AC4CEE0; Sun, 5 Jan 2025 17:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098003; bh=Q0/WJ946MqD0mFVd5xBXELbDxbs0v37GbJ8NV+S5cTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ECZ6Xkchpnix96fTiA2ym7lFIivmDcariEYLiO2FX/3lOsvNDcPiy78QAOzZRr2X7 6xTHHPo7QD9JccAgs73Bb7rihiVWvHNTSIj3GGl306BiG4NiSyJTgzCJ2TdIhhGpMe jYIdnDVO5wVFTvpLnZuLry1n62+MmsECeBzxXGXlYgqngnTDNL+cbMmsmEHK//bGD7 plvCEUUfFdBArLANYokz1PCzAVX50YJJtHHUDMIWJhGVL4gZkFv5xS+s3eyz6S0EHv mAwSPkeFhDqaA6KGQQPljV+Aq03MjEwCCEowF+y7cLsHDTxJv/z1mOyDdWv6WJcFfY v3SAvN0Zovv5A== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 07/27] iio: proximity: sx9360: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:52 +0000 Message-ID: <20250105172613.1204781-8-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/proximity/sx9360.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c index a6ff16e33c1e..4448988d4e7e 100644 --- a/drivers/iio/proximity/sx9360.c +++ b/drivers/iio/proximity/sx9360.c @@ -321,16 +321,23 @@ static int sx9360_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct sx_common_data *data = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx_common_read_proximity(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx_common_read_proximity(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_HARDWAREGAIN: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return sx9360_read_gain(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = sx9360_read_gain(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SAMP_FREQ: return sx9360_read_samp_freq(data, val, val2); default: From patchwork Sun Jan 5 17:25:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926673 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 D21B18F6C for ; Sun, 5 Jan 2025 17:26:44 +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=1736098004; cv=none; b=U7o3eq9hIH7GbP3HPezu9rO4PBD/JBNqvTG95WUG2kNW4uUkm5x9NiFB9kUIQRkNGP9Abo7wLH6D7Vham2El+5ejD4kcEOjmLmEypxJNvqc20v2jXQVSf/kzhBWlEsVaijB0unrRNwJEpU+C/jB/XXYyL/i/TZzGrL9xYllJ1tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098004; c=relaxed/simple; bh=iG6L6cXGESzrWrgcvBGtR9H+em9f1BXhQCTTSs4lXy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UqzWCJKX7nTHCv78FAeFrCts25JoDmmGoCKrpLr/nKQ3xUPXxxrRc6ye06lt21xNeHaGU0EkZfM89bSMkLkCxqLwn8o0u97X3qREPL0iWZcS2w8BNvgubIPLf68VW1DXoieXm361aci/iWg4A4kJ6I5Ev48H/sof7hxrauMVG9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TNuCNkEj; 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="TNuCNkEj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3DA7C4CEDD; Sun, 5 Jan 2025 17:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098004; bh=iG6L6cXGESzrWrgcvBGtR9H+em9f1BXhQCTTSs4lXy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TNuCNkEj+ehcOHSN0/OJnR8brQ399FmZkkcA3xcy96qd55Fw+97BYs0taDEMVd14y iUk56ltJzC99CLqABFmzE0TRZpS1yDTU24YxFvkrg8ledvXHT1+6XZkSIUPX+kwwu8 9ToYAJ1HB4IHHHRxnMXU2nsnla4loeW6R/0sBgbpWtHbOuV+tc9Bde95Z7xF3R80Sj B5B1buKjVj2JalFqjcPXhQV5QsGRkatqPIiwQMAMIjFNg2z1PhXwjiUHBupNHIBdb2 jTtMaz0hVOXQ6u2yVO74jx8HMXiQ8tNakdZo2Enduoo/VvBtuDWS1VpgET++RvZEcH KVih85t9rIFTA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 08/27] iio: accel: adxl367: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:53 +0000 Message-ID: <20250105172613.1204781-9-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 --- drivers/iio/accel/adxl367.c | 194 ++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 88 deletions(-) diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c index a48ac0d7bd96..add4053e7a02 100644 --- a/drivers/iio/accel/adxl367.c +++ b/drivers/iio/accel/adxl367.c @@ -477,45 +477,42 @@ static int adxl367_set_fifo_watermark(struct adxl367_state *st, static int adxl367_set_range(struct iio_dev *indio_dev, enum adxl367_range range) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - ret = regmap_update_bits(st->regmap, ADXL367_REG_FILTER_CTL, - ADXL367_FILTER_CTL_RANGE_MASK, - FIELD_PREP(ADXL367_FILTER_CTL_RANGE_MASK, - range)); - if (ret) - return ret; + ret = regmap_update_bits(st->regmap, ADXL367_REG_FILTER_CTL, + ADXL367_FILTER_CTL_RANGE_MASK, + FIELD_PREP(ADXL367_FILTER_CTL_RANGE_MASK, + range)); + if (ret) + return ret; - adxl367_scale_act_thresholds(st, st->range, range); + adxl367_scale_act_thresholds(st, st->range, range); - /* Activity thresholds depend on range */ - ret = _adxl367_set_act_threshold(st, ADXL367_ACTIVITY, - st->act_threshold); - if (ret) - return ret; + /* Activity thresholds depend on range */ + ret = _adxl367_set_act_threshold(st, ADXL367_ACTIVITY, + st->act_threshold); + if (ret) + return ret; - ret = _adxl367_set_act_threshold(st, ADXL367_INACTIVITY, - st->inact_threshold); - if (ret) - return ret; + ret = _adxl367_set_act_threshold(st, ADXL367_INACTIVITY, + st->inact_threshold); + if (ret) + return ret; - ret = adxl367_set_measure_en(st, true); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, true); + if (ret) + return ret; - st->range = range; + st->range = range; - return 0; - } - unreachable(); + return 0; } static int adxl367_time_ms_to_samples(struct adxl367_state *st, unsigned int ms) @@ -620,23 +617,20 @@ static int _adxl367_set_odr(struct adxl367_state *st, enum adxl367_odr odr) static int adxl367_set_odr(struct iio_dev *indio_dev, enum adxl367_odr odr) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - ret = _adxl367_set_odr(st, odr); - if (ret) - return ret; + ret = _adxl367_set_odr(st, odr); + if (ret) + return ret; - return adxl367_set_measure_en(st, true); - } - unreachable(); + return adxl367_set_measure_en(st, true); } static int adxl367_set_temp_adc_en(struct adxl367_state *st, unsigned int reg, @@ -725,32 +719,29 @@ static int adxl367_read_sample(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - u16 sample; - int ret; + struct adxl367_state *st = iio_priv(indio_dev); + u16 sample; + int ret; - guard(mutex)(&st->lock); + guard(mutex)(&st->lock); - ret = adxl367_set_temp_adc_reg_en(st, chan->address, true); - if (ret) - return ret; + ret = adxl367_set_temp_adc_reg_en(st, chan->address, true); + if (ret) + return ret; - ret = regmap_bulk_read(st->regmap, chan->address, &st->sample_buf, - sizeof(st->sample_buf)); - if (ret) - return ret; + ret = regmap_bulk_read(st->regmap, chan->address, &st->sample_buf, + sizeof(st->sample_buf)); + if (ret) + return ret; - sample = FIELD_GET(ADXL367_DATA_MASK, be16_to_cpu(st->sample_buf)); - *val = sign_extend32(sample, chan->scan_type.realbits - 1); + sample = FIELD_GET(ADXL367_DATA_MASK, be16_to_cpu(st->sample_buf)); + *val = sign_extend32(sample, chan->scan_type.realbits - 1); - ret = adxl367_set_temp_adc_reg_en(st, chan->address, false); - if (ret) - return ret; + ret = adxl367_set_temp_adc_reg_en(st, chan->address, false); + if (ret) + return ret; - return IIO_VAL_INT; - } - unreachable(); + return IIO_VAL_INT; } static int adxl367_get_status(struct adxl367_state *st, u8 *status, @@ -852,10 +843,15 @@ static int adxl367_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long info) { struct adxl367_state *st = iio_priv(indio_dev); + int ret; switch (info) { case IIO_CHAN_INFO_RAW: - return adxl367_read_sample(indio_dev, chan, val); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = adxl367_read_sample(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ACCEL: { @@ -912,7 +908,12 @@ static int adxl367_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - return adxl367_set_odr(indio_dev, odr); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = adxl367_set_odr(indio_dev, odr); + iio_device_release_direct(indio_dev); + return ret; } case IIO_CHAN_INFO_SCALE: { enum adxl367_range range; @@ -921,7 +922,12 @@ static int adxl367_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - return adxl367_set_range(indio_dev, range); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = adxl367_set_range(indio_dev, range); + iio_device_release_direct(indio_dev); + return ret; } default: return -EINVAL; @@ -1069,13 +1075,15 @@ static int adxl367_read_event_config(struct iio_dev *indio_dev, } } -static int adxl367_write_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - bool state) +static int __adxl367_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + bool state) { + struct adxl367_state *st = iio_priv(indio_dev); enum adxl367_activity_type act; + int ret; switch (dir) { case IIO_EV_DIR_RISING: @@ -1088,28 +1096,38 @@ static int adxl367_write_event_config(struct iio_dev *indio_dev, return -EINVAL; } - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - struct adxl367_state *st = iio_priv(indio_dev); - int ret; + guard(mutex)(&st->lock); + + ret = adxl367_set_measure_en(st, false); + if (ret) + return ret; - guard(mutex)(&st->lock); + ret = adxl367_set_act_interrupt_en(st, act, state); + if (ret) + return ret; - ret = adxl367_set_measure_en(st, false); - if (ret) - return ret; + ret = adxl367_set_act_en(st, act, state ? ADCL367_ACT_REF_ENABLED + : ADXL367_ACT_DISABLED); + if (ret) + return ret; - ret = adxl367_set_act_interrupt_en(st, act, state); - if (ret) - return ret; + return adxl367_set_measure_en(st, true); +} - ret = adxl367_set_act_en(st, act, state ? ADCL367_ACT_REF_ENABLED - : ADXL367_ACT_DISABLED); - if (ret) - return ret; +static int adxl367_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + bool state) +{ + int ret; - return adxl367_set_measure_en(st, true); - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = __adxl367_write_event_config(indio_dev, chan, type, dir, state); + iio_device_release_direct(indio_dev); + return ret; } static ssize_t adxl367_get_fifo_enabled(struct device *dev, From patchwork Sun Jan 5 17:25:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926674 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 560358F6C for ; Sun, 5 Jan 2025 17:26:47 +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=1736098007; cv=none; b=SCM5YxEhlHSyxXK93SLG6wWgp0eKoV1la+Or6bCJWSBGc071ZXKDAI9v3YH9Nf3ip6H4nBGtX/+UjqOLo9rOXP2XHFl2YeFTNNNgpnLmeIVtF9X3f0f+WsTIrqNlAKlQlpeavZROLOwE1kqvLDIWrZmxoIZGYAp8XzHzXEbdUvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098007; c=relaxed/simple; bh=v6Q1erGVN5BFergJayj06fy9eiHQobsivWzLHugz1Sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J85QtZatxEPtc+v5kWB2bWAIikMmlg1EnlYkjx7gTbtTJPSvDgHRYlcASwrbnw1mvXxPjbhV6c/DCT2xyyWbl9CiLRVPV1+jDWKiHMSfjY+q03LVeQ4K6aRYhAWCqC/vPReXSsxLs5GMvyYT2QjH7LZklX7hOzTzXekI0JDel08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SNw8iDae; 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="SNw8iDae" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23FD3C4CEDD; Sun, 5 Jan 2025 17:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098006; bh=v6Q1erGVN5BFergJayj06fy9eiHQobsivWzLHugz1Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNw8iDaeCXS1+s61asbJqMejS+kLlqNRuAtkH0CCV8VdzVSJ8CKD0B5mKMHgCjK1Z 0MtWGAYX77/PFbPyWfDTm3XUcRe+j1dRxc8s3h4++5TSgdzCU6tmQb0gUiftsk76EZ RQTyxjBl4a9KQxXDPtr0iqEI4MyDDMCdmt8mdmIgSQwivKBpE7X6mLwWgSujfrQGKd E0OFq2ZMbZrsd5K6l7i+ItbeKh1Yuoodp7pYaCN5SJW13eGvgwiuWO7rhWbq3l6eyE BIuN11h/di7AYvwNzI8KbOwL160Y33QWQxB1zk+vHvQeWjUHFjwCwBaiY/08fG+uoF nBWhXVyCLrENg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 09/27] iio: adc: ad4000: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:54 +0000 Message-ID: <20250105172613.1204781-10-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 Acked-by: --- drivers/iio/adc/ad4000.c | 61 +++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c index 1d556a842a68..ef0acaafbcdb 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,47 @@ 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; + 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); + 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_write_reg(st, reg_val); - if (ret < 0) - return ret; + ret = ad4000_write_reg(st, reg_val); + if (ret < 0) + return ret; - st->span_comp = span_comp_en; - return 0; - } - unreachable(); + st->span_comp = span_comp_en; + return 0; +} + +static int ad4000_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + int ret; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ad4000_write_raw(indio_dev, chan, val2); + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Jan 5 17:25:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926675 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 99EF28F6C for ; Sun, 5 Jan 2025 17:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098009; cv=none; b=fexpU+RNEEDhlDTe9dWLGGTy3EBALNfMoOuPWDLYjC/pUVd5FpUQ/5qxOCIbOOzPBHNgoWX2fNEwQ3wu2mNzn6TYMsWZT4S1prtPkGmqbhERcqJO3dZljfV6u1eLxblS1HfKUxvR+ohGgHjRkl6yNaTckF/zxMvq1lgNQKo/7ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098009; c=relaxed/simple; bh=ER0444V4E6vvf0TtAZZfsCZ1xjti7ybmWbsZjwHyWYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YiBGyWFGc3oap9k/8B5mniBFco24zJoFS6oTHcU9Wnw8I5EneHTC6IYFiMJrkLtuBg2381vaMPmlTC3qOl3BeSdkNW0hw4Lw+ku8mCCGOdpIAV3WVrEf7ZWiwJ9NJb4dz2BWJ4ZigdVbgx8e3glVb+FS2wJ1A7BduNIYFQjIGyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tPmOixk6; 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="tPmOixk6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76ECFC4CED0; Sun, 5 Jan 2025 17:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098009; bh=ER0444V4E6vvf0TtAZZfsCZ1xjti7ybmWbsZjwHyWYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tPmOixk6pIcvEyBdDCqteoOLwP6SZhjwUHzXccK6qSAxZiMDuvFVyp8Hc260E5Wyj 4tkJxZRTIDG9BIq2PvQqokxs+JsMfRgkJhutP+b8fcLf/hnwHiZzpa/wKoEVl8goy8 0fZiAU75hLPG4jnFcpiRAk0ZIPUp0pSb0STIlIEAi0bemR8nRtNhUDtR9QDPClbbDQ bS/rgg7udvAlIGqDAQ8utmFBcD9VFfAhExfOVi29e5TB8hC896evfYlJu0n81WfwPw whxvflKt342d2FxBMdWifAK1H4PFJAP/ttl95p++ZXt4DXlOA/4jDAP55X3vtLeRUl SY0AgwCfGldbA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 10/27] iio: adc: ad4130: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:55 +0000 Message-ID: <20250105172613.1204781-11-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/ad4130.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c index de32cc9d18c5..09012f33ff16 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, From patchwork Sun Jan 5 17:25:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926676 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 144BF8F6C for ; Sun, 5 Jan 2025 17:26:52 +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=1736098012; cv=none; b=dtuF1mdrnGk8l7GNpcJ7M9yueF1tbzo0180BZ+fl8i36kZ1AI9VG7SxDurpjcLbC4NjCnSFKXoTaqeswSBqkPtNg/3uCtei+/U6hp5j0bULj8b6PxD9RIqzLsPwpS+SJ8zqY3eauIMBO7zutsaj/XKfIFxfbOO08PxVmfjiGMO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098012; c=relaxed/simple; bh=LWqHOjlFuf3//TsXJwahIXPO8AJTEI6GqRf9NpFvPU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GPUCS3PQ6sOWiHiQRTH/d3IHha6oA21MlTJ1xLuGN+him24F9vjthmbaRqIEaD7KMXzikmmLwE2VDEuclWUp3Aeql/LcurXscww+TNUm/kxOBwmtOuTUylPnooCTnCqV2JsIs3FLkLn1QhsZVkEMivNiyGYs0iVnMFVsL9gtgrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J5V3HtMw; 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="J5V3HtMw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E8D3C4CED0; Sun, 5 Jan 2025 17:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098012; bh=LWqHOjlFuf3//TsXJwahIXPO8AJTEI6GqRf9NpFvPU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J5V3HtMwHlH8OCJfIWG9wQcCJjODBo3odTpX58eP5MPIyMvO+l78C5Zeqcpgmsc5j TbceEU6QqQacvnkq79P/LSH+aeayk73c/pcndBVrlk0HJachd1us7R59SjB9hJbYgG 1s030uwZ/8wauDH8+xv/j3560SOurtFkK18LiMNPQiAeEcUd/iEyHZjAwj5tFgQQ5/ /7sUX96q+3IeEwCPgkl73VTZv27SYZz3cUHkeSIzpV3duoT0ZdNkaqeqHxt4gZ1ccW qTCRlSOud6DrWw/Vtbv0qsNe8/DVhrlJPju1XwCYwI5ntNvdxfLZocJAvYZy/g4khP KDkLaxlSsOpLQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 11/27] iio: adc: ad4130: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:56 +0000 Message-ID: <20250105172613.1204781-12-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/ad4130.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c index 09012f33ff16..1a38b52abbe4 100644 --- a/drivers/iio/adc/ad4130.c +++ b/drivers/iio/adc/ad4130.c @@ -1074,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 Sun Jan 5 17:25:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926677 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 6AE5D8F6C for ; Sun, 5 Jan 2025 17:26:54 +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=1736098014; cv=none; b=qkWBw/kbNHe3AsgO4fJY32kbE+LAL757mMQk6JGmKiIkMs2q2LkYZfvmTwQu5bE4rYfu57oYULwdI7yGekcGEk07VSt842GsXDFRXAu5cQ5r96x/UY0sIzSi9OU+H38wkB6JkAtOK1tbXjULMBXiQ8a5Se4ieJ6KSO+QFrQrcsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098014; c=relaxed/simple; bh=ffVqcrp7WSVymc9RZ8iLqJXWAA/B3Rk4otNv7EmrnCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TRa2DcYuyTIbjfusXgYCZqC3qXsGH5fle2ftRjL1J7ZyYCOKXHY2reSHNvZ2FO2jf9W9d0972+E81gbL6tYw0Elqp5qN+wzVDg0GEd7NbynWA2NIwR4fQyA+5bN2Sc/qp2o19ORqXFAR9sszVSJI1tLq93+2uWdJN9TGA+J05u4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NPW/6rD+; 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="NPW/6rD+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADA26C4CED0; Sun, 5 Jan 2025 17:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098014; bh=ffVqcrp7WSVymc9RZ8iLqJXWAA/B3Rk4otNv7EmrnCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NPW/6rD+ouE6aOLbYsYNe3+a3adQ/kHZyjBsQBDsbSyagAU0rnVhyqrOENc8G+lfQ 7SWAXNbmnyeeC/cqLQyEBbtclVEzh5j0PxwaBiY2HaEkZvBLTihQbjbQ7rHgXNB26X 86MMnxIWqm/si+rDVu2Ke+hMV5chZijS2KoOYjqTIPnOakaY9EX24D9v0xDGCQoqoi b9oi3aDw6BuFDDHUjF9XeysmCuTLOA/iDdPFvLng/Q4Rgqvzg1ddBcDShJ4YxFf8gK CJ/KWBm6Pm7ulFW2pUVq3dFmFgdxnGxRjx4Iy7/97egFLo1tP1ocGlu13IYZxJKu/A KqWm/C65UoYLA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 12/27] iio: adc: ad4695: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:57 +0000 Message-ID: <20250105172613.1204781-13-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 --- 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 3c2c01289fda..e7bf4870099c 100644 --- a/drivers/iio/adc/ad4695.c +++ b/drivers/iio/adc/ad4695.c @@ -617,6 +617,25 @@ static int ad4695_read_one_sample(struct ad4695_state *st, unsigned int address) return spi_sync_transfer(st->spi, xfer, i + 1); } +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) @@ -629,19 +648,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: @@ -679,45 +691,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; } @@ -726,64 +738,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, @@ -833,26 +856,29 @@ static int ad4695_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int *readval) { struct ad4695_state *st = iio_priv(indio_dev); - - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - if (readval) { - if (regmap_check_range_table(st->regmap, reg, - &ad4695_regmap_rd_table)) - return regmap_read(st->regmap, reg, readval); - if (regmap_check_range_table(st->regmap16, reg, - &ad4695_regmap16_rd_table)) - return regmap_read(st->regmap16, reg, readval); - } else { - if (regmap_check_range_table(st->regmap, reg, - &ad4695_regmap_wr_table)) - return regmap_write(st->regmap, reg, writeval); - if (regmap_check_range_table(st->regmap16, reg, - &ad4695_regmap16_wr_table)) - return regmap_write(st->regmap16, reg, writeval); - } + int ret = -EINVAL; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + if (readval) { + if (regmap_check_range_table(st->regmap, reg, + &ad4695_regmap_rd_table)) + ret = regmap_read(st->regmap, reg, readval); + if (regmap_check_range_table(st->regmap16, reg, + &ad4695_regmap16_rd_table)) + ret = regmap_read(st->regmap16, reg, readval); + } else { + if (regmap_check_range_table(st->regmap, reg, + &ad4695_regmap_wr_table)) + ret = regmap_write(st->regmap, reg, writeval); + if (regmap_check_range_table(st->regmap16, reg, + &ad4695_regmap16_wr_table)) + ret = regmap_write(st->regmap16, reg, writeval); } + iio_device_release_direct(indio_dev); - return -EINVAL; + return ret; } static const struct iio_info ad4695_info = { From patchwork Sun Jan 5 17:25:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926678 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 1A5CA8F6C for ; Sun, 5 Jan 2025 17:26: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=1736098017; cv=none; b=LsdY2aN9SGnwUvbdxwHpE3cU6ixKKNI35YORB5pe7vQuZiNtvtBRhhgVwNE7Mij3fBxXlxZoMUyRKR+7iv5BbkT+8zO6Aw7i8bgctaUH02EFngbiDWWQStE8ZLl3saMcIng9pjOHdZgTUStbaqMm6E1Hvn/DyLxta5Up8r4nTCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098017; c=relaxed/simple; bh=QDdQBDoAOKy5DBNK9gUZzN0KcyKnxKQPse/9J8M5+xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SyTtyS1f+dik1oLxQtudmwEBnhcsJa+nW5UDYD+YwGMfjZ/BDwr9hG9C5Z16tFCrbOEpoFLQ6+iDsNaDCepQZzrV0ee49p4Hp1QxXSIahVLqRXkjv2fbQ8XETyzWmfOaRAa277XyzLh6F3sUJddqVwGpxxxS5wFtKomQt4LHZyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GiIQGgUl; 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="GiIQGgUl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC60EC4CED0; Sun, 5 Jan 2025 17:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098017; bh=QDdQBDoAOKy5DBNK9gUZzN0KcyKnxKQPse/9J8M5+xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GiIQGgUl/RUnS4LpNKu4wUgGYWslCFk9uuwVWbHbSYzmc3usEBQ8gXJ5+rLih6qiu s/EjWdYZUi44BoMSN+TkymKt3E5JNJYZWG5WiDC0905/2GI5Q8NTQQZoGFq5df756D 0zis6jb7frVrJLTOh5Hs4YhjLc73C5HjLFU0tTHwdDbSQkXpldyUAe4meIF6l0SHCf o8FGI6tcaAejlTzQamqep0kHRW+ID5W1OSZRnQQ+Fkpc1V0Y21w0xjG4xptT1nFti7 GKcfpOgQQO7N4S9v+rgK9Lq47mZaaRt2NqgeuTvF+XRHJjju0JwlWHQ8iw70dtnyoh Xr4STWpbyKwCA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 13/27] iio: adc: ad7606: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:58 +0000 Message-ID: <20250105172613.1204781-14-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 e35d55d03d86..1579cf100569 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -744,13 +744,13 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = ad7606_scan_direct(indio_dev, chan->address, val); - if (ret < 0) - return ret; - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad7606_scan_direct(indio_dev, chan->address, val); + iio_device_release_direct(indio_dev); + if (ret < 0) + return ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: if (st->sw_mode_en) ch = chan->address; From patchwork Sun Jan 5 17:25:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926679 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 A2A388F6C for ; Sun, 5 Jan 2025 17:26:59 +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=1736098019; cv=none; b=HU83grc/Y2AkRZjvIxcruwvuskFXjeEFVby6av81Pn84syCP/dMlzM1T9r0glEw2O/5svkNPSbi+RPyLMCGJaXwxgZj9q1hnlLzpLoTzMHM573kxIBc9qbM9f+MP/nbPsNJI/HjVtTS/Xkxafhhnbd5Nk/bi3e6H8Fm317kcLlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098019; c=relaxed/simple; bh=KU6HxxU/RSeeEVD61ryK+g3swM1J7O+RmQKPu0C5KYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aVJm5X6T8+YleWIrUFutEOMEcyvqELZketcY3muk45cmzjSnXXh+J6DI8a97htCQDcoF7trWvWdT8CbvQyEh2cr4ockVIFA7R+yTJ/H3IZiW2Leux9JZtVTgHWMwq7jxOyp0eDkcrFgCkSODoY6EKvXIKEzd+sEqSgah7PJ2rZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HF8EuydL; 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="HF8EuydL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A8DAC4CED0; Sun, 5 Jan 2025 17:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098019; bh=KU6HxxU/RSeeEVD61ryK+g3swM1J7O+RmQKPu0C5KYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HF8EuydLGUw4pbzZkSNraFKQsxhgmX0t/dyEePWXWnp09rdM20GyNZ7XYo3c1AzUn fxhomcbkiKPkur/JCEehNRZgPXX6Zsts8XtxQwekpda8PQzR2p8FxOVIduPmMkOnLk i+JmINzr7DUt9YPIZR5b3VRKBfmXqxuqkAtfOy3njzU4yhOt2lUFpElVouCyI9+sr0 Hf/O4SbQBEhrXlGDm3Wo0PyyGzxTYwMMD6OZtyX9+AhPWyJV5iXVeNySbawSktUXnV OJ8kgzb0qR/zQp02/r8X3OUd+m4UIcf8rXM7PfiT/gxbYVnxvVQDX5vKF9zz42vvoE I17VHXdVI1Z9w== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 14/27] iio: adc: ad7625: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:25:59 +0000 Message-ID: <20250105172613.1204781-15-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 afa9bf4ddf3c..a39c970450a2 100644 --- a/drivers/iio/adc/ad7625.c +++ b/drivers/iio/adc/ad7625.c @@ -248,12 +248,15 @@ static int ad7625_write_raw(struct iio_dev *indio_dev, int val, int val2, long info) { struct ad7625_state *st = iio_priv(indio_dev); + int ret; switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad7625_set_sampling_freq(st, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad7625_set_sampling_freq(st, val); + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Jan 5 17:26:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926680 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 B43048F6C for ; Sun, 5 Jan 2025 17:27:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098022; cv=none; b=TZgPbpfBANbpVP0yQb/mlvPGyHHAFX+/8w4XyRJTjShjhOuHsYHn0lZ/WY2XUT25VjoxHFdyLM7F8f82Fqt8/6GnEQeiaq2U2egDkNX11y8pknFlDByPVm/mDkXQCFyAEMK8j221bjCnE1VDsygndHlcN9vcKk6YabnBMzqn8Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098022; c=relaxed/simple; bh=EzvbwWTBiplbRViuWSzRqII72rV3fPlPSqb2nFGlufQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PbXOja5GgUyLleOr3anU30j+nQwEWvQvLTuu6WM41cAg0qIUj3XN6lF+kmVA286H2sqgNg8kha97tdNyob+NbKT2AUQ/RkXoXz5A3RFcX1yUZHqEYrU/s31N8FtPS/izeIaAeH74qLBkZL1SU5l3W/6mOsRm+5np+XICgA90HN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QdU+i5RP; 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="QdU+i5RP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48182C4CED0; Sun, 5 Jan 2025 17:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098022; bh=EzvbwWTBiplbRViuWSzRqII72rV3fPlPSqb2nFGlufQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QdU+i5RPI5fDh034h22OnMiUld1SeQYvO07H10I9DBg8cFiqzRQxeEN72+NMW9uj1 thZMnmvqsREYpH8fKv2em+UFQsAZo+YdScWGo82HE/g9i8T946i/YBg5j0aATzRtf/ vwNOhsWL+gBQHt+herRJriKdqMb9r41XP1d0NWcx9mJfVFu0WA/vgk0CZ2NhLaFdaK wi4w2jSeVMJHFg/SXvE9KdZt/JSckV36Wx/2dRf+v/fNlZ7oQfxQvF+xnYSG+0PGxu tHlc5f9Aix378LboZnKI5M6za66ygo9dz4rR/C6p28Yut7FrRVhDojyUlQRjx5+TC/ 4Ghue2mqa/+YQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 15/27] iio: adc: ad7779: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:00 +0000 Message-ID: <20250105172613.1204781-16-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/ad7779.c | 103 ++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c index 2537dab69a35..3b132665d24c 100644 --- a/drivers/iio/adc/ad7779.c +++ b/drivers/iio/adc/ad7779.c @@ -467,65 +467,88 @@ 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) { - int ret; struct ad7779_state *st = iio_priv(indio_dev); + int ret; ret = ad7779_spi_write_mask(st, AD7779_REG_GENERAL_USER_CONFIG_3, From patchwork Sun Jan 5 17:26:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926681 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 7EE338F6C for ; Sun, 5 Jan 2025 17:27:05 +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=1736098025; cv=none; b=DeBFELszo7uqQEQ60vTSg0Qlu7153sY/MEp1/BOrnmgwakrDkgTQheOl8xcXaE+j1yRPWwx+RH8pzO27pnNS8//eSdcDh5D+iNQcQbzmqmEHdgPpMS2rhrWtRppi7umzQzSG29kbfPAGOGGaCtjiEe/9wv+b2EQsdPRp5I/hM9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098025; c=relaxed/simple; bh=WNYIJEHgCJHVWy/TBjRkd/pVhx++SSb4QBgaXiMc9gU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TGO/lz58n0V5ZpvrHqxEc68r1uS/XvKB/CngJbhr/sPEVugz70V/FSNH9auvMew/q8eJELN00/6OU0tmj/MZr6XoB4lnXyRL7mIv4LKtEey97x1G/sY7BL0Tl8McGe5xGazBqOqi7TU+Q5FD+e193qaDcNqNyhaiq8ru3Uol8Hw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ox6bCrvo; 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="Ox6bCrvo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E538C4CED0; Sun, 5 Jan 2025 17:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098025; bh=WNYIJEHgCJHVWy/TBjRkd/pVhx++SSb4QBgaXiMc9gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ox6bCrvo0ul7VFekDQE01ydlrb3265v/V7WJJTzJ/d1rOVX5JMSyesIO7jAxV7bCd 3PG7/MZflNx2cHJLVVV2NqTT7eGPshnwvWAS6BCFjnmiZFs+BHuhL9lKKgjZcuxlIE lDOZxQfBQL+ZmivWQpRK+dRLPTltbQvtRjJ05R6IN3umvLPZOa1DXPqY/QWFdz55AC sD9HcrbAH237i1R7PbKZcPfFIgQmzhdaBl1hj89CDHycLhmV16nMDGIs+ddwpoZUWR ar54X6Pq6OElTlQ2UV0LifPqkF/NnPUnZwe6V2KYfmb5HeyLxwy7qLEKNDlsBsLYq6 3dcMrZg5/1fGw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 16/27] iio: adc: ad9467: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:01 +0000 Message-ID: <20250105172613.1204781-17-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 d358958ab310..635c0d10c7bc 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -813,6 +813,18 @@ static int ad9467_read_raw(struct iio_dev *indio_dev, } } +static int __ad9467_update_clock(struct ad9467_state *st, long r_clk) +{ + int ret; + + ret = clk_set_rate(st->clk, r_clk); + if (ret) + return ret; + + guard(mutex)(&st->lock); + return ad9467_calibrate(st); +} + static int ad9467_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -842,14 +854,11 @@ static int ad9467_write_raw(struct iio_dev *indio_dev, if (sample_rate == r_clk) return 0; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret = clk_set_rate(st->clk, r_clk); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; - guard(mutex)(&st->lock); - ret = ad9467_calibrate(st); - } + ret = __ad9467_update_clock(st, r_clk); + iio_device_release_direct(indio_dev); return ret; default: return -EINVAL; From patchwork Sun Jan 5 17:26:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926682 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 9F4F08F6C for ; Sun, 5 Jan 2025 17:27:07 +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=1736098027; cv=none; b=ozTim1KsY+edcOrg8/4fM5L1GC4MiSYvOJiGcRSKzdAONdRdXm3O7uEGBcQL+vxy6yxm2EXxLgZV+bikhinbWBZ440WQB7wPfVtLUrUKJLX6rAreVa4qYAUrhnMq5tJAWnBqqvd7N1BDvU0rFTfLlN/kG78MibLGLNgdqE5MoCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098027; c=relaxed/simple; bh=cxUiR/damgtGhKiOE1aiR2GfIhrYU81eWmM7M1LKBaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fXqoHbmCuriSGnKUoZIFMPX6Xs6mf3mcheU8D70nVDUYifmW8Ye1RbbL3re2yhESBYp4CyAC98hE7MZBG31UXAHwBL4NTX6pyfO+AhgArK3YLUKC+OUNWm8Nk4ruWLoJjR8wM8/McwAot+3c9seOMxksDCwaaA46A8uhgf3l8Dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E8BbHN4U; 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="E8BbHN4U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96ED9C4CEDD; Sun, 5 Jan 2025 17:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098027; bh=cxUiR/damgtGhKiOE1aiR2GfIhrYU81eWmM7M1LKBaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8BbHN4UaM6wHtmHFHeAvTvq5Q/envuVdKkiRiDmD8etho949YpKAQzLwqCFGm/PU CBLJoM3oj4OURtDRGqzlH4GFlQ6vJKHU4JP0fDNLmf9AM2hml7zWrJ6qtQ86ZT+3O7 XEdmTPeZ2i8lXwyU7uQlKXXGq9SogH5ML+cDoAD/LUKeO8EFmCK8F21nJQ5GMvXnmr NyzD+EIUpgHzsddX4H54ckm9SBJGOsIjHAAKAWXcpkoYkOlgKElZFmlNo6JxHGFWza oX4EWwBJWBNlYo5ikbFlhuQlIqDWz4f0d2s2fwSiTZ8V32Y+gnM2NMa7BA7S2oYmql EOE3J07cUyVLw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 17/27] iio: adc: max1363: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:02 +0000 Message-ID: <20250105172613.1204781-18-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 Sun Jan 5 17:26:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926683 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 7AE638F6C for ; Sun, 5 Jan 2025 17:27: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=1736098030; cv=none; b=saY54+1X9yQuATYS8FEep6dwl0N326BLOuMCwHiVSObi2OaB3H0k0070dRqfbA3kOAaScFpvacLo1KQ7wMESiOFN8wJ/wnukyKD+Bk9gmX8jQc5kHSJHBx/i6wFaiUK0ILGYjZMmrkzADyloDYH2Y9hkCn+ZQdXq+kDmuMxlZv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098030; c=relaxed/simple; bh=imrV38BBD1D7gAE5+2EjqleqAlmXUiTC1u+Xo3E+w3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uE/7e87mGc896cYYXc/PIK8ww/bVAdEZjSKGMEqXeRG/VSCPw87Cz6thiIpQYWIrc3k1oQ0zAfTSXDdVfEGLbTMBEztVGOQMKGSFSBA+t54twYIABQ+ajkDGWWPMpWO1t4EwMQXSgawuIcLCbzMhDvqXQY3H30CBChmliGwjg0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=onaDFXqS; 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="onaDFXqS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44A6DC4CED0; Sun, 5 Jan 2025 17:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098030; bh=imrV38BBD1D7gAE5+2EjqleqAlmXUiTC1u+Xo3E+w3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=onaDFXqSjvjCYqoXLZJoFMW/fz7ICFQNfNBWOMLYGXdOZl/WDgBdGPdUM5BfQ+6ZQ /Aeeowm1bLdEz85DA2gdpiCeMd4mxvE+qXJY7+Adm4px/F4DqzOzU6I5yCiw7lrdBB smtcizP2jgrtOzdr41n2QQ1RWcsJJYgXeRt+CwH4cW8FfwEjsFI+1nZo59PduDihoB 45xdz+yJsQgD3Ix7M8F9BzpdfMrMYJhnZEgbP3s7R3gEKwApTajpkh0XZj7l5LXTHG 903/D8UjROCuFCFirK32c6w3fR2hBJuU5u6MDrS0HiGPw9DJIOXZHZEg60jnn3OUo6 s1h2lrGmTv71w== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 18/27] iio: adc: rtq6056: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:03 +0000 Message-ID: <20250105172613.1204781-19-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/rtq6056.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/rtq6056.c b/drivers/iio/adc/rtq6056.c index 337bc8b31b2c..4cb9add4682f 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] = { From patchwork Sun Jan 5 17:26:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926684 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 171FA8F6C for ; Sun, 5 Jan 2025 17:27:12 +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=1736098033; cv=none; b=JZAqU9abOkclgim3Fep1HzsFLRmiaWXy6Uo84oobAC9L1268esvzyYjM029DreQujHOaHEGw1/by2odeG2Pmx+e0JtW0BePWFnX36MQ+iqAJz2gM3WBSA3+479U108XOlQXl25uHpocKTnycNONMXyjBHh6rJY4AEJ1qhpeqrlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098033; c=relaxed/simple; bh=Jtc7TozGykM0Wj6p93o65xTHuGnOYj1z1cMBkhoxmG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MThRh1XhHYDZNEn5Y5SH+dmChevggmqrTArSdzx2w6LpVO+oqLetDco5Pmf4ciVIBAnd8yGVA5lpxGrxfAdWvXYzfGXGebIdn7S8kpP1IvHNbu17xFlpttzGx2z8EpEpdgfp2heBjUt0fKNB9oBCjYVgLdsOLwPbAHMpUUZXEUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZqWIdsDb; 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="ZqWIdsDb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B884C4CED0; Sun, 5 Jan 2025 17:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098032; bh=Jtc7TozGykM0Wj6p93o65xTHuGnOYj1z1cMBkhoxmG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqWIdsDbqHj4fGSq8ckhQMqFnRf+2TLnhjwhCKfJRy+IaaPn235FLhoAEfWLapDop quIbVeVGio4sniqrjsxM2h7FUxRiPRgXoKpnBg45/uop23ErwFbVVnVr8XpnUcx2J8 JGFjNoZkrG/K8Z2ujneZOIxtYm6NaJt8M9IMm0kp30AH6p2qzlQA+Hl6UMZsKmu3tx JLqm+yg1nrSnf1KgmBJbWs7c79eRuJXkDvUihWD4Zv3SXybgwZQqgpm84Ivre+GoM8 G2ELQpXreWoMmAyDQLc4/EL69WHx8vYq22iqAl4YC+NprPrTr2d4t4+Mw29kAlSrW2 Q1OrPBAHkgRsw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 19/27] iio: adc: ti-adc161s626: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:04 +0000 Message-ID: <20250105172613.1204781-20-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 Sun Jan 5 17:26:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926685 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 A1AF08F6C for ; Sun, 5 Jan 2025 17:27:15 +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=1736098035; cv=none; b=W2RSLaU0OxT4GOOtsSJEY7vneRllM9EgklWC5rQmvohBGvP7XCENd/er6c1ryHm4tiHcK1Dcm5x0uvbRN0CyfgNpGBtrs+VIn43WXKbFNAQ4FBM58SNi3FxKt/hjPtwMjrlCW0t+hYwm8a2fw7L1M73C0PrED+jW3lDEfeybPbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098035; c=relaxed/simple; bh=Q6Qsf2gEdxsJrcccQEnvDysXVWC+F3Su4CC6BUMXIQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6/9Ke/hYEfVQlkbN/l0CmP/ZmlGiILDqPPWwpoY0HLboIP9oXuxhfgfT3dueVpkH9v/VcD2G2nQ9GdTCGZ+s3EhanxYipgeLA0gyw5LxSjKK9eproXhwTLhkPvlBkDx0zPIZHu8w6ue0FTz9hWsTUnbgzwWb1TFOeLA4rC8Abk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EQM/yiPl; 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="EQM/yiPl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F501C4CEDD; Sun, 5 Jan 2025 17:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098035; bh=Q6Qsf2gEdxsJrcccQEnvDysXVWC+F3Su4CC6BUMXIQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQM/yiPl1yR8jTlexAQ/bkqgBCIU7GeQf7DVpYcn7ps8xHiTh1Ifao10jDU1UgA72 bcvPBrFhWzC5RBz0VuD3aDQv3BF9iZNeCb6uO0hYIBPn8CQvsHIgP1UntVrsqEDyUa Dx/DulYpBDQiNwXxBErCSFV2dhU3PyeBFxGgMaNDUtxr0ZOhW/Q4nUaSWscyaX/v1S AaTjzCjo31DEuFDe3yRm4HulzO7lUcXz7E+Vkguanh7hxucUn2XnWnwLbM9uEt6CNB /t4QE0bSeJbZk2TQVH6QwhiVf5pR65lisnNEwmhAeUffUxZjoW195+jRaYKoV88ctF Ip65Fh6BHGuFg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 20/27] iio: adc: ti-ads1119: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:05 +0000 Message-ID: <20250105172613.1204781-21-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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-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 0a68ecdea4e6..fe8086622988 100644 --- a/drivers/iio/adc/ti-ads1119.c +++ b/drivers/iio/adc/ti-ads1119.c @@ -336,19 +336,24 @@ static int ads1119_read_raw(struct iio_dev *indio_dev, { struct ads1119_state *st = iio_priv(indio_dev); unsigned int index = chan->address; + int ret; if (index >= st->num_channels_cfg) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ads1119_single_conversion(st, chan, val, false); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ads1119_single_conversion(st, chan, val, false); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_OFFSET: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ads1119_single_conversion(st, chan, val, true); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ads1119_single_conversion(st, chan, val, true); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: *val = st->vref_uV / 1000; *val /= st->channels_cfg[index].gain; From patchwork Sun Jan 5 17:26:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926686 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 7DA198F6C for ; Sun, 5 Jan 2025 17:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098039; cv=none; b=lDHGjoB5RByKeMl5qcRD486NLJX+tn45arv4csw9dWALQeAB6wN53XhR5MvKrtTYjfD62eDocw0w21bxEGhjAgvCRDvfLNv8KoKlqN0NU1QjAnlWaijtQ4KgovxVuAjbaAVwVFVXU08LK9jeW1eLQ30+ofQ5Y3m4s9DEXeUIlGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098039; c=relaxed/simple; bh=luNL1NLkc3rdtd+YZvmoF9Uh8NjEhpzaCtoloqL0F3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VGwqDj2DFrPq0DK+qNdWr8i3WQPfgLM1BRHH36Q5iHLDbOyp0fs6KdOLuX29LyR4V+XnDZUI9rnqnzbkxgJLnAd9YUR/XWzmyjQF9s+LebM43t/cUdEmafkNNS0XSAIfnMfEi9Yc08pmyodEkpIQfIrZyxw2KRwM6bYwEjTlFtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tq5ONPoX; 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="tq5ONPoX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B9F4C4CED0; Sun, 5 Jan 2025 17:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098038; bh=luNL1NLkc3rdtd+YZvmoF9Uh8NjEhpzaCtoloqL0F3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tq5ONPoXkcLvH7LRpcwPrlK26caQCALC0Uwy6M0pBxuTTNTSzEWmmoXGx3lJQO3hD ERpfRP+Goea+utRkHkRsMyIaTDNdPd51xMZ9s/p6C2WRksEu58JQSQ5VYh/Eu3+77o LEknA0zhMy4F7x5gwEu2QnGP30AMlLz9Z5KfjIvzMnFsDG/YTjtisdFlzSNOd05MPG tgGTraQH9lSdCa7Oe9Nu08X3EqMr5Sw0oKAviUrgqkFlEf3VmyGXJHXH98Ch4VRRC3 Ca2YjZ3rFjPdLpzV7Cyk86UVvHbn6uDyzYl9S1cPCaz7B9SJzmcdZJGFaUQ6X5l9bE aTcr1JE7pY/xA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 21/27] iio: addac: ad74413r: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:06 +0000 Message-ID: <20250105172613.1204781-22-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 --- drivers/iio/addac/ad74413r.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index daea2bde7acf..f14d12b03da6 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -826,6 +826,8 @@ static int _ad74413r_get_single_adc_result(struct ad74413r_state *st, unsigned int uval; int ret; + guard(mutex)(&st->lock); + reinit_completion(&st->adc_data_completion); ret = ad74413r_set_adc_channel_enable(st, channel, true); @@ -865,12 +867,14 @@ static int ad74413r_get_single_adc_result(struct iio_dev *indio_dev, unsigned int channel, int *val) { struct ad74413r_state *st = iio_priv(indio_dev); + int ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); - return _ad74413r_get_single_adc_result(st, channel, val); - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = _ad74413r_get_single_adc_result(st, channel, val); + iio_device_release_direct(indio_dev); + return ret; } static void ad74413r_adc_to_resistance_result(int adc_result, int *val) From patchwork Sun Jan 5 17:26:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926687 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 D10598F6C for ; Sun, 5 Jan 2025 17:27:20 +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=1736098040; cv=none; b=DzkjPLimbAcFFnKO3U1Q6eop6RnpqplUlTRBQYCKssjnzkYK6zdSIgvm3Uk263tO4OEKBs6qP4iWSkqlmFc9fxqokiFnx97C1IRRMhqV+SrtXEEFDDUDF8uF2525SyTsvfA2NiUzghdpqGWVxK/JipjPvg8+pQ2Sp50SxFz1bvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098040; c=relaxed/simple; bh=KPf/jLRA7SCW4wUrCoTMSteypPI4EMEVIWlbRfbsFZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=co7diX46szLANa5ZHd4/BvClVqcik2DcqUODa/U97XnMavroj/sS+VHuXmou8RRYRu63nvFE3UUYPbesT34l3QM0clIzbDjd5O7BsCoyh+Gzq5RNq+Ifbmb+Z2rt4YytusK8KM4227rI3eTIHE9PfZ0YCNdSGfu2rAHW/lUFa9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fok9foc6; 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="fok9foc6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8C0FC4CEDD; Sun, 5 Jan 2025 17:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098040; bh=KPf/jLRA7SCW4wUrCoTMSteypPI4EMEVIWlbRfbsFZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fok9foc6e/jFv9hK1fwoJ1S/5eFNlkgodZR4EwYMtHPsoMARZ8eEt5gCQoxhdxEk1 duurhtVoLVuDQwPJH4B+mEWu5ocTaYjoYFhDHDwffb1PXJrwkks+PMLRvkMuzzXwms UqjYXEoM2NYBMnssLkF6waG/XHdS2UOUoAXkv2NAeHwf83DA+EBiQJ+dT37PVHPmAL aEc8VWumJDPH3mz70T6g4iVKXlk/BdrmDBgtO/adBaEsVBWcoEp+vHcQLx7i+QyJCK bmfY4SxbiOXVDhLk6UFl6pLQPjnfIPdN6RhCzBqinPhWXlkJAHt6PXT1VeLmuWHGL7 6YKYQvy6hzEkA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 22/27] iio: chemical: ens160: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:07 +0000 Message-ID: <20250105172613.1204781-23-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/chemical/ens160_core.c | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/iio/chemical/ens160_core.c b/drivers/iio/chemical/ens160_core.c index 48d5ad2075b6..152f81ff57e3 100644 --- a/drivers/iio/chemical/ens160_core.c +++ b/drivers/iio/chemical/ens160_core.c @@ -100,25 +100,35 @@ static const struct iio_chan_spec ens160_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(2), }; +static int __ens160_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct ens160_data *data = iio_priv(indio_dev); + int ret; + + guard(mutex)(&data->mutex); + ret = regmap_bulk_read(data->regmap, chan->address, + &data->buf, sizeof(data->buf)); + if (ret) + return ret; + *val = le16_to_cpu(data->buf); + return IIO_VAL_INT; +} + static int ens160_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - struct ens160_data *data = iio_priv(indio_dev); int ret; switch (mask) { case IIO_CHAN_INFO_RAW: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&data->mutex); - ret = regmap_bulk_read(data->regmap, chan->address, - &data->buf, sizeof(data->buf)); - if (ret) - return ret; - *val = le16_to_cpu(data->buf); - return IIO_VAL_INT; - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = __ens160_read_raw(indio_dev, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->channel2) { case IIO_MOD_CO2: From patchwork Sun Jan 5 17:26:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926688 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 553388F6C for ; Sun, 5 Jan 2025 17:27:23 +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=1736098043; cv=none; b=jeAgUD2qYmmOLjr0fklFnXGzPdYxZwEclq/r6YNQDYtBLhzePzzx/92H+CprKlt7TRCoRAVf84VUWF51LWfckKnMFu39XSw2PhrpUQs0igWHTOq/fRHsniA4LGl8FNYwnezaqLMYlwsOiH15IaCRIa6yfVVemtnphtGA+Ca1Pic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098043; c=relaxed/simple; bh=g3hjhJia7MsY61ghQy9J5RYMGQ3jPz2uj222N4yHGoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X3r+cHxhE1FqRrOd8tyvHPhgoR3jueWTWpQKg7Mfz1PuGP3sNttXsBe/Q68IPUOvTl/F4qIjTdYiIDh1bKxcWYEehXYhDuIeH5WYlSPILzFxbTsADN72aDRzstp0j8sRvT7YI7DHoiVp2+jEQJ1JVb0RPT5VoIHkKDv/cu6gv9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YniBf58r; 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="YniBf58r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44617C4CED0; Sun, 5 Jan 2025 17:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098043; bh=g3hjhJia7MsY61ghQy9J5RYMGQ3jPz2uj222N4yHGoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YniBf58r5TX1IAzK1a55UVZ5K8kqvSNvgB/B+CuDCnEDJA6oPUIZcTuuCLYj38Tcw sllxE1a5qOLhBCEoKWS7GVHqeyVevT3OrEO1FSXgakTC4vbnrvLYNv+JBS1Tb/T+DZ cSTQ5RWxh3monmceliCk4IwhyauBhU9DcKoQ0cfRzf+q/8X+YNjgZgShmA0+2LvwhB TM5FzmwciS3hoGsRAVX8gez8mHPMsQFn6jPaHbVaYCJqDkIP4T5vF+5Jcyda6ybxW6 dxvE1w8D9OBoeAOrW5I7RntaV0MZhY84gkpcPPTfxcqwYQGeYnk7kP6wOGZ+aqE82E xwNSC7p9kHs6A== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 23/27] iio: dac: ad3552r-hs: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:08 +0000 Message-ID: <20250105172613.1204781-24-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 216c634f3eaf..64899a02ab28 100644 --- a/drivers/iio/dac/ad3552r-hs.c +++ b/drivers/iio/dac/ad3552r-hs.c @@ -90,15 +90,18 @@ 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: - 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(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = st->data->bus_reg_write(st->back, + AD3552R_REG_ADDR_CH_DAC_16B(chan->channel), + val, 2); + + iio_device_release_direct(indio_dev); + return ret; default: return -EINVAL; } From patchwork Sun Jan 5 17:26:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926689 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 29CE28F6C for ; Sun, 5 Jan 2025 17:27: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=1736098046; cv=none; b=FHBg0SMVW7PV6bA+/euPkSw5H6zoMlh8pWiF1aVSCr/WrSRG/BMEJjF0mmEY37kPFI2oIMZqNTZBPu+iPtzWRV79ysg4Rkwlt2GDW+Gupn4DSsM89UyVNQx6gE2m/GJ99lOpNmz/xqJ/mj91g7ATz+mzagA1dIYx3+yd28v1iL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098046; c=relaxed/simple; bh=AoDf4nBDGo++mG69k4T1L8PEeggQpxjopLGcZh3X2xU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZeBq06LBGsDwvJhaU1XIT0otFJ4Dbv/Y+m7T79A+zXU0pDScbeZU9cvYF+LBKsNDDg4t5Ei08CDPZO3VElG1PW+RFGrmXv/OzlIkz7V9PHpAXPK4fHFFJfVt2XPEbZeZ39V6In7ItcpLrQpRHhtLgkDEB7VGfRZsxEX0P6PKaOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fe8wwTE1; 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="Fe8wwTE1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6612C4CEDD; Sun, 5 Jan 2025 17:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098046; bh=AoDf4nBDGo++mG69k4T1L8PEeggQpxjopLGcZh3X2xU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fe8wwTE1SiYhradFfB6vT469t71qqcqEaLJGjyQ77dIRIFaLJxiD6yfE8CAtRZrmx DNBfM+DD03TZE74o9Pl8fat7BOd1BVhI5jJmWyTwVn+Y976x9ar22vhUuEY4mIhIFm HcyEw7r7tpg2byMpviEAHdKB+Mc92mCpqG41tyo1Gy+MVfytgbwnuUfrY88tFYtWF3 WXSvsTz7v7HYXS6GF0TDXd07OfvUeYvvtAc2bb5fPwEP2hjzTJNtlvufsUczV+7mZy Qrs4qsruwixLPxU37LE8wdmzSmNHzl+2+Fesqy785vfBlr4PrGIv4RZG7eUaQ6AQX0 bWVcU2dAqcRxg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 24/27] iio: dac: ad8460: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:09 +0000 Message-ID: <20250105172613.1204781-25-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/dac/ad8460.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/iio/dac/ad8460.c b/drivers/iio/dac/ad8460.c index 535ee3105af6..6e45686902dd 100644 --- a/drivers/iio/dac/ad8460.c +++ b/drivers/iio/dac/ad8460.c @@ -264,9 +264,12 @@ static ssize_t ad8460_write_toggle_en(struct iio_dev *indio_dev, uintptr_t priva if (ret) return ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad8460_enable_apg_mode(state, toggle_en); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = ad8460_enable_apg_mode(state, toggle_en); + iio_device_release_direct(indio_dev); + return ret; } static ssize_t ad8460_read_powerdown(struct iio_dev *indio_dev, uintptr_t private, @@ -421,14 +424,17 @@ static int ad8460_write_raw(struct iio_dev *indio_dev, long mask) { struct ad8460_state *state = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_VOLTAGE: - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) - return ad8460_set_sample(state, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + ret = ad8460_set_sample(state, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CURRENT: return regmap_write(state->regmap, AD8460_CTRL_REG(0x04), FIELD_PREP(AD8460_QUIESCENT_CURRENT_MSK, val)); From patchwork Sun Jan 5 17:26:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926690 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 0BA338F6C for ; Sun, 5 Jan 2025 17:27:28 +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=1736098050; cv=none; b=DVjlouz0VP76voutdi4l+SDDiKPsWTFXbKP4bA0EbrtDQyrC7NvmBLO33LevVx3z+lWCt9m0eMQMmOIY+mSbhNv9m04DEIdWT57f6apCmmcMenOGgsPHkjBFNbIDhSOGUvyV5SH51W2MTUAwKv4XNaSdhwNsGA01qNDkLRvL90I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098050; c=relaxed/simple; bh=md6jWwUtO95BgwcXVwXezSoZBYj5BSJ5q6Ow5oWA/IY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JrR+upsFxJZSJa8ko+mYU447MOuk4U3lLD2TWa77u2fZ1aVqXr6dmUQ+9g53+DujT1kPZEEQrs3CRSMPLNJn50EvUGdrsZjGsVOYVHScg6NNMFmIu7KgPkRjr7QuRY1L4IzXK6KUQWAPm0+/6xwetmUJYIJQ99qSbM50NTuOc0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l39Wd5vh; 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="l39Wd5vh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94FCFC4CED0; Sun, 5 Jan 2025 17:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098048; bh=md6jWwUtO95BgwcXVwXezSoZBYj5BSJ5q6Ow5oWA/IY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l39Wd5vh4WVu0C+d1gRmOhG5jgAYwof5b8lkKvJDX3jpBHth1wBa4/SltR0D8sHEE zdgxKBF6XRtr/NCZ5zSG0eCpTiqLpGAfKqtO/iCCZrstFqjS5yBdGmX3+K63+cBzxc CvssKiQkHZJDKf2KhFK+F1eNS79uND72RfX3ePCh5ZE6NEHPHOEx+fexSI2Zo/6o4M fet36wA3ukgsBIqpryo87VYtFVLO/O33XZOgN7n3AfugLEyLcapwQoRBNsPgny79X4 YlPAJ5eQyuzoK0dmI0VIHG3xBSpHLyX6+9wsyArB4nF2UfxopSbbLZ50WdeGwf6Mov 8oFSmld06/TYw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 25/27] iio: dummy: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:10 +0000 Message-ID: <20250105172613.1204781-26-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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 Sun Jan 5 17:26:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926691 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 50A1D8F6C for ; Sun, 5 Jan 2025 17:27: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=1736098051; cv=none; b=ULPnzKJQOn7OrFRd5MuzJ9T0UYi94/qsbPG7UuEdqjN/e3dttzMQi1mOQlbQfDW+GeZCPxhxF24q4ike+29JAhnP3/Xhx/1aIF5rBD/WTbJRR7V+2uGpHGAWv+Cj4rnWHqERpvcHYQ/iF/XJzTV0xvqRWSZrLNamlLJQ6Um3g9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098051; c=relaxed/simple; bh=WgmCfcR6LyM/e7GGfwpOhveZgaF8JMYRnrXccjs4AMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BmwvtvxsFN+tzGv4fLMaqyaiWQryi6W1VLmPBt8+DJKUnAdZCwUqIgDy9ufEV/OqnFLe5RtJseclqsH+D6rZJg7W2DfSRjsi6cTz2S+wu2nsgk1BWoSGJZO4l0T2vD3HrenEZ4Aqb7TUNcxu59u3esu2+RdFVm0jL2AAI+2d3yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aJodWHFi; 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="aJodWHFi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BB96C4CEDD; Sun, 5 Jan 2025 17:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098051; bh=WgmCfcR6LyM/e7GGfwpOhveZgaF8JMYRnrXccjs4AMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aJodWHFiAx91aPo/urevp6Y/wpHe4UEEPBUZbK5HHVB7zkRKuO17aXr8R9USVRlj7 G40lGaTk4ss//Mggtt5+/0stDgeIybgitXslx+nxMKqXEkPIi32TtnAAtDzygoc6d8 8NL9xJbfv9DCP5OebFZht6FD2jM8LX7YVer7DRYMofUVEv7ycMQTIPtYQs8FRFu3Sw RB7+tRq32MUB1Pg4bWrpAYgQjQ60iPaa28P1etp5txFha58XYBGgtFkvptZHtMn6D5 fUQD8jJGtKP9AXsyX1UnUzagnALQVI1LMUtJ5GTiyg+hd67pgxphh85UKRC51kQmDl kOkrKIogasPhA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 26/27] iio: imu: bmi323: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:11 +0000 Message-ID: <20250105172613.1204781-27-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/imu/bmi323/bmi323_core.c | 51 +++++++++++++++++----------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/drivers/iio/imu/bmi323/bmi323_core.c b/drivers/iio/imu/bmi323/bmi323_core.c index 7f386c5e58b4..4c404e44a3f4 100644 --- a/drivers/iio/imu/bmi323/bmi323_core.c +++ b/drivers/iio/imu/bmi323/bmi323_core.c @@ -1702,26 +1702,36 @@ 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 +1757,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 +1766,12 @@ static int bmi323_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_ACCEL: case IIO_ANGL_VEL: - iio_device_claim_direct_scoped(return -EBUSY, - indio_dev) - return bmi323_read_axis(data, chan, val); - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = bmi323_read_axis(data, chan, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_TEMP: return bmi323_get_temp_data(data, val); default: From patchwork Sun Jan 5 17:26:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13926692 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 CC13C8F6C for ; Sun, 5 Jan 2025 17:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098053; cv=none; b=RS6ma5vnV8pcWEVGizbHS/muCFaB0XNR2xLzlCGGonDDQVPnlddGVE0Cqcnyl6jsHyHwGRREHrShZfIY15qk3WuhoyQaqqtWT8iKxTJfFuK42d8F8xY8NBK0qTozMHYlzF/K1sUbuxZi9jB+m6oZUcRlaJ/CoxcJV8q+F7TcFds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736098053; c=relaxed/simple; bh=efDmfrqpb35QgZd8qGvw16iYdHkWXdieufTb1POukhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hHC5OncKWc/fNIf7P1BEFoFRLKtEOLz+3X14FsLP8P5rt6E8UcwwR9hmKjTKDFT0Y2ylZCEG4MP9246ScQwQ1a6acI3SKBkrULifwjJj37XDU+mDmqFx5QxNmJ50z3vynrSi/GkrLm3D2iH7SwPqD2oSZzV64dYUnk9pAx3O2Og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FkB0j+/8; 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="FkB0j+/8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08B6EC4CEDD; Sun, 5 Jan 2025 17:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736098053; bh=efDmfrqpb35QgZd8qGvw16iYdHkWXdieufTb1POukhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FkB0j+/8Ct9HDOnprcgTAipv6OSm8CU9J7fzn1KYSLhuOhzcnJP3rnM8awSbYR0s0 8Tuznd/pYTtQHm272mlPEvzBaPYAraGvET6IW50V9Y0blr/gvI9CuGIvnjWW+SdQMb dFSANpuooRGW9U7A8MMCQJ/7kdDWZCPTuq48klJAe3MGMchk1+u5q21H3I50bJiBKr t95i+LN2GPufCmbBHwGLV60uzDyoxHpvbAqyzFyX1Yv3wsUHWWcJKdhZq6WVFduLEz zc3siexIZsPncexpFvmIKr8OCoUx6Da7DP1yucyq6R5Y9VM6TrckKWwKA7iNJrvj1V 711aJkv5gymEw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?b?4oCcTHVjIFZhbiBPb3N0ZW5yeWNr4oCd?= Cc: David Lechner , Jonathan Cameron Subject: [RFC PATCH 27/27] iio: light: bh1745: Stop using iio_device_claim_direct_scoped() Date: Sun, 5 Jan 2025 17:26:12 +0000 Message-ID: <20250105172613.1204781-28-jic23@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250105172613.1204781-1-jic23@kernel.org> References: <20250105172613.1204781-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/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 00a33760893e..a2f3df7f1818 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);