From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) (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 4079650094E for ; Sun, 18 Jan 2026 15:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768749561; cv=none; b=G+T8ksO1VfMBVN8mksZDE5YX/jZYiResLV5lcEj46EyjLHB/sAncwiidskppHB6LcFjzH6/UJH9eSd0xdxBCFHR60MwpWmdMI6N14/CSjAHTGPHX4jX4DCTd5Tsgh5gHDhLdf1yZIoHsNXOjNHuKk4sHft8ZVG1EIQfxUHuBhVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768749561; c=relaxed/simple; bh=g06A1tXDMolKKapiyzUzcHhUdjAZvYx4RznKjM44peE=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Cc:Subject: References:In-Reply-To; b=spk28oJKQIJN4rdH9TWF2g+Ctu4qjUqIw70Qh+A2hBj4zgm/RhzFNj8g8iT3wvOn3hYw134nLFkjce2OguUzI9TmiLKW9sRcD3aiBV5YwU0okzmKI2U79LprQPbQu3q9j+Q8vaCpgFgGGegGTBDKIlzQ+JNSTDQJvLB4WLrpJcY= 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=AFJFGqCE; arc=none smtp.client-ip=209.85.221.173 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="AFJFGqCE" Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-563610de035so2856490e0c.0 for ; Sun, 18 Jan 2026 07:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768749558; x=1769354358; darn=lists.linux.dev; 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=BOUvpplcT3urd/iksfVnrJu08Fkv1KRGqxSkXimkTS8=; b=AFJFGqCE6dw6T8eVb3VdqluaEqdA+uBnema32cjmJLQ6b8a3vg7gPQ78s+eujxOTLl FhufZkLb1nU0ao9O5gGeRxFSkQXjfz+jniVCSiK88pm4g73Ub6TDwx/iCk40fdaKygux ME6LVGHN/31J5s16a31bIjU3IGKwx7nWfa/pE0GNeQhcsUF+QjOFR6SX6Ta00NGVAWID 35UfFsqmC/JSubdFeRu2qbtCt3Mgv5ka/4aofEiLRRD7bChWbxDkT5/QYVvw7nlLtgkg d42KfbQA6KwQVZrDuGkcTZDQW/QC1z2rhrvaZ8+m7v0vFScdiRRSRxa9nZwQUD1jGTc8 OyVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768749558; x=1769354358; 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=BOUvpplcT3urd/iksfVnrJu08Fkv1KRGqxSkXimkTS8=; b=m6A/cmDMwgf83i+YP4kckceheFQ+QiWbw0quUVK5KsQEm24j11f7sywwOifU6gk0KM gDr52T86PVMERF34X2v9/mPt9vZRuededGMLuprfmXgoc+FWh4gMRC9m6wW+5KoA9syY iqrCFXMZ1fjmSLk+T9dJ0rZekqYBtWaKc+EQ5uLwepw+IXsuFcaBFBQMfAsilYIJgkaS YW3p2tKmGHLEstkAL5E9V3A0XqzuaNzmpZHoAfVFMlrG4W3ZkhL3+CpETddjE2Sk9EKh GQGJtg8hFIgyM9FU3kewXB9yedwar5QiCrVPBPbDwFK5wAg6WaDPaPArA1eh7AcfOvwN gH5w== X-Forwarded-Encrypted: i=1; AJvYcCXQnUDxyEzmIvcFamRXGTGKAK7GbBWS4UKHaDbLtoK5KGldneo43GjOoBmwBRAMG7RtyoccCupplJHauNi5Rno=@lists.linux.dev X-Gm-Message-State: AOJu0Yw+Brn33ibFa3w/v2dwV1Cya222aWqE6vTuYl8rSjekuvCkoxC8 NW1Ys4Fw40AhyFWflMFx0CONJRKkAbwWSaa2i2X2EMXc8573arp4VJSH X-Gm-Gg: AY/fxX6CE+4/pWVsQ7SJ9YU0eMpH/PWdMgB0YiM2JvuP5I6yO+9TNzpdxENm9XBR6Y6 99whDUZ4N/EIeNztdQsQ0hiPp0liG6on3uqJlbu22ZyZyr4E7KEC/DkjYfaC4/Q9cSefiFJoSpb Icv2HRiYKSef0RzoDb+6L6hDYbrhD5C9FZHx7nGh6dBZUhxh+On3mXKTc+6ujtNtszjVtgrt55p PwHvGtxIpP357vztRT1WKl990cOfd/vpNchbUIBP+vEnk520W2mnOCNY7jugdS30YDTMvyZ9ssz 2oZXKEHCpge8GG86fw8jslpuAG01wCc0sAjgdYkLOUYUUUgyjyEFZ4hYmpcVZAWsT5vuxju6zDo ESvDJUfyVUtolAynYIU57Areei8t9xEdDOpqijbsCURYwHKiZWj6kOSs5DhqlLiig0aG25guPkh oo/B3WTlnmZhlq X-Received: by 2002:a05:6122:3c92:b0:563:7062:2a75 with SMTP id 71dfb90a1353d-563b5be1d20mr2679439e0c.8.1768749558189; Sun, 18 Jan 2026 07:19:18 -0800 (PST) Received: from localhost ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-563b6fdb023sm2154628e0c.3.2026.01.18.07.19.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Jan 2026 07:19:17 -0800 (PST) Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev 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:19:09 -0500 Message-Id: From: "Kurt Borja" To: =?utf-8?q?Nuno_S=C3=A1?= , "Kurt Borja" , "Andy Shevchenko" , "Lars-Peter Clausen" , "Michael Hennerich" , "Jonathan Cameron" , "Benson Leung" , "Antoniu Miclaus" , "Gwendal Grignou" , "Shrikant Raskar" , "Per-Daniel Olsson" Cc: "David Lechner" , =?utf-8?q?Nuno_S=C3=A1?= , "Andy Shevchenko" , "Guenter Roeck" , "Jonathan Cameron" , , , Subject: Re: [PATCH v3 0/7] iio: core: Introduce cleanup.h support for mode locks X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260106-lock-impr-v3-0-1db909b192c0@gmail.com> <363f81bfe996de839a43e9f6a355ed014cd3de8a.camel@gmail.com> In-Reply-To: <363f81bfe996de839a43e9f6a355ed014cd3de8a.camel@gmail.com> On Sun Jan 18, 2026 at 5:00 AM -05, Nuno S=C3=A1 wrote: > On Tue, 2026-01-06 at 03:06 -0500, Kurt Borja wrote: >> Hi, >>=20 >> In a recent driver review discussion [1], Andy Shevchenko suggested we >> add cleanup.h support for the lock API: >>=20 >> iio_device_claim_{direct,buffer_mode}(). >>=20 >> Which would allow some nice code simplification in many places. Some >> examples are given as patches, but the last two are the biggest >> differences. >>=20 >> In this version I dropped the RFC tag, as the general feeling is to go >> through with this after some modifications. Main one is the addition of >> IIO_DEV_ACQUIRE_{BUFFER,CLAIM}_MODE() wrappers to avoid drivers using >> the guard classes directly. I also added comments on the forbidden ways >> to use this API but I definitely still take suggestions on this. >>=20 >> For now I dropped iio_device_claim_buffer_mode() rename, as this point >> is still being discussed. My suggestion based on the RFC discussion is >> to do it, but in a separate patch (using coccinelle) and while we're at >> it rename the whole API like this: >>=20 >> iio_dev_mode_lock() >> iio_dev_mode_direct_trylock() >> iio_dev_mode_buffer_trylock() >> iio_dev_mode_unlock() >>=20 >> Let me know what you think and thanks for taking a look! >>=20 >> Signed-off-by: Kurt Borja >> --- >> v3: >>=20 >> =C2=A0 - Reword commit message of patch 1: infallible -> unconditional. >>=20 >> =C2=A0 - Drop "*strongly*" in __iio_dev_mode_lock() kernel-doc and be a = bit >> =C2=A0=C2=A0=C2=A0 more clear on the function's intention. >>=20 >> =C2=A0 - Keep comment about inline functions and sparse markings, but dr= op >> =C2=A0=C2=A0=C2=A0 the __cond_acquires() part, as the new implementation= makes it >> =C2=A0=C2=A0=C2=A0 unnecessary. >>=20 >> =C2=A0 - Implement iio_device_release_*() as macros around >> =C2=A0=C2=A0=C2=A0 __iio_dev_mode_unlock(). >>=20 >> =C2=A0 - Rename iio_device_claim_buffer_mode() -> >> =C2=A0=C2=A0=C2=A0 iio_device_try_claim_buffer_mode() to avoid silently = breaking >> =C2=A0=C2=A0=C2=A0 out-of-tree drivers. >>=20 >> =C2=A0 - Drop the `_` argument prefix in new macros, as there are no nam= e >> =C2=A0=C2=A0=C2=A0 conflicts. >>=20 >> =C2=A0 - Drop "dummy" from IIO_DEV_ACQUIRE_DIRECT_MODE kernel-doc, as th= e >> =C2=A0=C2=A0=C2=A0 `claim` variable does store the error value. >>=20 >> =C2=A0 - Drop IIO_DEV_ACQUIRE_BUFFER_MODE() until a driver actually need= s it. >>=20 >> =C2=A0 - Rename IIO_DEV_ACQUIRE_ERR() -> IIO_DEV_ACQUIRE_FAILED() to mak= e the >> =C2=A0=C2=A0=C2=A0 name more clear. >>=20 >> =C2=A0 - Rename IIO_DEV_GUARD_ANY_MODE() -> IIO_DEV_GUARD_CURRENT_MODE()= to >> =C2=A0=C2=A0=C2=A0 make the name more clear. >>=20 >> =C2=A0 - Add missing . in iio_device_release_direct() kernel-doc. >>=20 >> =C2=A0 NOTE: Andy suggested __iio_dev_mode_*() be exported into the IIO_= CORE >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 namespace. However, this cann= ot be done because these functions >> need to be called inline, so Sparse can see the __acquires() and >> __releases() tags. >>=20 >> =C2=A0 Happy new year to everyone :) >>=20 >> v2: https://lore.kernel.org/r/20251211-lock-impr-v2-0-6fb47bdaaf24@gmail= .com >>=20 >> =C2=A0 - Add __iio_dev_mode_lock() (formerly iio_device_claim()) in the = first >> =C2=A0=C2=A0=C2=A0 patch. >>=20 >> =C2=A0 - Added comments to make sure __iio_dev_mode_lock() is not used b= y >> =C2=A0=C2=A0=C2=A0 drivers to protect internal state, or in general. >>=20 >> =C2=A0 - Add patch which re-implements iio_device_claim_direct() using >> =C2=A0=C2=A0=C2=A0 __iio_dev_mode_lock(). >>=20 >> =C2=A0 - Match iio_device_claim_buffer_mode() semantics by reimplementin= g it >> =C2=A0=C2=A0=C2=A0 in the same way as iio_device_claim_direct(). >>=20 >> =C2=A0 - Guard classes now are prefixed with __priv__ to make sure drive= rs >> =C2=A0=C2=A0=C2=A0 don't use them directly. >>=20 >> =C2=A0 - Add IIO_DEV_ACQUIRE_{BUFFER,DIRECT}_MODE() documented wrappers >>=20 >> =C2=A0 - Avoid any function renames (for now). >>=20 >> =C2=A0 - Rename dummy variable `claim` instead of `busy` on vcnl4000 pat= ch. >>=20 >> =C2=A0 - Avoid scoped guard in max30102. >>=20 >> =C2=A0 - Keep using iio_trigger_validate_own_device() insted of >> =C2=A0=C2=A0=C2=A0 iio_trigger_using_own() in opt4060. >>=20 >> v1: https://lore.kernel.org/r/20251203-lock-impr-v1-0-b4a1fd639423@gmail= .com >>=20 >> --- >> Kurt Borja (7): >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: core: Add and export __iio_dev_mode_= lock() >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: core: Refactor iio_device_claim_dire= ct() implementation >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: core: Match iio_device_claim_*() sem= antics and implementation >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: core: Add cleanup.h support for iio_= device_claim_*() >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: light: vcnl4000: Use IIO cleanup hel= pers >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: health: max30102: Use IIO cleanup he= lpers >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 iio: light: opt4060: Use IIO cleanup help= ers >>=20 >> =C2=A0drivers/iio/adc/ade9000.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 2 +- >> =C2=A0.../common/cros_ec_sensors/cros_ec_sensors_core.c=C2=A0 |=C2=A0=C2= =A0 5 +- >> =C2=A0drivers/iio/health/max30100.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0=C2=A0 8 +- >> =C2=A0drivers/iio/health/max30102.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0 33 ++--- >> =C2=A0drivers/iio/industrialio-core.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 |=C2=A0 86 +++--------- >> =C2=A0drivers/iio/light/opt4060.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 52 +++----- >> =C2=A0drivers/iio/light/vcnl4000.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0 49 +++---- >> =C2=A0include/linux/iio/iio.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 145 +++++++++++++++++++-- >> =C2=A08 files changed, 196 insertions(+), 184 deletions(-) >> --- >> base-commit: fb2f4eb29a258145b0336601f00509cab6e93e7c >> change-id: 20251130-lock-impr-6f22748c15e8 > > Nothing to add from me... > > Reviewed-by: Nuno S=C3=A1 Thank you for your feedback, Nuno! --=20 Thanks, ~ Kurt