From patchwork Sun Feb 9 18:06:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13967056 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 897F91E0DFE for ; Sun, 9 Feb 2025 18:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124551; cv=none; b=Fp93mNzuQXlN7CJg+xf+cvqg6HEYhneFO326RjViaRtTCBiK8B6KmFFmtBTn8eEHqqgWhJ61KPaXryfyeSpts99Jne7P6m8jl4InFyMYPO+f23V64PC4wmmszWdXyypo6cS/IHvkZjQ3bfouAp0O1735WmFJxbVDmOVkoRnGknA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739124551; c=relaxed/simple; bh=bmwY4eYPSPwIYEQE0xzFBYW4Vk8fPKHIWAts6VBI7OQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ztyahhvjet79lxHXJ7y09fCZEa2uy0JVYv7bpq1x+t3j8Rrk0wlX3d08sBt4bLXfz+o/IaPCTdTum/npmRfIDmCaNOq5xw/qBB8DXJ+x9ODgWo+pGYoESE0hPg9slrGbdfd4XCEHfhe3SPmLNKe1BRQ9PzK5Ca/Xmx47raOM+18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z7Q6GHO+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z7Q6GHO+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D448AC4CEDD; Sun, 9 Feb 2025 18:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739124551; bh=bmwY4eYPSPwIYEQE0xzFBYW4Vk8fPKHIWAts6VBI7OQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7Q6GHO+RCIqsMYWLLiw5sEcnd1bvWzsMOF/EGf+F6UpflwbZz8eEq7T/umj4oL5e 8lDBcBxno2+5TL5DFi3hvdPOpYI5KKvQZh5J6xBo/GmtStx324AicYSLIEHrZWCwNI ISToBPtHuQQRItrJTgveICJSXtpD4rvWMrMlN+i4pC2RLdoGhhPOl7+dlXZs2iaCE0 Y/qYKEQBiuh2KFcpDZHCwfE3ToaaFvSg1AwnnFH3hsLwnZE6K5YTiKVJ/j99Z7TtYl S9EDuvNEc5WTJmSehNMTfDR0IhJUMnQn4uxUC7f/WfBs8Ol68IGg6+iz0UVm3/uMWf 5M8iXMsZ8IWoQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Mudit Sharma , Julien Stephan , Mariel Tinaco , Angelo Dureghello , Gustavo Silva , Nuno Sa , =?utf-8?q?Jo=C3=A3o_Paulo_Gon=C3=A7alves?= , ChiYuan Huang , Ramona Alexandra Nechita , Trevor Gamblin , Guillaume Stols , David Lechner , Cosmin Tanislav , Marcelo Schmitt , Gwendal Grignou , Antoni Pokusinski , Tomasz Duszynski , Jonathan Cameron Subject: [PATCH v2 20/27] iio: addac: ad74413r: Stop using iio_device_claim_direct_scoped() Date: Sun, 9 Feb 2025 18:06:17 +0000 Message-ID: <20250209180624.701140-21-jic23@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250209180624.701140-1-jic23@kernel.org> References: <20250209180624.701140-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This complex cleanup.h use case of conditional guards has proved to be more trouble that it is worth in terms of false positive compiler warnings and hard to read code. Move directly to the new claim/release_direct() that allow sparse to check for unbalanced context. Includes moving a mutex lock into a function rather than around it to simplify the error handling. Cc: Nuno Sa Reviewed-by: David Lechner Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- drivers/iio/addac/ad74413r.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index daea2bde7acf..f14d12b03da6 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -826,6 +826,8 @@ static int _ad74413r_get_single_adc_result(struct ad74413r_state *st, unsigned int uval; int ret; + guard(mutex)(&st->lock); + reinit_completion(&st->adc_data_completion); ret = ad74413r_set_adc_channel_enable(st, channel, true); @@ -865,12 +867,14 @@ static int ad74413r_get_single_adc_result(struct iio_dev *indio_dev, unsigned int channel, int *val) { struct ad74413r_state *st = iio_priv(indio_dev); + int ret; - iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - guard(mutex)(&st->lock); - return _ad74413r_get_single_adc_result(st, channel, val); - } - unreachable(); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret = _ad74413r_get_single_adc_result(st, channel, val); + iio_device_release_direct(indio_dev); + return ret; } static void ad74413r_adc_to_resistance_result(int adc_result, int *val)