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 A98A13AD510; Sun, 28 Jun 2026 14:09: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=1782655794; cv=none; b=BDM3nP500bKaB1yKlMCsEchF7C6uRPb4RIfIhBbf+O3LziZY2pzmucRjuMhwhB2k1pDWd01DUnCTRE/RSKMh14VgVHqu8QEjduWoOSCo7P8UIjuo8YYWGFA5mNDrQJASxjnzy9lAr4dNEZw2Aj+9+B3Zk3qxoHPB2dxvTf+wFB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782655794; c=relaxed/simple; bh=XktOlaasuSm3hYXKmS8amfCoiKQ/2h3DNBwBGo5qc3k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iQG2LT7+pFF8wfUATl7L/j4vKqKwfe4s/VyjTf+htHDVZR676NYpa1QXjt+K6p+r4zMALQtUO9/ncvWpvZEbZuBDlWT5MSufZjxCLzaA6rfTu5ULtUYoazs8/CvTbCisquBDjr1fWDcFB4ugDiqgpjVlpfhjT38Lr0RprjR5bn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iZ9weRO8; 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="iZ9weRO8" Received: by smtp.kernel.org (Postfix) with ESMTPS id 75DD8C2BCF5; Sun, 28 Jun 2026 14:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1782655794; bh=XktOlaasuSm3hYXKmS8amfCoiKQ/2h3DNBwBGo5qc3k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=iZ9weRO8JE29TpLckXnd+G3H2fhrkbUG3KJQXhTKFNMWTrz3jU53x/alOOUslsH9v pT7K5opavqGq72w19FZTorIroDEavCGD+jHwDEMDTrdwH6ejvPpnZLMZVKWkNrOmTf 5vFG/F8k1/2Yd2NAdOPfaPMpzOcb+MSQjOnbEDik7Lk01w3Iche9J61n9ailhtsgZL wO+JKe1Rbi6FIT5wX0miilD302wOr8XY9sr+nH4jN7Hb5UOAQTYorwL1f3l1rdZvA3 drTA6c3Tc1Jw3XJ5sLNmt0SaNTFY+y0iibRJQtx4rYDyivXQVbZRUj1+5dAXTI8qm5 AGwcCtvgVqgfw== 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 6C3E2C43602; Sun, 28 Jun 2026 14:09:54 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 28 Jun 2026 15:08:17 +0100 Subject: [PATCH v5 10/12] 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: <20260628-ad5686-new-features-v5-10-577caadbf7c0@analog.com> References: <20260628-ad5686-new-features-v5-0-577caadbf7c0@analog.com> In-Reply-To: <20260628-ad5686-new-features-v5-0-577caadbf7c0@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=1782655792; l=2132; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=KXdOCM8K80hSnPdNpvlDlxzShY7L4kR4B4GuvME7upg=; b=aNYv+xR+QxVbEAyfJJ+GZdKnBX5FDx9m8LPdRniFyAUJ+TTxXpJ0BFYfvIjpE7nz5IRDOfDPk WjSEUdXbNEZAIPTmFlzr9GH39KauDXLYwFFearEyFKYUowuMBFWjnc/ 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 75dd7921c67b..db175e77b0b7 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