From mboxrd@z Thu Jan 1 00:00:00 1970 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 A0DE441610D; Fri, 10 Jul 2026 11:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783682461; cv=none; b=Wq2fZXiYfbe6ZWWVySRIO/tFFjXUi8T2zCalIbPyMszB06bl+SFwP93TnkeTVCwQ9FLQtgtWCh/kZCW1gWpMJWCL22zPyAclHHzMGTEpbUuEug+mB2Np1Q2vfinDyImHIlmTrzLBI7gJQfJ3arm1/zOJ+PL5O4I3sZdn4/cT2dM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783682461; c=relaxed/simple; bh=bvM61nZlVlm3Dqfqh6pLDa+6KikA7MazMtB8NJEhcEE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Zd1cFsGqMpI4wb34eRBluy9wgXoUqv3FwcSSTPfIvHwYwpa0z3eJXg0AGPvrTs48Ztpnv0sHbkGueF3tcCb93Dsp5LaCN0r9fhwhJQqY9yv+dgRUiFxhCvhVkElZbPVZI6vgvq/aH6nXRs8KSuDQsBC9yQiMK3NwI/rkZqOP6EE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ag3hhozV; 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="Ag3hhozV" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8C60DC4AF10; Fri, 10 Jul 2026 11:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1783682458; bh=bvM61nZlVlm3Dqfqh6pLDa+6KikA7MazMtB8NJEhcEE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ag3hhozV4S45f8SFv5OZ3AhHGMdAp8t7ZMbwJKVpQZJuP9lEHPGI3pdATItah4SOJ eUd4DIb1vBhj591DJYvQ1Qp7HtwGK9d+9889IANsJKb2z/mjCS2Canh3dS8Nq0wDDH GYAlyo9+uKHlaxEGlbPDDZPSCRQOorxK9mxLOHOsbgsgSYtujsvrDsSZi6r3LYook3 gGwb0R9Xf/W0JGi88c0Zc3W5oj7fjY22xOIxKARfGR3dGQavnf5RWSiMwnpIQ2/UYP 8AAfJYCCeJ74LeaUake75adAShIKa+MO2jHUNLgcfM9cw8b9/reD4Kv41hD/CB0ibh pPe3FcaWhqAZA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79591C44507; Fri, 10 Jul 2026 11:20:58 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 10 Jul 2026 12:20:49 +0100 Subject: [PATCH v7 5/7] iio: dac: ad5686: read_raw/write_raw: use guard(mutex)() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260710-ad5686-new-features-v7-5-1bcc8c280e4d@analog.com> References: <20260710-ad5686-new-features-v7-0-1bcc8c280e4d@analog.com> In-Reply-To: <20260710-ad5686-new-features-v7-0-1bcc8c280e4d@analog.com> To: Michael Auchter , linux@analog.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , Kees Cook , "Gustavo A. R. Silva" , Rodrigo Alencar , Maxwell Doose , Joshua Crofts X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783682457; l=2132; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=4HNzAutLFGeXIbyru6R+loI4tx3NII/f1eSB75Ol0ao=; b=XVywTb/qzdZLK070cIpxzqti+5w13j0cJ4eqN8F68hkkTSAnN0NyuoINK7cbHjtXNdybhCxMf k0L1DABfT7jAoaBEu62qBNJT/zJTGXT8bBf2SRHRix/gYJpzbPEta3a X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Use guarded mutex lock to facilitate code review when adding new attributes. This will allow for early returns, avoiding error-prone locking and unlocking in error paths. This also adds missing include linux/cleanup.h. Gain-control support will allow the scale attribute to be configurable. Reviewed-by: Maxwell Doose Reviewed-by: Joshua Crofts Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 316f9ccf54d9..df32f46db81e 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -177,11 +178,11 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, struct ad5686_state *st = iio_priv(indio_dev); int ret; + guard(mutex)(&st->lock); + switch (m) { case IIO_CHAN_INFO_RAW: - mutex_lock(&st->lock); ret = ad5686_read(st, chan->address); - mutex_unlock(&st->lock); if (ret < 0) return ret; *val = (ret >> chan->scan_type.shift) & @@ -202,23 +203,19 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, long mask) { struct ad5686_state *st = iio_priv(indio_dev); - int ret; + + guard(mutex)(&st->lock); switch (mask) { case IIO_CHAN_INFO_RAW: if (val >= (1 << chan->scan_type.realbits) || val < 0) return -EINVAL; - mutex_lock(&st->lock); - ret = ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, - chan->address, val << chan->scan_type.shift); - mutex_unlock(&st->lock); - break; + return ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, + chan->address, val << chan->scan_type.shift); default: - ret = -EINVAL; + return -EINVAL; } - - return ret; } static const struct iio_info ad5686_info = { -- 2.43.0