From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) (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 1A741284B58 for ; Sun, 18 Jan 2026 15:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768749802; cv=none; b=quGpLVeLpOtkQKR04I9kMhrSZ58cX74kcgt6tFvNivNct3bE2QApJSyplbWyKIXPvJ4PUsRRI4fcERPWBheNp8sNnYQyQdHEt5e2gYR5Czcg+/u1xVnxdrp3Qs7MKvqRCAz8ig1rZFh8mW39YRLm+tD9a6JUhIyv9XNnNBqfZR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768749802; c=relaxed/simple; bh=oDCpgvsXM4z2bwqDfi9aak6qgcm1ME6wpQjZP0HqRiA=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Cc:Subject: References:In-Reply-To; b=Iw6fyfgrI55vr/9+dfk3pjArMMGbig/4GsX4hB8cO9eL5ROms5cfdpmh2jvWB3MX75zvmj9gCd9agb7/lpKgMjA3bB3IDkJjN2GqvmjzYPQkKiMcOX0uhvipPpXzdnvq6d5ySLUk8lp5StzWAdE1Bt5NAVjIgBM76Llt7Yn4tuI= 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=WY2mP+4x; arc=none smtp.client-ip=209.85.222.44 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="WY2mP+4x" Received: by mail-ua1-f44.google.com with SMTP id a1e0cc1a2514c-93f56a97064so1093150241.1 for ; Sun, 18 Jan 2026 07:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768749799; x=1769354599; 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=r3ZZgfPfki6qi1CLiANLanlgbVGTSpzfg25ShrKXaFI=; b=WY2mP+4xcyTdj74QdIdknnmTgCvfVPdlx8v3vjl3ZI1Fyc1RbUr8sG6SEEKJ3OeP/M WDsS9zool9YPkhlAef1IC8v2Yz3bM52Wq/Bew8uldYeoQyXEq7YGGjJUwSjA9nIIwWI1 pRiSc27iV4mpMIqqDZOPck6y2ut1aRxvGJT92/E2uItWqAm0RrID6KfVTGKbqEt0Yxsg 9h+k2r4SJAZ3QDTYrTyQ6TWIdRUWnxr0WOFT3o0NLxv1fL8H4Mt/pukI2yjC3gilxagH 2PEmZzeuXq/5xMvQOYfqQTTwxHhPhsONMvGFY8llxfzv7BpWh2xtbirWel3IdPsLtc3+ Yqyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768749799; x=1769354599; 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=r3ZZgfPfki6qi1CLiANLanlgbVGTSpzfg25ShrKXaFI=; b=MdpmMTLYJeurx1ApBf8sv2AIBySPr0BKo2dMIxxamC9fLR3DPsZvBVrHlLTZTL7sU3 oEwKisIFDtspkdSlr6FDCQayavabD9RnuIpVCPUUuFAU0MiKDsc5aGgF1hsE/MM8IR40 H1YYhODQena6wQzoGtxhQ9Rp7DWJfZDvJr//LzofoUEP4/bOQdIxft2Hi5L5hOzNxrwu 8DKOxtw6ZUtOJcDl/HIzMUVoVXlbGHWwW90B02gWUHjwZWWCspoUBjutECn77JS93xXa ZnTk3QG3bTm1YbVkR4pQcYE4iudvpfsyomQ8vRT5Fkngil1iqVYvaDME4QyZofChKvxE Wseg== X-Forwarded-Encrypted: i=1; AJvYcCWNHq8m0P74SK85ujqIfPnbYXi734KaG1nZtwl/ROX5OrCNlWqIhydCdA4ByMwr07NhnqBdz6X7JTK2xEg=@vger.kernel.org X-Gm-Message-State: AOJu0YyyCa7ZjO1MLJhEHW7zK3Z810LqdddjVu5Cz5Phhj0wAvT8OySa YXRVEOriMWaOxZgAVJJpbzZR2R196ezOwKh7j9OCHL1SPYJtp/RULY91 X-Gm-Gg: AY/fxX7ZH3D9rKUP4zaaoxmBgCdXzSbwG3fKsC4DZEHqz2FPLbNNIwZmxnQrJKuC+/T i0QMEbiHtILCfB7b9CjAyu70QCEfVHBSAWMcWkIopMXxxTK7E7pyT2PEOQgW5n4YBOiGOlbIuUm JiSIkAth4QxT6V8hSaMHqmIPjZu02jbPxF8wyh9KTOpfYggOivJ4WUmS2MFLTyhzhgXJYE34KSk OyC3FI0ZH6vsbJuKFwSJgCO7OFhj3n4bZWXNduhuZhVN91+8b158/k/8wGZtkAB0OalUbHycR3a eQ/iYcXofkvMf8ahdez+lAaTiwVpSIYXaqRwE10MbzrUOygEIRRzkb34L8KuAkc8CMEuNMYToAg 4qwgiIDFH/359e/YIaESj6AuoGCgFAYf0O17pz2i0W3cu+hKNH8DQQP+7A+x2AscGfzT3+gqeW2 5uy2JksL/dyHRQ X-Received: by 2002:a05:6102:dcb:b0:5db:3b75:a2aa with SMTP id ada2fe7eead31-5f1a701cbe2mr2430397137.18.1768749798940; Sun, 18 Jan 2026 07:23:18 -0800 (PST) Received: from localhost ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a69444f0sm2595579137.7.2026.01.18.07.23.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Jan 2026 07:23:18 -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: Sun, 18 Jan 2026 10:23:10 -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 v3 4/7] iio: core: Add cleanup.h support for iio_device_claim_*() X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260106-lock-impr-v3-0-1db909b192c0@gmail.com> <20260106-lock-impr-v3-4-1db909b192c0@gmail.com> <27cf1ec1-545b-4e44-8229-852f8bdae116@baylibre.com> In-Reply-To: <27cf1ec1-545b-4e44-8229-852f8bdae116@baylibre.com> On Fri Jan 16, 2026 at 5:03 PM -05, David Lechner wrote: > On 1/6/26 2:06 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 >> Signed-off-by: Kurt Borja >> --- >> include/linux/iio/iio.h | 71 ++++++++++++++++++++++++++++++++++++++++++= +++++++ >> 1 file changed, 71 insertions(+) >>=20 >> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h >> index d8af0456f966..c795f731f2d8 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,76 @@ 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= llow 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 direc= t mode >> + * lock with automatic releas= e > > I don't think it is usual to put the function parameters in the > doc comment like this. They don't match the actual names anyway. Hi David, This format of kernel-doc applies to function-like macros too [1]. I'll match the name of the variables though. > >> + * @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:: >> + * >> + * IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); >> + * if (IIO_DEV_ACQUIRE_FAILED(&claim)) >> + * return -EBUSY; >> + * >> + * ...or a more common scenario (notice scope the 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 >> + * @claim_ptr: Pointer to the claim variable passed to IIO_DEV_ACQUIRE_= *_MODE() >> + * >> + * Return: true if acquired the mode failed, otherwise false. >> + */ >> +#define IIO_DEV_ACQUIRE_FAILED(claim_ptr) \ >> + ACQUIRE_ERR(__priv__iio_dev_mode_lock_try_direct, claim_ptr) >> + > > If we always have to add the & at the call site, could we just > put that in the macro instead? Then the parameter would just be > claim instead of claim_ptr. I'll add this in the next revision. [1] https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentatio= n --=20 Thanks, ~ Kurt