From mboxrd@z Thu Jan 1 00:00:00 1970 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 27DBF22D792 for ; Fri, 12 Dec 2025 02:45:35 +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=1765507537; cv=none; b=Y2Vto6kjMsDnxdVSrvL5xDn6pl/1Nkx3uhDyDd3mTDOvHKFifVy605gpKVxC0pSo1whZAJx5TVDWtN49hqjvPnzgZjaJn6yLJyg6qnBLJgnDh9K6ydk580xJqvTuIG9IjnkenTbwAqnZyuDl9DkNxP2bpW9D8v7G8kFJ3kJvcTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765507537; c=relaxed/simple; bh=ZyZf8TO7PzHx7g5RugMBOmjIDzgzIBX1y6ZRU4DbrOU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=h38t0iPMR+MQtRcuPxNrTNxZqWYr5jTg2ID6cQ8tIbqpJsrqNqs1Af43QYAbercjBblbJF3Ab8g3xvdq2RwXRTijbTFY+A106BwbkXMuBrq7JBub95z1YRcqsch3GktdEgfNFFFATOeb2s+cKOamfmVBLcDQerQhjiDGiVU87LE= 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=Nwk4UEco; 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="Nwk4UEco" Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-93f56804894so453838241.3 for ; Thu, 11 Dec 2025 18:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765507535; x=1766112335; 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=FinWiyCFvPunbe27vbfgs550CHQE+u+zy2oBmwPsfB4=; b=Nwk4UEcoYXC5Rzb6m220G8R8FHDJILcEAZs0bfqws75jSE15rZFvIudEVdoVphWKE7 nK4vVMFeHDD/XTv8Yguk2qoIKhSjP21EDLhMqV7I2jlWB2WPwO1KpT7hB2TsQORxF/ta DdYO3L6RopgRHU4p7RCK3jV0oF3pm484iS/2a8flFXNHGVUYFGX+jN3Jd0QiZK3sm2bd ChAeCxE2N44tlOAG3zPpmJrbN3ZPyPKbvZb4NL6XiyeCs8wz7BY2YPxfzs3JmGnYr7DI rsiFOJl4udFTzk38nnmmf0fEgqEQ/+YLV63DfsnLBZbw5ZjeMY4iJvoWu6xnHwrDF0pG XjUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765507535; x=1766112335; 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=FinWiyCFvPunbe27vbfgs550CHQE+u+zy2oBmwPsfB4=; b=e6Xc/iGSjrcppASIfzC3qROPAbkYFtBZCD47PKgmtnN7PMC1ZnarhX7vdoGI8PVMEF hjCqXER5DCKJwwkWPv3QaLTxIPoCyLyDbfJdJLEawSNmerNHdYV5mfJaEpI8ydTefxBZ JWh/aARdGsnCnvA3BEuvKDt//8A11yJFMQCcUsuIwGKRzf3xzmrFVMPmZUOoB1QEUJW3 RZnClXVLa9xNMHJXrppmJO2ap5D1FfAHizsgQt/2euWCVJvdu7CI1VYWbJWfutFOTRC/ manjhTsCkrE7eB8pFns5olHLLlnv8m9dsqVlfZaVLiH1D8auxd58Nvsg29CKcUmKUNMj Nu+g== X-Forwarded-Encrypted: i=1; AJvYcCWeef4iMQtt5f1uc8WFi1n1CnZmvwhKz/Q+yE6leFGn/ENodGz+Gg6l/Nebffruv1SuIOZ8yxI3PU7iTAI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzvwr8FZLcqWqmt4lzY6i+Wc9tP6VJzw1n419nrP8xPj6O3IBLE dlWYVEToAciO+OjLrFaBZCwfH+We8HkPnw1FysY7usj4Ij1WxtAdy/xbWoa4tA== X-Gm-Gg: AY/fxX7B3y5idWI4wNOLzEih0XHOx36ZHxlMhcPAcPfEGQGl568SfLlesd65gXR6A8a 2CneCmQb6GZmY3IEchxhdSJMvuXd4ATxU5kGQUBUbHnhpoKSdFliV7mBAfIRLejLpoU46/F3+T7 PDG0GjBs+cVsocXQEFYAkEv8XD9GyaUaIZfSbhmhfnyXq9+vTSbA4iXTC2CKZ3uhWcXM1wqr7sZ +8kpgE7uvk7fyQWyC8XcpHsJ73leizhqsFyJza0KG5b6nq29aX6LDGOosOSWOQciSbJUQh90+8u 84hAlP4fFgh3H64m3zmPfXRD9RiXXFhjZ3t8XsRhOG9hzTsOibcUNrWtiPZS9YQMSlO0nlk9fxB mBRL6htuY4IO+ZMXZ964DhdRPIMhJR2BhV35VpNlh9+k2mZKewplKyv4+bbvbQDggmd6iITv3KM oCXcEu1RSk7vZFbkVjN2uSzME= X-Google-Smtp-Source: AGHT+IF+ceBiyFMTLRWeRyVASsqKEDmZHzPSVx4bpNR94n9cZQdZ6LN/jPJOWf4xmhRScVw1fNAzfQ== X-Received: by 2002:a05:6102:e0b:b0:5e5:6221:c5a5 with SMTP id ada2fe7eead31-5e827471559mr131690137.9.1765507534762; Thu, 11 Dec 2025 18:45:34 -0800 (PST) Received: from [192.168.100.70] ([2800:bf0:82:3d2:875c:6c76:e06b:3095]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5e7d0f25ce2sm1693762137.8.2025.12.11.18.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 18:45:34 -0800 (PST) From: Kurt Borja Date: Thu, 11 Dec 2025 21:45:19 -0500 Subject: [PATCH v2 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: 7bit Message-Id: <20251211-lock-impr-v2-1-6fb47bdaaf24@gmail.com> References: <20251211-lock-impr-v2-0-6fb47bdaaf24@gmail.com> In-Reply-To: <20251211-lock-impr-v2-0-6fb47bdaaf24@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=2754; i=kuurtb@gmail.com; h=from:subject:message-id; bh=ZyZf8TO7PzHx7g5RugMBOmjIDzgzIBX1y6ZRU4DbrOU=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJnWjSeFLp+8w63AfWhP4Hkhj+5bBwSPez6VkFLr9zx46 tPMyhqJjlIWBjEuBlkxRZb2hEXfHkXlvfU7EHofZg4rE8gQBi5OAZhImhEjwwcRkZBgpfYy4eIt UjV3Fr5cftz0nBKD44SJ58KDw5f2pTMynGpay1dok3bNxvpoQLqt0fTqopYP3Y7XTvtePduxZLY dMwA= X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Add infallible 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. 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-core.c index f69deefcfb6f..1cce2d1ecef1 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, struct iio_dev *indio_dev, } EXPORT_SYMBOL_GPL(__devm_iio_device_register); +/** + * __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 stay + * that way until __iio_dev_mode_unlock() is called. + * + * This function is not meant to be used directly by drivers to protect internal + * state, a driver should have it's own mechanisms for that matter. + * + * There are very few cases where a driver actually needs to lock any mode. It's + * *strongly* recommended to use iio_device_claim_direct() or + * iio_device_claim_buffer_mode() pairs or related helpers. + */ +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_dev, 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); -- 2.52.0