From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED35523D7CE for ; Mon, 19 Jan 2026 19:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768851064; cv=none; b=X22qqciKXPTAPqurMccoZhIwnikXdQ/pK5Cgf75iAsAcBkECRAmkfeBy4SBUXAcFgmleK7sMOVEqsYvi6yCiYiilqfesvdFpLPwFEu2g4jRqM+1u4PQXPAaEO10Ebbq9AywLLOQHE8JaFEKdAsqPDYC4TNxKyqcW8t7M7j4AK+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768851064; c=relaxed/simple; bh=8ekbjBw6M/rsnNmO/cbzayaTuonKM33h9jOjhxZad3M=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Cc:Subject: References:In-Reply-To; b=Id6DUKrvlmsXRCGRCLN1lz78VcdGeOrY7MbGgWr4YTuK3scarkIE+8I011xVWj3xJ0veqlVKc9fsvQulUt8oY3KZNMPvCSFsGSfjt/TiIILUOvULhVSMcYZAisFaWyQwhqWOGvauuJblJMV1yGlWN9ZQJUs/n5zvuTCs+uw+eNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QXQDr7Na; arc=none smtp.client-ip=209.85.221.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QXQDr7Na" Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-559a4d6b511so477374e0c.0 for ; Mon, 19 Jan 2026 11:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768851062; x=1769455862; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mSI/mMQ05DiSZvf3TBwxj/Af+SeoSoRBsI8Y3/TAqgo=; b=QXQDr7Naeb800YNykA01uCCTnGG3IZLuAkfN85m/9z3fPGTlkWwYPOa/22vyQUtIho TNWmzFPDNncifN7ptJlAtPBHq0xeKmepj7oDHsUOkF4zGpivutlLd49pVhq5/WGZiJoe XJJ8h7AuS706Ql+h617J+4idxJj6pFnPp20cdOf09hx/UiQnTb6mV6bshUlgU3rh2O+v K/c5ieIAxrw8CQiAue+62ceYO/4ezFvR7u8s8cV+7qrUeiEBkkYVPfOLpoYr0U/5NkMn adt9rwXbSfuGGmme/OtNVh1ge+ivTFQpImOnzBwQaes/eHEyOdijMlMuE7V7r9WtNaAg 3Iiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768851062; x=1769455862; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mSI/mMQ05DiSZvf3TBwxj/Af+SeoSoRBsI8Y3/TAqgo=; b=e3SBFNdl3KClKduHC+SEjwVhYAbwoHWeGMPud7JK/oHPteLb7mlL8blcYgqKF0vs74 6Lhh4y5X9KFG6/Fee5Y68xpUD96egt2qenoDkEzuvLGlHbqzc2qymZxpCmj1AFvvTIfx j76QQsfgUV2FGrYKg41hyQPaiic989E6hATnlHPQ7Cx6tb4URv130JlHSQ5EPg4Lh1NP cv6s4hLjOVRhYHoGGKvIPhRdaNsu+1qLCE2y7jW/02n6jGSR1xP//I3P7GIA6l9Auw+H AqjfEVKn1SI3KHnOFHr5VKqz1cR0IyFMGUD/RzFEEVD+jt+1XplLSUD4sLGdejeXcUdr i6eg== X-Forwarded-Encrypted: i=1; AJvYcCVFtcdBYBFDJILGIVu81lQj4O58/FDz9QmAN4nkP7UQYSsSvlgqBUzx+9t/rsLVi717PSJSAHiAYDib7sQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwIVgOJizyAdCbAiySjcvLyJLvzrskq17v7imteAEk/+At91MUB HUXi0mfLkc7Xx1lZZtPfLg/d62cC9/gF99sbcDwy8zujPbt8N8+95OTX X-Gm-Gg: AY/fxX7UtTwwh+jM1qhR3NiGfJzkCnyC3JDe86fkrctC9ssfNH0B72vFVOrUbcns7rw LgR512E9/jP958atj0hvvELSDMkJxUjQEcOwYteVRZhXx/qg5uQKl0N9i3uw1pHi3Vj9f7DNsBf nhiRoOM6+MDKLTepbcf05pVy/sMauCn88G2B5VdrDbe3iSNyFv57fwR1oH+vJs92Of/08wngnRV OlC8WXjHiCZ0oIDIvW3GuJUYnQyhwElV+aOUcam8eioVyFE+734GMhs/CzxvzhU2sMpfP7lZZSd 4QmJ7s6uB4cls+vzsQzsdow0mS/2F6HraqmA6q67Cb3DM46VAgRtpOOBUWUkrI6XzDBrOp5O2+K kvwiX+VXBCxFcDfWkz3HxkrUjtduAPo3k7RE3CYzH7DNpY8ZQ7hMd3hKCunLRC+hHeWQR46DC8a FuOQ== X-Received: by 2002:a05:6122:7c8:b0:54a:1e96:e958 with SMTP id 71dfb90a1353d-563b5a79b75mr3945356e0c.0.1768851061928; Mon, 19 Jan 2026 11:31:01 -0800 (PST) Received: from localhost ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-563b70fea8csm2984342e0c.15.2026.01.19.11.30.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jan 2026 11:31:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 19 Jan 2026 14:30:53 -0500 Message-Id: From: "Kurt Borja" To: "David Lechner" , "Kurt Borja" , "Andy Shevchenko" , "Lars-Peter Clausen" , "Michael Hennerich" , "Jonathan Cameron" , "Benson Leung" , "Antoniu Miclaus" , "Gwendal Grignou" , "Shrikant Raskar" , "Per-Daniel Olsson" Cc: =?utf-8?q?Nuno_S=C3=A1?= , "Andy Shevchenko" , "Guenter Roeck" , "Jonathan Cameron" , , , Subject: Re: [PATCH v4 4/7] iio: core: Add cleanup.h support for iio_device_claim_*() X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> <20260118-lock-impr-v4-4-6c8d0aee8ed2@gmail.com> In-Reply-To: On Sun Jan 18, 2026 at 2:35 PM -05, David Lechner wrote: > On 1/18/26 9:44 AM, Kurt Borja wrote: >> Add guard classes for iio_device_claim_*() conditional locks. This will >> aid drivers write safer and cleaner code when dealing with some common >> patterns. >>=20 >> These classes are not meant to be used directly by drivers (hence the >> __priv__ prefix). Instead, documented wrapper macros are provided to >> enforce the use of ACQUIRE() or guard() semantics and avoid the >> problematic scoped guard. >>=20 >> Suggested-by: Andy Shevchenko >> Reviewed-by: David Lechner >> Reviewed-by: Nuno S=C3=A1 >> Signed-off-by: Kurt Borja >> --- >> include/linux/iio/iio.h | 65 ++++++++++++++++++++++++++++++++++++++++++= +++++++ >> 1 file changed, 65 insertions(+) >>=20 >> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h >> index fa671e120e95..4a0a77fcfa8d 100644 >> --- a/include/linux/iio/iio.h >> +++ b/include/linux/iio/iio.h >> @@ -10,6 +10,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -740,6 +741,70 @@ static inline bool iio_device_try_claim_buffer_mode= (struct iio_dev *indio_dev) >> */ >> #define iio_device_release_buffer_mode(indio_dev) __iio_dev_mode_unlock= (indio_dev) >> =20 >> +/* >> + * These classes are not meant to be used directly by drivers (hence th= e >> + * __priv__ prefix). Instead, documented wrapper macros are provided be= low to >> + * enforce the use of ACQUIRE() or guard() semantics and avoid the prob= lematic >> + * scoped guard variants. >> + */ >> +DEFINE_GUARD(__priv__iio_dev_mode_lock, struct iio_dev *, >> + __iio_dev_mode_lock(_T), __iio_dev_mode_unlock(_T)); >> +DEFINE_GUARD_COND(__priv__iio_dev_mode_lock, _try_direct, >> + iio_device_claim_direct(_T)); >> + >> +/** >> + * IIO_DEV_ACQUIRE_DIRECT_MODE(dev, var) - Tries to acquire the direct = mode >> + * lock with automatic release > > Should be just IIO_DEV_ACQUIRE_DIRECT_MODE() > >> + * @dev: IIO device instance >> + * @claim: Variable identifier to store acquire result >> + * >> + * Tries to acquire the direct mode lock with cleanup ACQUIRE() semanti= cs and >> + * automatically releases it at the end of the scope. It most be always= paired >> + * with IIO_DEV_ACQUIRE_ERR(), for example (notice the scope braces):: >> + * >> + * switch() { >> + * case IIO_CHAN_INFO_RAW: { >> + * IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); >> + * if (IIO_DEV_ACQUIRE_FAILED(claim)) >> + * return -EBUSY; >> + * >> + * ... >> + * } >> + * case IIO_CHAN_INFO_SCALE: >> + * ... >> + * ... >> + * } >> + * >> + * Context: Can sleep >> + */ >> +#define IIO_DEV_ACQUIRE_DIRECT_MODE(dev, claim) \ >> + ACQUIRE(__priv__iio_dev_mode_lock_try_direct, claim)(dev) >> + >> +/** >> + * IIO_DEV_ACQUIRE_FAILED() - ACQUIRE_ERR() wrapper > > This one is correct style. > >> + * @claim: The claim variable passed to IIO_DEV_ACQUIRE_*_MODE() >> + * >> + * Return: true if failed to acquire the mode, otherwise false. >> + */ >> +#define IIO_DEV_ACQUIRE_FAILED(claim) \ >> + ACQUIRE_ERR(__priv__iio_dev_mode_lock_try_direct, &(claim)) >> + >> +/** >> + * IIO_DEV_GUARD_CURRENT_MODE - Acquires the mode lock with automatic r= elease > > Missing () Hi David, I didn't see what you meant in the previous email. Sorry! I'll correct it. --=20 Thanks, ~ Kurt