From nobody Sat Feb 7 17:41:05 2026 Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (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 E580736C59E for ; Tue, 20 Jan 2026 06:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890075; cv=none; b=SRfK3Dv91TztoJ2d2+m9WUe1bL9uIdTAUE3HxS/ZF88B8I0zylTigHovb9G4IUfmXaRJjOmzAibW8CWFVsGEUdWaQnt2b93y5/u5iMgieOOPz3XvXfMw3AYiEnQCrIkybeIw+S3DpODXlyS0Ta5moKBmIIT6Jhb8Cxg9wpjC8uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890075; c=relaxed/simple; bh=Tc5/3NT6AVqhl2DjZzJv2Sn4xFJDlerjPios4AAER84=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZgUqBI5I2EZHfjrVfLAQlm7Vq6z/dfrsRunxqLX1AfZWCeCbyaIvXsB+Hl7ibsMym92JE2d9DIaO2Y/YvpImsd5UHbAk0gEcNhMcECEgRpMGrXEUIfZgFV5pxloXnKp2qh7o+RJEeWxTJxE4OamKcHQzJgpyQ1XujdR7M1g0+p4= 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=GTaoP8+4; arc=none smtp.client-ip=209.85.217.42 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="GTaoP8+4" Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-5eeff7e8bb3so3400645137.1 for ; Mon, 19 Jan 2026 22:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890073; x=1769494873; darn=vger.kernel.org; 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=awxt+DDD9i1Z2I3KP5u44VA06ZhetlDbI4UFSh79c8k=; b=GTaoP8+4IhTadtwK6Z2nJXtXYsn0s8u12Rn1G40dWtT3nOSr0NAUilCIBvyBNljsnf G8sdtqBH/wmTUu8yaAT2uK+IN+ntfkjIOuY0Ld+LPKCbH2WxhxfyyAJquFHdlk0xue2G OZwQ1AzZSgyGag7pALRzdglba96ul+2KhSiQGo7xmw8HpD26gVrx5blMWcWd+9vQiFXf Xxmy5GYsmKYkVS3TX3CLN+HPt7kkICO12kNycNNuBT2pH9a6udSqiqzJoenv3G4QHFuH +Ow+Vbq06CvE4nFC9Gd2o8ga+OK4skz1Go1/xwEnyncSG0hdJmA3GLbBQUFfS582hXd/ 5xwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890073; x=1769494873; 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=awxt+DDD9i1Z2I3KP5u44VA06ZhetlDbI4UFSh79c8k=; b=BFmxCkDEDHlhhBwkxalds/1fhntP3aLVJ15DeFG0T1fz/GIlXByi42cj0VeaIUv5NB aLysrN9fNHb48g64MybueWcHs/hkQzR2vO7UTaaHng9hZ1wR49ohbRvfCZhbA9NQksHZ PNngfBmpnCCHqBrod8idSquuua3ih0nNCG+VZSccNaxz7BP+LRFxSil2wXQfSeYFq35c +XIo+bbYTvVqvHrsF4NvK6SJjIYP3Bu7tvpk3fwPxC9Xr6rqFWR8xi72A7p7GgwiY5FP a+yGnKK3kyJnP6XWyFyTLkP+hlPmYyIgEK+tDQTGsRVMYar1J+iyFo0thQ/FfVWqyBR8 EYsA== X-Forwarded-Encrypted: i=1; AJvYcCVvvMCR001/WuAqScuTKYYaAn2CElzwVDLKq3WJ2nMd7MDuFBnFKqyZ2jlFKWCK7ThvpUJQcYCO+rTN/7U=@vger.kernel.org X-Gm-Message-State: AOJu0YypGx4Xqhcj9PPrdlYhK4aHU4IJMINgB6azlZZgKI7ZjEPI4l6M bf6bTQgIGxPqo36R7qtXBoPNd7vD6mIufo7aTL9sYtRKn+p547tqSGQB X-Gm-Gg: AZuq6aLaZcVcDwm/k9yyGIr8DwkOdxqVevZPsG/Pp9S1Ybn56Lq8z1ggOfIz+aCCDki c+XhAMAU3IcByz0S0VZ0U1p4+y2bPD0WfoAopHvZYvdiqjt+YXapjv6B5pu/Dcl1GmX5z06aXuw dSUedvRIlHBGK/ZvtgvlNpqpeMf/0uQfaVLioF3vihheG7LTezx4CWc63cQzKOPUNrWUCL/dtzm t3fAFvrVGNqpLbGwads/2AUm2HcUtbNJI2qlx1R3MfX4UxBPWq+LnhOF+1vet96TgYmFsfQtkeX eKQBIKxXPRiruQM6RzKXVf8VTH7w4+SsOaXvOhi+Ecs9I7ND7WjzpPptK+xiw6eu5hJMhl8oamR BNphteodjDY+1yfNlfHPyCVFLK8mtBY7gvxKZvbFP8mRuVtw5qUiki68T0ta/QmHDPLT7CeK4e7 3BTJiHeWtz8vaAo/xYLuHFkY0= X-Received: by 2002:a05:6102:3907:b0:5df:bb10:6334 with SMTP id ada2fe7eead31-5f50aa7f38emr239664137.39.1768890072897; Mon, 19 Jan 2026 22:21:12 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:12 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:41 -0500 Subject: [PATCH v5 1/7] iio: core: Add and export __iio_dev_mode_lock() 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: quoted-printable Message-Id: <20260120-lock-impr-v5-1-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=2878; i=kuurtb@gmail.com; h=from:subject:message-id; bh=Tc5/3NT6AVqhl2DjZzJv2Sn4xFJDlerjPios4AAER84=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpd37ymcE5MvdiLlS5ro7VTG8AX9gdpToh6cz+6Z/ KxHf+mmjlIWBjEuBlkxRZb2hEXfHkXlvfU7EHofZg4rE8gQBi5OAZhI0gNGhq3ckxtdHLa7+G8I cTm6hz1GQVN1rXR06HtRDoMf3zz7shj+57ZOjdJUbFh+n7ni3ORULgb2G5XJWkZ/Fj0/5r33mbc eOwA= X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Add unconditional wrappers around the internal IIO mode lock. As mentioned in the documentation, this is not meant to be used by drivers, instead this will aid in the eventual addition of cleanup classes around conditional locks. Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/industrialio-core.c | 30 ++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index f69deefcfb6f..db803267df6e 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2171,6 +2171,36 @@ int __devm_iio_device_register(struct device *dev, s= truct iio_dev *indio_dev, } EXPORT_SYMBOL_GPL(__devm_iio_device_register); =20 +/** + * __iio_dev_mode_lock() - Locks the current IIO device mode + * @indio_dev: the iio_dev associated with the device + * + * If the device is either in direct or buffer mode, it's guaranteed to st= ay + * that way until __iio_dev_mode_unlock() is called. + * + * This function is not meant to be used directly by drivers to protect in= ternal + * state; a driver should have it's own mechanisms for that matter. + * + * There are very few cases where a driver actually needs to lock the curr= ent + * mode unconditionally. It's recommended to use iio_device_claim_direct()= or + * iio_device_claim_buffer_mode() pairs or related helpers instead. + */ +void __iio_dev_mode_lock(struct iio_dev *indio_dev) +{ + mutex_lock(&to_iio_dev_opaque(indio_dev)->mlock); +} +EXPORT_SYMBOL_GPL(__iio_dev_mode_lock); + +/** + * __iio_dev_mode_unlock() - Unlocks the current IIO device mode + * @indio_dev: the iio_dev associated with the device + */ +void __iio_dev_mode_unlock(struct iio_dev *indio_dev) +{ + mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); +} +EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); + /** * __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 872ebdf0dd77..aecda887d833 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -661,6 +661,9 @@ void iio_device_unregister(struct iio_dev *indio_dev); int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_d= ev, struct module *this_mod); int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); + +void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); +void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev= ); bool __iio_device_claim_direct(struct iio_dev *indio_dev); void __iio_device_release_direct(struct iio_dev *indio_dev); =20 --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (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 6A5E8374178 for ; Tue, 20 Jan 2026 06:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890078; cv=none; b=kNzfAuHkyYlQSTI29KZyGqM8riED8jFUQVaOMmhsipD28R3qbOOSrf6Vzyjy4mBR+KAMrS0Oj+Ye4Ra/obpnSHdLK0354WwQGxY3n1EwiPEw1gkuxHoduW4PWOIS051C2XYQES8YFbWlY61hjqYc3PDu+xa2KsK+3j1wf2gLDQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890078; c=relaxed/simple; bh=vf6b08yM9ZBa2hmugn0zaME77U5lLecJX0FGGC0bIPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RuK+JLRUwUEeEsWukv/Rj9xJ4RSQzRFnSEIENSmGivOtJXd/fcZ0564uvzokIcVoLwXKN+QZf1cMq1njK+RXBK3ZO5IT34p8kzewtK0RYiwgz3nx1FO8HP//sUK4FYhYbwJ1+yqqS7yNX2lm3d/JsnNRuYjLJcZpxhVvjidFuMw= 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=WsZOHxUh; arc=none smtp.client-ip=209.85.221.171 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="WsZOHxUh" Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-563686df549so3934867e0c.1 for ; Mon, 19 Jan 2026 22:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890075; x=1769494875; darn=vger.kernel.org; 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=UKZCOUdlyM96S2jf/HyAYyFcxZYAitp5mesgIJsfK4E=; b=WsZOHxUhnXFH2GwCloPOTOSdNG2QYdQB7NzZOt5fJpnvA3Jy4BmYcPIm5nhCzdqUPx sfmD6LZitwZccev2CJZEKtxee+MJLiD6CxPXoBuosl3dsiozzpI2z7JKxunMETxoJN4V yQsHPs5LmiUlZRP1pHlSjpyh6YZvtb8Gq7BluhSqknA7Xgq9mVjLQVQEsZWMmOW+9SbD r+nP/+aVBLO3yicSmG2I4btYEVQyh1QYvNMU4gFgOsL7TSXYurzpFTFntGtqTKVG9ixn rXVMr4h6MxalFzKy3mScxSHJ/e1R72PQhGZJuZ6F8a7XjpC944dxAsx5DalmD1p/QAPK lJ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890075; x=1769494875; 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=UKZCOUdlyM96S2jf/HyAYyFcxZYAitp5mesgIJsfK4E=; b=ayrBQZwzeQCN40vryFsTMeqT8Ga8j4gdmghD3XUvT/6dKOaPFLWi/8yvX9BVamJlN0 A8NIbRwti9jKRrJRTUAkV92rQh7UsiB+Y6WurQyerkS9gGWhSJsvPTrHgtmiGb5AGUvE jIu4+f0uSJr84C6l7IPozptIIMD7mh+lXm3vxhjpUxivv0gqafnqb03wGYMN766xIuvI 3ViKy7TEe8+ndTbgtJoJX8uFleNRkPPV5JLQZunGHG68e1IS3mPS8T6peB69gGyUACMO PPIQbZPWGizGMmQ22srkeC1fij9JiZxjlidj/lx/SWToAl0YJ999/PdTSuH5c3iv49n+ ORQA== X-Forwarded-Encrypted: i=1; AJvYcCUc2D6zn4kXGA7URibDlRiJQ90b/3qlLgtNjdsm/TZcl6eW0ZgkuBf4sJcQaMymyLJ6gmcHMUPz9kIEsmA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8UhfNKSJCxDugXLWWR3+Niru/DmMaGVUBCT1JrAeLc8LmzTfq J16l77IG6B0Lk2ZqNq7eUxFsqzwX+dLfOVRTrNMWgoYZ717qDt3SxwEF X-Gm-Gg: AZuq6aIcTq2YM0OsesFVsVs3S7E7VM5QbLGQZyW4an9KGNJj1ZPXCKZUdc+V+3vcFg+ QRr5XXGNW09dS9EO5TH2p2K1uKHKlesy+142q2RvaxJymz8gkRa5vj9FgJ1+ZsEBqy3fnRgqH26 FeR3o1098K1hM86U8QlVQOtND1XPg4wJG1A1QWeNVHzuCW+qsaKSrKZNNPppTiB/+rbvynO+hDP 4gRD3mXOc2DoKGH9S5tbPfn13FGWFcdYq5qJ626LcFF50qYr4FmUenLX9fkFc50K5zYJ7mtpiY2 zBATRSdpQOmdIul2/jlQNXq9SkKbnyiNEKymeWjjSVVUgiHyBDtqWoxK6b67+QfRo0vi0mgzJzX 7ld7VRnX9AdJb3UUyD62M/n2HweUJuM0dEdAP9v8nbykVFVkKdSTWbKQnI+7EcwtsikegqztXrB RFY2ugCTBLUv+S X-Received: by 2002:a05:6102:d8a:b0:5ef:a67d:e957 with SMTP id ada2fe7eead31-5f1a53b38c0mr4505673137.17.1768890075189; Mon, 19 Jan 2026 22:21:15 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:14 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:42 -0500 Subject: [PATCH v5 2/7] iio: core: Refactor iio_device_claim_direct() implementation 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: quoted-printable Message-Id: <20260120-lock-impr-v5-2-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=4538; i=kuurtb@gmail.com; h=from:subject:message-id; bh=vf6b08yM9ZBa2hmugn0zaME77U5lLecJX0FGGC0bIPo=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpf5LG6/EohJOP3nqa3Td73uF36+G0KMD15gvxJ8+ csh01lbO0pZGMS4GGTFFFnaExZ9exSV99bvQOh9mDmsTCBDGLg4BWAi91MYGe5Onsm47XqjXF9l xaefDEfazxfP+84wKevVtQmG/Ptq3kxj+MM5y0bhrKqgoPmVx/JSklkXvVvOczI0r3o+ce7yRwE /WBkB X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A In order to eventually unify the locking API, implement iio_device_claim_direct() fully inline, with the use of __iio_dev_mode_lock(), which takes care of sparse annotations. Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/industrialio-core.c | 44 -------------------------------------= ---- include/linux/iio/iio.h | 40 ++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index db803267df6e..0f8e3aa98b72 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2201,50 +2201,6 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) } EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); =20 -/** - * __iio_device_claim_direct - Keep device in direct mode - * @indio_dev: the iio_dev associated with the device - * - * If the device is in direct mode it is guaranteed to stay - * that way until __iio_device_release_direct() is called. - * - * Use with __iio_device_release_direct(). - * - * Drivers should only call iio_device_claim_direct(). - * - * Returns: true on success, false on failure. - */ -bool __iio_device_claim_direct(struct iio_dev *indio_dev) -{ - struct iio_dev_opaque *iio_dev_opaque =3D to_iio_dev_opaque(indio_dev); - - mutex_lock(&iio_dev_opaque->mlock); - - if (iio_buffer_enabled(indio_dev)) { - mutex_unlock(&iio_dev_opaque->mlock); - return false; - } - return true; -} -EXPORT_SYMBOL_GPL(__iio_device_claim_direct); - -/** - * __iio_device_release_direct - releases claim on direct mode - * @indio_dev: the iio_dev associated with the device - * - * Release the claim. Device is no longer guaranteed to stay - * in direct mode. - * - * Drivers should only call iio_device_release_direct(). - * - * Use with __iio_device_claim_direct() - */ -void __iio_device_release_direct(struct iio_dev *indio_dev) -{ - mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); -} -EXPORT_SYMBOL_GPL(__iio_device_release_direct); - /** * iio_device_claim_buffer_mode - Keep device in buffer 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 aecda887d833..e263ab5eeccf 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -664,31 +664,47 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_= code, s64 timestamp); =20 void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev= ); -bool __iio_device_claim_direct(struct iio_dev *indio_dev); -void __iio_device_release_direct(struct iio_dev *indio_dev); =20 /* * Helper functions that allow claim and release of direct mode * in a fashion that doesn't generate many false positives from sparse. * Note this must remain static inline in the header so that sparse - * can see the __acquire() marking. Revisit when sparse supports - * __cond_acquires() + * can see the __acquires() and __releases() annotations. + */ + +/** + * iio_device_claim_direct() - Keep device in direct mode + * @indio_dev: the iio_dev associated with the device + * + * If the device is in direct mode it is guaranteed to stay + * that way until iio_device_release_direct() is called. + * + * Use with iio_device_release_direct(). + * + * Returns: true on success, false on failure. */ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) { - if (!__iio_device_claim_direct(indio_dev)) - return false; + __iio_dev_mode_lock(indio_dev); =20 - __acquire(iio_dev); + if (iio_buffer_enabled(indio_dev)) { + __iio_dev_mode_unlock(indio_dev); + return false; + } =20 return true; } =20 -static inline void iio_device_release_direct(struct iio_dev *indio_dev) -{ - __iio_device_release_direct(indio_dev); - __release(indio_dev); -} +/** + * iio_device_release_direct() - Releases claim on direct mode + * @indio_dev: the iio_dev associated with the device + * + * Release the claim. Device is no longer guaranteed to stay + * in direct mode. + * + * Use with iio_device_claim_direct(). + */ +#define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_d= ev) =20 int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); void iio_device_release_buffer_mode(struct iio_dev *indio_dev); --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 C9B1F36E470 for ; Tue, 20 Jan 2026 06:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890081; cv=none; b=hHGvHM75NmCWv/TLcsr0H+TMOcNDIvb+e9cY0URCI0sc0j5QeQJjZWGU40OZvRfWEZXUr0NfC3MpGkUj8i3SzRKG3MTqwQlJhpHnBYGQnDn41031NGDgr8MKuXy3drJ7biEhEaaqLElpfJjPN9U16HRXhzMTHVFO3uMKfMLQ+E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890081; c=relaxed/simple; bh=JrWulgb5grSFMVK1z6odZB7wWOSYuUBdIJG44+bjR30=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tCOUZHOU6GsWwKhckw9TbbkRXQyFMxyIHo0Ifh3UCje1E/1Ze51BAr0A87p3oHwDzWdNvk8ow7ywVcMeHphuWrmEbHy4lOemP4PNODWNidj4sT5Xnmm854+JDtch9EDq2Nzs6dAspWG/QjuUgRU8obEx/2nDaloGbLTIuKw3HLI= 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=lbTaHZcG; arc=none smtp.client-ip=209.85.222.53 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="lbTaHZcG" Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-93a9f700a8cso1274316241.2 for ; Mon, 19 Jan 2026 22:21:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890078; x=1769494878; darn=vger.kernel.org; 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=NLMTng3flPO+eq1heKg9qmQSNnEZhgCKKq6nL/z8Gzc=; b=lbTaHZcGqpwjVCmsEuka2Wq/nJP1T/ppzvUgHmpavU0X2r9b5AK2degoxw8XvB3/jx xwIcB3KMFdekMU7VO2sXoZJr7gGh1OmbIDfXp8MM9KfLe4fRfC8o4VWDHUvycYoUOzpX E8iX+CdAoUaC05ORn4FMM+UnaEmkfYy7KrIGVyKSPUWTz5oRmPooaktQb8Vgg+wzhMF8 M5zb2T+rEwAyKZrW5+oa0HJ4oF1/bpFYlNKLcn9hxnEmZ+wh08JyzH2vOjZHch+pWfAP B2osWhKc2KzGYVol5Up2qFWEynViwF5t839ms12nNFnRZTo8yxJxdvqAhPOW/+qNWgXx lvTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890078; x=1769494878; 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=NLMTng3flPO+eq1heKg9qmQSNnEZhgCKKq6nL/z8Gzc=; b=sbbMOzkyNlvTAd5z39ylMR5S1HE0WnZuN6kSJLHOJTHKgF10M0/80ztWMl6LmN5HpK 8h7KKoI6F2n8l1dQMPvizuleUXzFAp2Hdc5y+5ryisC+CyW7+PHH2iRmgTX5owMCrE1a Krqf0YwbefpWoIqlK+4ubTlU9Y5+XrQcOVC0NhJvOSm2PV0rvRlmL5xaRBuhFbpLmjGX 6JeKgJGYh8kB1lJVhDrj8Vjnl870LhvsxdHJ4WRCJdfP3UpLxdxBC61jjSyVv9Gd+SFt mlZWSDrXz3h0TBPXQeFtPlr3LbD1oy7wY152vnENiFV7ZGaVF77lYm6JOBTZtZnlvuDz SZAw== X-Forwarded-Encrypted: i=1; AJvYcCWmdEtvax19RlabZc8bLgsxlXR4rpD74v7kKUBHxgiblrM2hOJ6wBdmZT1WJ0vYEHUoyPGA2eABU6nwCBE=@vger.kernel.org X-Gm-Message-State: AOJu0Yxeu+aUtlWvWJCJ7XC8+zZziM//Cf63ka09pxFyqdVZU/aopi6k /2OKF0TkOXbFLft9y9fawbrZsDtRoPZIBAnknF5I+QsPW3CTd3vRp09J X-Gm-Gg: AZuq6aLzlF9BDP6OLnS903TMUO4TlJPQYJcGXmO8IyUnFHcJKP5n2Xj2oYj7bbR/muc eXZF6YJx88/KiPh9+RUeQStoy1Z8y0bXNtzTYfg8vv0PEmbETtRI9IOKanyxWr+nFsX8WBrgyCt hT3cuecD5kUA+gIDBSJ40Ap9T06834fUk1Yfh6YebyK9bs9BsK4C9zfLX4gwMYSRJXa3eVc9yo9 sjZMVsd/FdGbjf6jf4DZQN/6wIKX+gL49UB9YQ7hBQPq7oHqcQeZE3GYa7JXBTledJFwjnFD+e7 G7zoONpoEAaQvp5K9ko6U7JxyWs4drdkZ4mx6cGJ9jxBiFcix1tc9dOZMxjBU4RAMF05Tx5JiPe 1RpKfya4WDlYGxmIYbRrwcmSW7ZuKuObTwtPF/1l9u5FE8buqjT5XprxFHH8LcopPwo3dnJPmmk QvwK5yTaQGaDT+ X-Received: by 2002:a05:6102:d92:b0:5ef:6709:4738 with SMTP id ada2fe7eead31-5f50ae44e0bmr212536137.30.1768890077616; Mon, 19 Jan 2026 22:21:17 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:17 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:43 -0500 Subject: [PATCH v5 3/7] iio: core: Match iio_device_claim_*() semantics and implementation 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: quoted-printable Message-Id: <20260120-lock-impr-v5-3-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=7973; i=kuurtb@gmail.com; h=from:subject:message-id; bh=JrWulgb5grSFMVK1z6odZB7wWOSYuUBdIJG44+bjR30=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpfPF6fGflh4ZLVF60+WZ0d2JFe53Lj1jWlKoURQz LpXv123dZSyMIhxMciKKbK0Jyz69igq763fgdD7MHNYmUCGMHBxCsBE/KMY/kqxM92esy1mUmah uxXHfyaLprqCRbEpS/13PkzU6VY+UcbI0Ho1fGXLnYMb30+9qVVv+G2iBUtwYGTh5v4uFwbHK/8 MWAA= X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Implement iio_device_claim_buffer_mode() fully inline with the use of __iio_dev_mode_lock(), which takes care of sparse annotations. To completely match iio_device_claim_direct() semantics, we need to also change iio_device_claim_buffer_mode() return semantics to usual true/false conditional lock semantics. Additionally, to avoid silently breaking out-of-tree drivers, rename iio_device_claim_buffer_mode() to iio_device_claim_try_buffer_mode(). Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/adc/ade9000.c | 2 +- .../common/cros_ec_sensors/cros_ec_sensors_core.c | 5 +-- drivers/iio/health/max30100.c | 8 +---- drivers/iio/health/max30102.c | 2 +- drivers/iio/industrialio-core.c | 42 +-----------------= ---- drivers/iio/light/opt4060.c | 2 +- include/linux/iio/iio.h | 35 ++++++++++++++++-- 7 files changed, 39 insertions(+), 57 deletions(-) diff --git a/drivers/iio/adc/ade9000.c b/drivers/iio/adc/ade9000.c index 2de8a718d62a..db085dc5e526 100644 --- a/drivers/iio/adc/ade9000.c +++ b/drivers/iio/adc/ade9000.c @@ -964,7 +964,7 @@ static irqreturn_t ade9000_dready_thread(int irq, void = *data) struct iio_dev *indio_dev =3D data; =20 /* Handle data ready interrupt from C4/EVENT/DREADY pin */ - if (!iio_device_claim_buffer_mode(indio_dev)) { + if (iio_device_try_claim_buffer_mode(indio_dev)) { ade9000_iio_push_buffer(indio_dev); iio_device_release_buffer_mode(indio_dev); } diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/dr= ivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c index 9ac80e4b7d75..ef53066b1735 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c @@ -188,11 +188,8 @@ int cros_ec_sensors_push_data(struct iio_dev *indio_de= v, /* * Ignore samples if the buffer is not set: it is needed if the ODR is * set but the buffer is not enabled yet. - * - * Note: iio_device_claim_buffer_mode() returns -EBUSY if the buffer - * is not enabled. */ - if (iio_device_claim_buffer_mode(indio_dev) < 0) + if (!iio_device_try_claim_buffer_mode(indio_dev)) return 0; =20 out =3D (s16 *)st->samples; diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c index 3d441013893c..7dfdb5eb305e 100644 --- a/drivers/iio/health/max30100.c +++ b/drivers/iio/health/max30100.c @@ -417,13 +417,7 @@ static int max30100_read_raw(struct iio_dev *indio_dev, * Temperature reading can only be acquired while engine * is running */ - if (iio_device_claim_buffer_mode(indio_dev)) { - /* - * Replacing -EBUSY or other error code - * returned by iio_device_claim_buffer_mode() - * because user space may rely on the current - * one. - */ + if (!iio_device_try_claim_buffer_mode(indio_dev)) { ret =3D -EAGAIN; } else { ret =3D max30100_get_temp(data, val); diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c index a48c0881a4c7..6918fcb5de2b 100644 --- a/drivers/iio/health/max30102.c +++ b/drivers/iio/health/max30102.c @@ -476,7 +476,7 @@ static int max30102_read_raw(struct iio_dev *indio_dev, * shutdown; leave shutdown briefly when buffer not running */ any_mode_retry: - if (iio_device_claim_buffer_mode(indio_dev)) { + if (!iio_device_try_claim_buffer_mode(indio_dev)) { /* * This one is a *bit* hacky. If we cannot claim buffer * mode, then try direct mode so that we make sure diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 0f8e3aa98b72..3115d59c1372 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -2183,7 +2183,7 @@ EXPORT_SYMBOL_GPL(__devm_iio_device_register); * * There are very few cases where a driver actually needs to lock the curr= ent * mode unconditionally. It's recommended to use iio_device_claim_direct()= or - * iio_device_claim_buffer_mode() pairs or related helpers instead. + * iio_device_try_claim_buffer_mode() pairs or related helpers instead. */ void __iio_dev_mode_lock(struct iio_dev *indio_dev) { @@ -2201,46 +2201,6 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) } EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); =20 -/** - * iio_device_claim_buffer_mode - Keep device in buffer mode - * @indio_dev: the iio_dev associated with the device - * - * If the device is in buffer mode it is guaranteed to stay - * that way until iio_device_release_buffer_mode() is called. - * - * Use with iio_device_release_buffer_mode(). - * - * Returns: 0 on success, -EBUSY on failure. - */ -int iio_device_claim_buffer_mode(struct iio_dev *indio_dev) -{ - struct iio_dev_opaque *iio_dev_opaque =3D to_iio_dev_opaque(indio_dev); - - mutex_lock(&iio_dev_opaque->mlock); - - if (iio_buffer_enabled(indio_dev)) - return 0; - - mutex_unlock(&iio_dev_opaque->mlock); - return -EBUSY; -} -EXPORT_SYMBOL_GPL(iio_device_claim_buffer_mode); - -/** - * iio_device_release_buffer_mode - releases claim on buffer mode - * @indio_dev: the iio_dev associated with the device - * - * Release the claim. Device is no longer guaranteed to stay - * in buffer mode. - * - * Use with iio_device_claim_buffer_mode(). - */ -void iio_device_release_buffer_mode(struct iio_dev *indio_dev) -{ - mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); -} -EXPORT_SYMBOL_GPL(iio_device_release_buffer_mode); - /** * iio_device_get_current_mode() - helper function providing read-only acc= ess to * the opaque @currentmode variable diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c index 981c704e7df5..8c4a1f562a83 100644 --- a/drivers/iio/light/opt4060.c +++ b/drivers/iio/light/opt4060.c @@ -304,7 +304,7 @@ static int opt4060_set_driver_state(struct iio_dev *ind= io_dev, struct opt4060_chip *chip =3D iio_priv(indio_dev); int ret =3D 0; any_mode_retry: - if (iio_device_claim_buffer_mode(indio_dev)) { + if (!iio_device_try_claim_buffer_mode(indio_dev)) { /* * This one is a *bit* hacky. If we cannot claim buffer mode, * then try direct mode so that we make sure things cannot diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index e263ab5eeccf..36bd14e93a75 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -706,8 +706,39 @@ static inline bool iio_device_claim_direct(struct iio_= dev *indio_dev) */ #define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_d= ev) =20 -int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); -void iio_device_release_buffer_mode(struct iio_dev *indio_dev); +/** + * iio_device_try_claim_buffer_mode() - Keep device in buffer mode + * @indio_dev: the iio_dev associated with the device + * + * If the device is in buffer mode it is guaranteed to stay + * that way until iio_device_release_buffer_mode() is called. + * + * Use with iio_device_release_buffer_mode(). + * + * Returns: true on success, false on failure. + */ +static inline bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_= dev) +{ + __iio_dev_mode_lock(indio_dev); + + if (!iio_buffer_enabled(indio_dev)) { + __iio_dev_mode_unlock(indio_dev); + return false; + } + + return true; +} + +/** + * iio_device_release_buffer_mode() - releases claim on buffer mode + * @indio_dev: the iio_dev associated with the device + * + * Release the claim. Device is no longer guaranteed to stay + * in buffer mode. + * + * Use with iio_device_try_claim_buffer_mode(). + */ +#define iio_device_release_buffer_mode(indio_dev) __iio_dev_mode_unlock(in= dio_dev) =20 extern const struct bus_type iio_bus_type; =20 --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 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 6AB3A36CDF8 for ; Tue, 20 Jan 2026 06:21:21 +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=1768890083; cv=none; b=DcvZw+yuf8qccRLcp/GPwOYw518wARKQqjskYfHdL60qbk5R3/jSe8lxs5E973q/0oIAuQ3W8fKDtq2yBknFtzQeZBCPS4nYlr4Pj48skNbr1aijJhXyYEk69ajYpvr6LZ+vBV80mBFnf3KnKt1F1fYarCzaqiZ5Y0u46Cz8pEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890083; c=relaxed/simple; bh=gk4uEOkebbeY+cZwYTy+/3fKoRkuSLvWkzrfvmHqOLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a+7IRz9rQKy4e8B54bKtdla59x+aB0CwD6QjtBGZAaBiQvZpJQAlJCh6YR/w9jDnei6yH4Cx80XThSYMB1HN+XS915VAGIhvKt9ifr7UgsfcMaXsbbrgmkPgo9QcFb8ah9B9iGmRU72zf2jPMyJ6/7u5HePkcWaC5YBFH/cpQ4o= 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=D7Y3FEH2; 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="D7Y3FEH2" Received: by mail-ua1-f44.google.com with SMTP id a1e0cc1a2514c-93f5905e698so1503755241.0 for ; Mon, 19 Jan 2026 22:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890080; x=1769494880; darn=vger.kernel.org; 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=ILl543DXo8pvw93JPMvlHELZN9bV6WaivIpMWAbJAoM=; b=D7Y3FEH2Oc7aXQcA+SAcaWUJs6lsWXG4IFcYPBrizcDTQKcUqu72Qp+tt7HRctOyux iHTy2h4dJFZXaXWGnQtR7SY8LXsd0qAwERiCCfoS5pXUHoo7SZVcXqCGdst1DbToZJNR dBPwdtY55nEP32L67UQAjg441RfNlxYKLoUF2csNlzDu0ILTyiMtnJTVe54q9lFqgx0p PEy4PI6aWe/PXOKYQrJt29yO/8s/ZjJ3yODNnEu1yrwN6qIzGYKI8cHrFraXdmjPDM4J GhmYx8EqKyt2sPFoEOdQKwO0Kcecdcr/AYMfCLjI6ILNtGA4pEUsmHId1rNxMCoGvktb Ek9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890080; x=1769494880; 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=ILl543DXo8pvw93JPMvlHELZN9bV6WaivIpMWAbJAoM=; b=F8het3mQkI57hYqqM6qnF262ixGNKEtTuYUNz6Y5L2u5+8rDvgqOUo1lDZWsrp5SZE 3SrpaGQjajPkKdmtm0XQps4J/JZd5REcgh//Diwm6dgdA/rv82kmyrK2rqJOCanbeb41 qV4gGlz/NHLg83FFknqdcaTVQ6H4HSWjxzi03YyQ6xCz4QrXVQHVzBwm0aVzLsHX+mnM AQKnfCn1AYihTWw7ukGbQM7QGAD9aAEop38vjuhKkyE+YO+1iId5QoN2knYhu3ssD4Cf JTUAeqSWp2AnfPzO+TUVDs+oB/fdUz1OlnAwNYN/3tZevTXZ5szItKtTzLT68+HXZu03 xYLg== X-Forwarded-Encrypted: i=1; AJvYcCW8jyK2hS6SESavigbWBD7idqFcP9yIvtVp1GOF6UUUH4kG1D2loxEN/HyPKnLXi++hYf2GnVmt6o907oo=@vger.kernel.org X-Gm-Message-State: AOJu0YyN7G6QblU47Rp8kAo/uNa1tIooYGOGbxqiPOpPIZ/D8VAxIpxC vtgJ+nl14wIbyp0Tau4lFzbd2FZ/2s9H3D1k7KasUY8GOz2aiN6e83wR X-Gm-Gg: AZuq6aJJAL56SP9wooYSrSSTDPyu/S8Rgp8NJ7qY6YtwW30OvjlY2MN5oahejGtaDLl yLiBDrLdHX1jvE7XckpO2NGBdSotua1Eq355x7eaHeHwLaVsaND+/w5d6pb27BWLBPrKfH0Rb0t hSUe7ssy83W03ZgCqxHppZsgU0MFwmdlhRFrHRK0xzI3GyEzbTxPkgA7waLuzH2svyPgUqOrQ6o p46zoyeS36gyxcIrA4NAGBCNOcWoQD6dTQdj2BjqzjUx3b4oRrJbAYUKcck8JSF8M0mYuej/8bJ wLq4t8wpniFq3tfUlwKdnp6nhFfzbmQu40n0YUUjWqLTDPYOHk6mj8LDh9mxtXUCP/CXkU/Od1M nghUzI6LUSIZg8qXbaEo8U6ckl3DO3rT+LEswjBWDlWBpS9I26xWaGsMNbgG64T08C5JgmsdLM1 PvZ18WEzDG3yS3 X-Received: by 2002:a05:6102:c94:b0:5db:3cda:cc3b with SMTP id ada2fe7eead31-5f1a55a2fddmr4131087137.34.1768890079962; Mon, 19 Jan 2026 22:21:19 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:19 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:44 -0500 Subject: [PATCH v5 4/7] iio: core: Add cleanup.h support for iio_device_claim_*() 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: quoted-printable Message-Id: <20260120-lock-impr-v5-4-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=3613; i=kuurtb@gmail.com; h=from:subject:message-id; bh=gk4uEOkebbeY+cZwYTy+/3fKoRkuSLvWkzrfvmHqOLM=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpd9jkpauCy8c6Mr7FDbP7X+bXcND+wMvSkQ6RpVG ihSwDyvo5SFQYyLQVZMkaU9YdG3R1F5b/0OhN6HmcPKBDKEgYtTACZS8J7hn+oz17uT5/z/GWBk 0ccgsO+oyKal69KrXsRZn+p/MMMsYikjw+8dyw7LRUv+mJujZuS5yCbm46LESNWlYXrNHxM21u1 l4QcA X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Add guard classes for iio_device_claim_*() conditional locks. This will aid drivers write safer and cleaner code when dealing with some common patterns. 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. Suggested-by: Andy Shevchenko Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Acked-by: Andy Shevchenko Signed-off-by: Kurt Borja --- include/linux/iio/iio.h | 65 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 65 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 36bd14e93a75..a9ecff191bd9 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(st= ruct iio_dev *indio_dev) */ #define iio_device_release_buffer_mode(indio_dev) __iio_dev_mode_unlock(in= dio_dev) =20 +/* + * These classes are not meant to be used directly by drivers (hence the + * __priv__ prefix). Instead, documented wrapper macros are provided below= to + * enforce the use of ACQUIRE() or guard() semantics and avoid the problem= atic + * 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() - Tries to acquire the direct mode lock w= ith + * automatic release + * @dev: IIO device instance + * @claim: Variable identifier to store acquire result + * + * Tries to acquire the direct mode lock with cleanup ACQUIRE() semantics = and + * automatically releases it at the end of the scope. It most be always pa= ired + * 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 + * @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 re= lease + * @dev: IIO device instance + * + * Acquires the mode lock with cleanup guard() semantics. It is usually pa= ired + * with iio_buffer_enabled(). + * + * This should *not* be used to protect internal driver state and it's use= in + * general is *strongly* discouraged. Use any of the IIO_DEV_ACQUIRE_*_MOD= E() + * variants. + * + * Context: Can sleep + */ +#define IIO_DEV_GUARD_CURRENT_MODE(dev) \ + guard(__priv__iio_dev_mode_lock)(dev) + extern const struct bus_type iio_bus_type; =20 /** --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 8FFAC350D4D for ; Tue, 20 Jan 2026 06:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890086; cv=none; b=oN6L7hmmtYVyVXriY8eopp9DAYHnjQ3m8sV3Z4t4d/lXIiY44r38DVOOAN1aHzg/pyvjcl16LChi9C0csfPT7hcV10X7HM+jSIH65Xf+uiLYcQNmZ6/ERRexcs76Qm7WHqPl7VFblAu4reGJG1ugarVr3MQhSbxCOxTPhNDUqPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890086; c=relaxed/simple; bh=3P+X2YeLcPjCXYTP9cibJrgBqh+scSiCbpaQGpGyBmA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZhG30R1/ECSwAJpMO2Dr8pzbXSgD/3gUd/30XLppg5NqO8w5akPe7jhJ2XPyV/2ufYjANaX9hW64typ2oi0FyUDgzw8jNdl3iP/tHCNDmYFal3pwtxmcIj/wy+dNlzOTmlUJMgu8byJAVTtY29xddYsAvy68EUTVf5ZaORK16GU= 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=UIOrgQEu; arc=none smtp.client-ip=209.85.222.48 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="UIOrgQEu" Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-93f5905e698so1503763241.0 for ; Mon, 19 Jan 2026 22:21:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890082; x=1769494882; darn=vger.kernel.org; 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=XTnTVRGv/a3yeACWeWEj6KZeE3Y99K4b2EX+Zi7IhJ8=; b=UIOrgQEurYEnRyBFnKR9+ame2oPrvvlZap5p+VRjNJo/qHI13vEZsXejCcPJXQmZuB 9LKhFLOlUmjONFKgR6FDCr1ctzO0Vd7CB5sGsw7A6kYzTNzr2axYBs5cT75rwRmtsyGn 0GQ/exnNYJO1kaKGIBlcCQV2UsYXHnKqr3A+dmQ7W4Q5VW6rpXZzxqnDiuEi360DYRPq aUtIL6Mf1jbXmD1udF3aj3//QXjHebYL693fdPKpUfBBrrN0Q5g9PVlw8O8pUTFco/rK hyIZWSw446TwCNPV4MumRW9GwZgHkrPEEtY+YTTNqrlXRZ40/+Z/8CzMx3EO5HZPSB9X 5PaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890082; x=1769494882; 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=XTnTVRGv/a3yeACWeWEj6KZeE3Y99K4b2EX+Zi7IhJ8=; b=dbiNInjRNneOEbGtjRpQ8O5NHxZd7b37G3ZXdgPZbOm5668WWiwU64uRQj5udi0mHn 8XslrNIliNI6hSTHYCzM2Me1gR4+N/3dOwa4ak5SeJVyzCgNIUrzzRoGjmKIpfFuqimO I3RmRxnh0GOIGe+/b/BLfGexVlMWCopCe5rZ12No10MJJpomf2UR5cqEPIPW0YoWWFS3 8IhhsE3lZ6Mka+v2+mE9gC8YOro8kwMhEcVypyaJyYrKPOs3T3mirzNx1uNZc0Bg3o+v WSYyZZ8Qtf+zw6eSrcsQBRiLghbANaMErVrPfFU+bjFk2bNydmasGCETx1R93FYwjCHs sndQ== X-Forwarded-Encrypted: i=1; AJvYcCUEf/u/OwY7jBeovhKcRtGRyL5sY5DgkZQk2PPUNbkW9EPi75by9cc9yeHgJFjsHZK54ozoaVkXtjgE5ck=@vger.kernel.org X-Gm-Message-State: AOJu0YwJ/xsVtklMtj57SacpBdjoCl8AcgBcAl1QMy7faPHM6KdDv3NA zzVjddgdyXdc+OryMCC01qJxq+1SKX2hcgafTY6K0OkT6coYuAB2YF8n X-Gm-Gg: AZuq6aLBwLdBPB00wXvMIk1kPz9AXzc8McRMynnQJnkK7dzV/Ea4hTh2lYgczozh5jX A9lLWsGS+G16pBhZy6tqOB2YDTYShbZSJyb4GDgDUY0lDdyIt5lIt3FTK67ra2NqMcwF8v6hDrx H3HP5fGMCyxyPlFnqxneHPiJGjejN4tYe6c2t1ldtSZ0AuzMWQRU5LJvIMcSBQ2tOIfBz6Jfhjx wDqW2aCRWy7NuQrqmcNjPkOUTTSaxGnB0uPCgjefAT1yD0zeDJbvUZbWtG62pxa5s+IyNfJVwYL gkIJuYSu0QWWOJJaiWHvHDvUbd4bhNMh9mWiQOx0gRZ+bjSbMFRnQeWjS4ZG5AZktIneGJ4L5dz 7yetp470+BHq1/5dMLYG4ytGYj2NwE7wlQ17kKdlWhiOWbTbJ9D4ZZEPJwRIfTpl45d8ZzuL7HZ tFVsPqfvvAdHzy X-Received: by 2002:a05:6102:c94:b0:5db:3cda:cc3b with SMTP id ada2fe7eead31-5f1a55a2fddmr4131102137.34.1768890082354; Mon, 19 Jan 2026 22:21:22 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:22 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:45 -0500 Subject: [PATCH v5 5/7] iio: light: vcnl4000: Use IIO cleanup helpers 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: quoted-printable Message-Id: <20260120-lock-impr-v5-5-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=3136; i=kuurtb@gmail.com; h=from:subject:message-id; bh=3P+X2YeLcPjCXYTP9cibJrgBqh+scSiCbpaQGpGyBmA=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cpcjX77/P+Ht9JK3564ce7SMe8Lsi0pHqwPPnlObq T2hfbLQwY5SFgYxLgZZMUWW9oRF3x5F5b31OxB6H2YOKxPIEAYuTgGYSMZJRobuqjUF4rn7DC7P CjnyrLTDRX3vzVluW1fdeMXzP5qTUdSVkeFtxctSkflfmh1+PTm1+ExoaSrn3e2fs6fKu3Px555 Jj2ACAA== X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Use IIO_DEV_ACQUIRE_DIRECT_MODE() helper to automatically release direct mode. Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/light/vcnl4000.c | 49 ++++++++++++++++------------------------= ---- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 4dbb2294a843..a36c23813679 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -1078,20 +1078,17 @@ static int vcnl4010_read_raw(struct iio_dev *indio_= dev, =20 switch (mask) { case IIO_CHAN_INFO_RAW: - case IIO_CHAN_INFO_SCALE: - if (!iio_device_claim_direct(indio_dev)) + case IIO_CHAN_INFO_SCALE: { + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); + if (IIO_DEV_ACQUIRE_FAILED(claim)) return -EBUSY; =20 /* Protect against event capture. */ - if (vcnl4010_is_in_periodic_mode(data)) { - ret =3D -EBUSY; - } else { - ret =3D vcnl4000_read_raw(indio_dev, chan, val, val2, - mask); - } + if (vcnl4010_is_in_periodic_mode(data)) + return -EBUSY; =20 - iio_device_release_direct(indio_dev); - return ret; + return vcnl4000_read_raw(indio_dev, chan, val, val2, mask); + } case IIO_CHAN_INFO_SAMP_FREQ: switch (chan->type) { case IIO_PROXIMITY: @@ -1148,36 +1145,27 @@ static int vcnl4010_write_raw(struct iio_dev *indio= _dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - int ret; struct vcnl4000_data *data =3D iio_priv(indio_dev); =20 - if (!iio_device_claim_direct(indio_dev)) + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); + if (IIO_DEV_ACQUIRE_FAILED(claim)) return -EBUSY; =20 /* Protect against event capture. */ - if (vcnl4010_is_in_periodic_mode(data)) { - ret =3D -EBUSY; - goto end; - } + if (vcnl4010_is_in_periodic_mode(data)) + return -EBUSY; =20 switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: switch (chan->type) { case IIO_PROXIMITY: - ret =3D vcnl4010_write_proxy_samp_freq(data, val, val2); - goto end; + return vcnl4010_write_proxy_samp_freq(data, val, val2); default: - ret =3D -EINVAL; - goto end; + return -EINVAL; } default: - ret =3D -EINVAL; - goto end; + return -EINVAL; } - -end: - iio_device_release_direct(indio_dev); - return ret; } =20 static int vcnl4010_read_event(struct iio_dev *indio_dev, @@ -1438,14 +1426,13 @@ static int vcnl4010_config_threshold_disable(struct= vcnl4000_data *data) static int vcnl4010_config_threshold(struct iio_dev *indio_dev, bool state) { struct vcnl4000_data *data =3D iio_priv(indio_dev); - int ret; =20 if (state) { - if (!iio_device_claim_direct(indio_dev)) + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim); + if (IIO_DEV_ACQUIRE_FAILED(claim)) return -EBUSY; - ret =3D vcnl4010_config_threshold_enable(data); - iio_device_release_direct(indio_dev); - return ret; + + return vcnl4010_config_threshold_enable(data); } else { return vcnl4010_config_threshold_disable(data); } --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 Received: from mail-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) (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 06A1F37F0E3 for ; Tue, 20 Jan 2026 06:21:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890087; cv=none; b=dVe5q9L58c4LU62Fdw1mNSyW9Jg2C2MxFehqZtNoQmfl4Dyii33GIPEpWyK7s0mD8PmYbtLqOo2RWmVWg5mwhQYyIaUlrJCxFhS/P1uBwFcy8VtwJldhfWCQiL6t3MX2mpZv9R1brEHzTiagUBP9nw/vHI8M3F5WWvFsDG6iYfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890087; c=relaxed/simple; bh=R6AtgfHNFuyoDu3Dt8So6HbHkHEi4svHf3KFVpxGpRY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M2zVvXFgrfJolvfSsL3Ke/NekPoLaIc7xfhWqqucXwerv5HI6iVux7C9X93sEmt364U9PajK/Zd1HmJ2lR9LC8SBn7G3FSGC2RY6yKXbcc1UFXwbJZJKYj01q3oOae/CUNLtNDxRGwMBRF1eD9wg6ChPd0m5Y9fYe77mnALdWpA= 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=C3KAM4V+; arc=none smtp.client-ip=209.85.222.47 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="C3KAM4V+" Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-94120e0acbeso3010077241.2 for ; Mon, 19 Jan 2026 22:21:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890085; x=1769494885; darn=vger.kernel.org; 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=RvaFKco8z0TcIBUmMpdNSTwRtZj3x2smNoAu0imBUvA=; b=C3KAM4V+GS5+Ez8w/HTF/une3gdoJQoiYI996ruNMpSlB3VSGoopswE0qLXLdA9wt/ Yy3QBOq1WqUp5wILnxd7KY7ZwtKnM5Go98nx14VZGDm5DeqKx8w/hwTRtZh1jsaXIX7U atfQdpx8NP6E2JZ9rKmxb0Q1B++OLN/sAEMtjlX8lxG16z1OB+3WkQsAxjVt2JJ32aoU HGGW+2JJReQsF5jt1r5+qbbFJICdyUOCgzJ9MVi81q0bDofrR20d/Y5sXIVAdpxS0lfc tqrFI/UrZ+IPiBfBF44zsQUf/m7FABvnVcyFwRlaYtY6tRuWYMiyBWNiP9MxHEYM92d/ shPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890085; x=1769494885; 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=RvaFKco8z0TcIBUmMpdNSTwRtZj3x2smNoAu0imBUvA=; b=voZA0tmKhU6oaeemHOIkJHOdjXtG5CYJ3+5x/8g7wnHyQdEzCMAvKATyE4FLqlltf5 0Rf0XI+eSCms5x24JrtJDqIQsexO9v+dA9ekEdhPYy2QR5MGRXA8jBwlcKweu/NWZnlQ dcrzus01rSCXSagznJT8L/V9sbmQELhr42Hk445/9R8DfNexwZNDyCGm6rkVC7QYnO7E ArCme87jVAXAQxJdunXyshlsboX96bFETXI1Dmj4nfPQ9UDGdSMWv8Lcxnx65vJ2ZDc4 R7JNsSEqg2ddKbOv2uaTIqAWYKoWPR4wfaMCuTKeHCdHubCTw8F/fFoLudm0NpdFukih c3gg== X-Forwarded-Encrypted: i=1; AJvYcCWzvJE2otzyG4IkLLYDzIIo+7fBS1EovWQKqnlXYUV8RYU7Co9vkvCkMpkeeekw1GRyVL11zRiSGix4fn0=@vger.kernel.org X-Gm-Message-State: AOJu0YwHWQx46zbrmBCvnlxFkYhhI4uabnnFV6YIltoqdZvYboVpr6IH OKe9LRX+AVC35xX/0ieCNKo+j0UA7ODxj9UUFPJoKc3nx37KIZtiQaTg X-Gm-Gg: AZuq6aIdqkz+m0oFsUjp7/oTe8zZIBjhZ6TyZlJ5O+aoonuycDje3aRc1L2R+TRxVbk 2UQnozHWEfPe96Ylg3XukPgm/7hBE1KjMK6X2aqfvWbwmfXrnLrZIEPriv71z1yWIMlmIIsA9a3 Wh0J9Duw466v23t/ZfKIwpEQC4JbcQeCpCBk6h4VSn10/T5dk/PnR4tgaOGHfeOlDqG830G9AOE BhOW7hiP1D93VoglSe7/82b+PsJxvyFmWuUrIMR4f4kQSNmmqsq+BccqW2xWL4yAde7kySJrYTp /ZbNp7DQtdlJeN+ey9oeHHkw/DRIpwwttwhtYIN30PxCzFtJCuH6rgasEW2vGM1TKi29/BHIjC/ oy9UZ88PkahbOWD2Azau5aV7Qd92kps1zs6gAeYCVKzpfnP/aobZy4KlInwjljfm4EUkZTN3sVb MaTmGvQjQ0UmlK X-Received: by 2002:a05:6102:c0c:b0:5ed:a24:1a98 with SMTP id ada2fe7eead31-5f1a55e599emr4178016137.44.1768890084657; Mon, 19 Jan 2026 22:21:24 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:24 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:46 -0500 Subject: [PATCH v5 6/7] iio: health: max30102: Use IIO cleanup helpers 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: quoted-printable Message-Id: <20260120-lock-impr-v5-6-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=2086; i=kuurtb@gmail.com; h=from:subject:message-id; bh=R6AtgfHNFuyoDu3Dt8So6HbHkHEi4svHf3KFVpxGpRY=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJn5cld4PVkXr+ucZnJwyS918f2KXWyhifIiBqXPPnDtW DTBSOlmRykLgxgXg6yYIkt7wqJvj6Ly3vodCL0PM4eVCWQIAxenAEzkhzXD/3wb/gNpl18+bNt8 9Nl/N9u7+uz7G8+HMO85r9p15cMGEWmG/9kLLLl/R1kvsVLoET5XJW8pd0Z0ekKpYf/HXzz/F61 3YwcA X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Use IIO_DEV_GUARD_CURRENT_MODE() cleanup helper to simplify and drop busy-waiting code in max30102_read_raw(). Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/health/max30102.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c index 6918fcb5de2b..47da44efd68b 100644 --- a/drivers/iio/health/max30102.c +++ b/drivers/iio/health/max30102.c @@ -467,44 +467,29 @@ static int max30102_read_raw(struct iio_dev *indio_de= v, int *val, int *val2, long mask) { struct max30102_data *data =3D iio_priv(indio_dev); - int ret =3D -EINVAL; + int ret; =20 switch (mask) { - case IIO_CHAN_INFO_RAW: + case IIO_CHAN_INFO_RAW: { /* * Temperature reading can only be acquired when not in * shutdown; leave shutdown briefly when buffer not running */ -any_mode_retry: - if (!iio_device_try_claim_buffer_mode(indio_dev)) { - /* - * This one is a *bit* hacky. If we cannot claim buffer - * mode, then try direct mode so that we make sure - * things cannot concurrently change. And we just keep - * trying until we get one of the modes... - */ - if (!iio_device_claim_direct(indio_dev)) - goto any_mode_retry; + IIO_DEV_GUARD_CURRENT_MODE(indio_dev); =20 - ret =3D max30102_get_temp(data, val, true); - iio_device_release_direct(indio_dev); - } else { - ret =3D max30102_get_temp(data, val, false); - iio_device_release_buffer_mode(indio_dev); - } + ret =3D max30102_get_temp(data, val, !iio_buffer_enabled(indio_dev)); if (ret) return ret; =20 - ret =3D IIO_VAL_INT; - break; + return IIO_VAL_INT; + } case IIO_CHAN_INFO_SCALE: *val =3D 1000; /* 62.5 */ *val2 =3D 16; - ret =3D IIO_VAL_FRACTIONAL; - break; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; } - - return ret; } =20 static const struct iio_info max30102_info =3D { --=20 2.52.0 From nobody Sat Feb 7 17:41:05 2026 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 3374037E2EC for ; Tue, 20 Jan 2026 06:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890089; cv=none; b=iymd2tnyqMlB/YJ+UUHTgTZ++EMasQUXRJIfpfnkddGJZNMWNh4QXJeoqregByH1FiOKzz5uffQHPcUFwxONEpQUr4+xBcH/Uq1e5ocvOVf5cF+72zGB6P8tvZIjuPRTcmkY/bV0ZFtrNzLDTEHaLMa6GswZylReALnEq6usJ30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890089; c=relaxed/simple; bh=K/GzZXmVDH5d3ajOh9Vses0jzRTbszvo9JEIlad+htc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X4pOEIylUz4e5BG7fG92VLDorjR2OQJXLPTLpmHD3CJrxXDegF1Qih9WSFw/t6dymgB+PFfufZOeq71QK2CieCpOJmslGM/skGGh3XHilCcxUxydFDuYTsVXMy5T7ZJwvPDGjnbZsR5qhMOVDF5HKNE6luoXYJONSLMc7h1hypY= 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=FYYuH+kx; arc=none smtp.client-ip=209.85.217.43 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="FYYuH+kx" Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-5eeff7e8bb3so3400744137.1 for ; Mon, 19 Jan 2026 22:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890087; x=1769494887; darn=vger.kernel.org; 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=SUuEqo1bBPTtYvx/6MqHHwRERlW4p1/ugxXmq/ssirA=; b=FYYuH+kxM1EGSoCC3HVZbHB6CGQjjBoqCO9fH5NY+5uq5ECQ5hV0w6Nuz3KBeAfTBW Q43b296pQ+H/76mHpGFhtd6voE+ahyBaqxRAJXTGENvElue+9ujKy7eUOaSxbCTo5/E9 f6NYk5HmnipR8KH2yl5jQD+cim6VTai204uKAs6IeoVebeeAEqKliL+60+/IwfvH8+hl qlLWQsU0QF2zxu62z2suYxrbHmsiuVfV5XYoyR/vPAGhAetCo3Cop7wleGlvVimO4nWs ElozcjgoWvAB8A/NNYuLQ/UABdULgnYFm6qNWySiyW+gJG0EZn4izvYcnRfL1r/B0NdC RN2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890087; x=1769494887; 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=SUuEqo1bBPTtYvx/6MqHHwRERlW4p1/ugxXmq/ssirA=; b=fAzQwbssgr09/dxjflWvXM0MzdtTXLbD7y1zvCfZIUEeGNlnLOfVwVU3I/YWhbyguZ S//TNpNw2e9bcuXRnkqelR8snAVU3EKJ5zw2WV7Rj6TkQd0bbK0MLeC8/k0dlkkWd3Mr QotH2dji5DeFy2/9HZsi35iNHwqG3g2H8tHPeYNVG/aZAd1zLsACWmNpQdzM/T86VP7M 4WACXAHAzSmhetGE/qjKQxt3gQQOV+EkoUNbMPznK8myOw0r2ovWW9g6YI6dCysVIplB P64i6AlpqFofj+klKf1XiYaH2Docf8hP7ty0F8RNboxnyAQhq3FP/wOYfzFuvmgjnUoR x1Aw== X-Forwarded-Encrypted: i=1; AJvYcCXbRg0hnvM3DnJYqcA0E9WTv+LhGO7bI2F+gagd6mgs/5A7xg5Rd3gu0iHGxUQA8PP/XJvbqJVmn0H9SPU=@vger.kernel.org X-Gm-Message-State: AOJu0YzJcMak2jwFB5KXfJTHXlbpnIRu9/yCrL+9IuAB/K6whfH4h8bo BLM2WY7Ei2KnCZ3JkwFQoGSX+AGh+YpmdFtVFnATx5YkTWAWsVmV/uXV X-Gm-Gg: AZuq6aIMUbeObgjCZndvf3lXfqveWMM7M6J1bCvKi/yrCOPvJ0GRiwOHhy2JGl4wVjF 8Ld1jroYKxT3FuCU9V1Zeu52RijCl7356UorpemsiCHcwqq06YFcBrTJctn7XF3H0Sx+qrSWqdD SOSolIlnu9FT5jgA4yCmzh4td0gBBcbOdjqfT/IT+abbpTV88Kq//uTgl0qnfpFXyp3yiu97H10 91T3Yl7NMdcF4V7JPhN82XHriPuN2CzFw1Gebb4PdOWsL/5Nybjfvwy5LVYo9zAcPmjD0LxbUuT ktMLZE+ImkCHwB9dmp5bit3L+Nzs1rnrOxGoOq8oSro5M3Ij7bvgK+5mbt9jesb+96fLdH2hlp7 DkjNaCQ/NqJaTL9Y8Sq1GyUMVO2odqtjsRtHXY68NzqcikU54PuDepZLV7PiYQmI1MQfeJ7/Kem Jr1Oh5g0VGfTf1 X-Received: by 2002:a05:6102:3584:b0:5ef:aeff:82fc with SMTP id ada2fe7eead31-5f50aa1028emr250763137.37.1768890087050; Mon, 19 Jan 2026 22:21:27 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:26 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:47 -0500 Subject: [PATCH v5 7/7] iio: light: opt4060: Use IIO cleanup helpers 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: quoted-printable Message-Id: <20260120-lock-impr-v5-7-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=2688; i=kuurtb@gmail.com; h=from:subject:message-id; bh=K/GzZXmVDH5d3ajOh9Vses0jzRTbszvo9JEIlad+htc=; b=kA0DAAoWFmBDOPSf1GYByyZiAGlvHtSjrwC1JnQanLoLExLJTwrpwdoltjp5KmS8n1f6i+dHS Yh1BAAWCgAdFiEEh2Ci9uJabu1OwFXfFmBDOPSf1GYFAmlvHtQACgkQFmBDOPSf1Gb/KAD7BdoF qUPP0diCbpCK9p45EPoIqdtrwlBjt1YOYDEaEvAA/2iqEPiM5dVqGN7bLWinI7Y1nD5Qgy9ZPUt 10sazV1EN X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Use IIO_DEV_GUARD_CURRENT_MODE() cleanup helper to simplify and drop busy-waiting code in opt4060_set_driver_state(). Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/light/opt4060.c | 52 +++++++++++++++--------------------------= ---- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c index 8c4a1f562a83..d6e915ab355d 100644 --- a/drivers/iio/light/opt4060.c +++ b/drivers/iio/light/opt4060.c @@ -302,41 +302,23 @@ static int opt4060_set_driver_state(struct iio_dev *i= ndio_dev, bool continuous_irq) { struct opt4060_chip *chip =3D iio_priv(indio_dev); - int ret =3D 0; -any_mode_retry: - if (!iio_device_try_claim_buffer_mode(indio_dev)) { - /* - * This one is a *bit* hacky. If we cannot claim buffer mode, - * then try direct mode so that we make sure things cannot - * concurrently change. And we just keep trying until we get one - * of the modes... - */ - if (!iio_device_claim_direct(indio_dev)) - goto any_mode_retry; - /* - * This path means that we managed to claim direct mode. In - * this case the buffer isn't enabled and it's okay to leave - * continuous mode for sampling and/or irq. - */ - ret =3D opt4060_set_state_common(chip, continuous_sampling, - continuous_irq); - iio_device_release_direct(indio_dev); - return ret; - } else { - /* - * This path means that we managed to claim buffer mode. In - * this case the buffer is enabled and irq and sampling must go - * to or remain continuous, but only if the trigger is from this - * device. - */ - if (!iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) - ret =3D opt4060_set_state_common(chip, true, true); - else - ret =3D opt4060_set_state_common(chip, continuous_sampling, - continuous_irq); - iio_device_release_buffer_mode(indio_dev); - } - return ret; + + IIO_DEV_GUARD_CURRENT_MODE(indio_dev); + + /* + * If we manage to claim buffer mode and we are using our own trigger, + * IRQ and sampling must go to or remain continuous. + */ + if (iio_buffer_enabled(indio_dev) && + iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) + return opt4060_set_state_common(chip, true, true); + + /* + * This path means that we managed to claim direct mode. In this case + * the buffer isn't enabled and it's okay to leave continuous mode for + * sampling and/or irq. + */ + return opt4060_set_state_common(chip, continuous_sampling, continuous_irq= ); } =20 /* --=20 2.52.0