From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 4BAB3334694 for ; Wed, 3 Dec 2025 19:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764789586; cv=none; b=WNXHN5eGjWdOniTUJ1SWNbX62tHy7CRq3ompE2tG/x7prwNoYeTUm4/RlDiYCgJ1wbTaJvLFrTXQBiSZYBEwR/NGc3lvdci5e5G2pabqAb/xFgenmNYtam6bgEEy+FloVA6yLFjrN7CkRNVyooyqUEI0FO0lFKSWbIhmX2swNso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764789586; c=relaxed/simple; bh=thwTqOzNRZkyszvhlMWjaq5EQB1WFkW17ri6c2K6Wec=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GreEYJ8fEmqJB4TDe7BU9J2iVircrjIpCpy1r5hT9C1L3YHNmC4DLfcm22v1IcFtmeNckp6t7jJqkZ8gs4p/UNLIcKYYknX+KvXtF+1UB5a+jft1x0Fyz2RNC3EccSI3U1ygXie/8C6WVYFnuxzwmp10KNcFrgkXVCxOcmUwYAg= 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=mCAtExXD; arc=none smtp.client-ip=209.85.221.180 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="mCAtExXD" Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-55b26461e78so33348e0c.3 for ; Wed, 03 Dec 2025 11:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764789583; x=1765394383; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=t+56Cx3PPU0pMNBTK6bCqPThZjyXJm4dzoboS+vzlFA=; b=mCAtExXDSsseqQkMWWJffdov3Jj1xg98uSzIUpmq/ob5Ste9uDnuIOeJTq9L3x6zKL t2Cez+eWRx3G/ngl8IVzvB6phDNkrQpA3LALQlx6aVVK+Q/vd+FRA0L9BHw+ksGWoJfj P88ICxXGOav568X8xoym0IrQpE18jFbGpuracT76+NsUduv+dZx3Bl84fKAGeHoPwBKS g6HkZlYUkOeRIS5D7QYUCGpBVumerp/kkWHKvW+1qIov1xLruF1KHkptH31UmTIl4eGs PHjbWPPS9XnFL1WYAlUmJjgu7lxz/KJx++gGpt/Yir9zSqOiyPER4eZpcFPJAyxfv85I Nacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764789583; x=1765394383; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=t+56Cx3PPU0pMNBTK6bCqPThZjyXJm4dzoboS+vzlFA=; b=HVWykIDyITEpCDuByhuMh1HsmXZPe5NqiWumndWlYbs/BdnfgKp8owRNYTpWYu6l/x uZUz9VK2ZYv4NslsmBVttn6WMsC0a0ixLk100IjkhBWXWnLYNBiMuiRdSvG0WnxhqZUx Tkh5dPqlXmxXRQEJJQznnyXeH9QW+R3ifTPYvDtllBHKQF7RtputteARgLtPvoRnERJC YvuABnW48md0tDYFiv7qHFph6FV+uB36nKjGZMBQtWh9EPRtktzTgxxiJw6ynOsqb9dq q7U1EtmScHBpM6GMIFFqaxrirJm/1NYIX6rDGnsvZQE8wr2aiwHT6fD757hidsa0+fSE a2RQ== X-Forwarded-Encrypted: i=1; AJvYcCWCxWOr8xrLSLDCrQWa9nmPp7UqolBNOrTiimFPaBUm+xphpXw9GPVggI4ALti7xzjnSE1YvCiOLHha8j+Rf8o=@lists.linux.dev X-Gm-Message-State: AOJu0Yx0ihXmnAir8IoCjUqwQbZQNGfYrZWYhwhFMyuyfel/usOHndnx JoCzIOQPEmEVgJRJB5ZdkLr0hSGqq7NaNjvDFYRiPNB6Ti+TyBtUDlED X-Gm-Gg: ASbGncsI+aslIBPS9FQWUOL7Afo/HFAHdKXSmiaBEGgrhLQsEo+8r2USeJ1+Vvubp37 tNESbXBrccGXhTxVZktsCKZqOk/dWq1RsGTBxqKSZ18iMFjHAMus6ZDDUdvc4hzu5Cf5UiD8xM+ OIBGBHme6dwR0E0Jz/jrrg2EeMoTGlp8Sd/9PMstQWFH9zWWS7bv77ONWp7k5j1Sy8m44djQD7D w2feFMEXEvXGd9HLdCLea9wl+eHE0QclQ53TUhtHdLM5fhYzmixVqXPJKWAeeXkWj4Xv2aBmc9H FJh4vDvWHUEJDofKqkIutxFwU9bnDZ5sm4wFS7OgBabdWkUfRPkBn1fsIugAEYBOOgOUVskYnAj yCRx83HKJJ/TMcvdIn7/VsS7sqzYsJqBefmdwPK9o8Q46ECOj/caDHcrfK5PpL0eoSWAZWhRYcu m5hemyJxsboLBj X-Google-Smtp-Source: AGHT+IF9pu1NwTmjdGn8DFeer46ehoguwJV+JygngR29KNUZyGSjHLZ4RhNSUqDCM7LAEFNIdyXKyA== X-Received: by 2002:a05:6122:2a53:b0:55b:9c1c:85f2 with SMTP id 71dfb90a1353d-55e5beb9cf8mr1482400e0c.1.1764789582987; Wed, 03 Dec 2025 11:19:42 -0800 (PST) Received: from [192.168.100.70] ([2800:bf0:82:3d2:875c:6c76:e06b:3095]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-55cf4e1d56asm8121346e0c.4.2025.12.03.11.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Dec 2025 11:19:42 -0800 (PST) From: Kurt Borja Date: Wed, 03 Dec 2025 14:18:17 -0500 Subject: [PATCH RFC 3/6] iio: core: Add cleanup.h support for iio_device_claim_*() Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251203-lock-impr-v1-3-b4a1fd639423@gmail.com> References: <20251203-lock-impr-v1-0-b4a1fd639423@gmail.com> In-Reply-To: <20251203-lock-impr-v1-0-b4a1fd639423@gmail.com> To: 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 , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Kurt Borja X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3155; i=kuurtb@gmail.com; h=from:subject:message-id; bh=thwTqOzNRZkyszvhlMWjaq5EQB1WFkW17ri6c2K6Wec=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJkGva4eG14sOFYksZvzvrHpBSYR7dYvj1f3lu2YMu9Fi /eyLGbbjlIWBjEuBlkxRZb2hEXfHkXlvfU7EHofZg4rE8gQBi5OAZjIgg6Gv/L3I60Fp6u0OM5J cxFWOHy/M+zN4uao9uhu/2YbjWctvQx/pXSPXko79vm9287F99e1PBbnfhT/oldqc/aSI7J7JK7 s5AIA X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Add guard() and ACQUIRE() support for iio_device_claim_*() lock. This involves exporting iio_device_{claim, release}() wrappers to define a general GUARD class, and then defining the _direct and _buffer conditional ones. Suggested-by: Andy Shevchenko Signed-off-by: Kurt Borja --- drivers/iio/industrialio-core.c | 12 ++++++++++++ include/linux/iio/iio.h | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index adf0142d0300..da090c993fe8 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2171,6 +2171,18 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, } EXPORT_SYMBOL_GPL(__devm_iio_device_register); +void __iio_device_claim(struct iio_dev *indio_dev) +{ + mutex_lock(&to_iio_dev_opaque(indio_dev)->mlock); +} +EXPORT_SYMBOL_GPL(__iio_device_claim); + +void __iio_device_release(struct iio_dev *indio_dev) +{ + mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); +} +EXPORT_SYMBOL_GPL(__iio_device_release); + /** * __iio_device_claim_direct - Keep device in direct mode * @indio_dev: the iio_dev associated with the device diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 27da9af67c47..472b13ec28d3 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -661,9 +662,23 @@ void iio_device_unregister(struct iio_dev *indio_dev); int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, struct module *this_mod); int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); +void __iio_device_claim(struct iio_dev *indio_dev); +void __iio_device_release(struct iio_dev *indio_dev); bool __iio_device_claim_direct(struct iio_dev *indio_dev); void __iio_device_release_direct(struct iio_dev *indio_dev); +static inline void iio_device_claim(struct iio_dev *indio_dev) + __acquires(indio_dev) +{ + __iio_device_claim(indio_dev); +} + +static inline void iio_device_release(struct iio_dev *indio_dev) + __releases(indio_dev) +{ + __iio_device_release(indio_dev); +} + /* * Helper functions that allow claim and release of direct mode * in a fashion that doesn't generate many false positives from sparse. @@ -690,6 +705,11 @@ static inline void iio_device_release_direct(struct iio_dev *indio_dev) bool iio_device_claim_buffer(struct iio_dev *indio_dev); void iio_device_release_buffer(struct iio_dev *indio_dev); +DEFINE_GUARD(iio_device_claim, struct iio_dev *, iio_device_claim(_T), + iio_device_release(_T)); +DEFINE_GUARD_COND(iio_device_claim, _buffer, iio_device_claim_buffer(_T)); +DEFINE_GUARD_COND(iio_device_claim, _direct, iio_device_claim_direct(_T)); + extern const struct bus_type iio_bus_type; /** -- 2.52.0