From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.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 CAEF62D0C63 for ; Tue, 23 Dec 2025 17:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766510384; cv=none; b=RrY1Qx4sSF0VUVv7Og4wpuh3kXn4UoGqoRGZerpHHz8whcWK/8xt3jrTPavaUYyEMRVaWZqB92UAgxAz9EcUZ1bJ+Z2bApOKyyyEhNdnidWp6UqEaSpR2QX+7t5YrE4QubqwCKR1H83Be44Juhl5MgC4iXuIwWNzY817XzZMeXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766510384; c=relaxed/simple; bh=NdjE4V+EEouklcSCm6BZ7mfDidB3bn7JY5Wh2M//4AM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VE4TVudzKvtP7J6IK3TblVcJluedm1GTs9G1cttQ1axC/uV6IjA5uQ3M3v9AluhpzthTKbZkEhu7i1kRGsk/QlVBWewZBAOFlct3KqrNdUo3cfnCWO6EP7SQiHqb7X25vSzrbMLKQR8aU5/Ctxmdvl2IgeEgzoTvRaIFhcb3/DY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ZOvWWfDU; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ZOvWWfDU" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-65d0952e596so2931918eaf.1 for ; Tue, 23 Dec 2025 09:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1766510380; x=1767115180; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kHzs3BD6a+q8LRnlmiLzH3xOmNz9JKocpErVtV3u+xk=; b=ZOvWWfDUKdgb2JtdGUO6hQVGmBTyYO4Koa+aFckFoUUTxujWgzeY2QcoKe9j7RbwV3 TyzHvWvKUU9yfVJSmvY7tJABwJ+ARp9bViEXkFuJlg+vax6dPnByac+7/y3wnsbORAwQ +heZMs1VBk964Chv8uMNQ/Rui9H3gAQ5TVBWWj6rLRFOTY/M795gwZ2MSLXhYHMxBmKD GWqqVtsegHBC5Tzo4D/XT2jTNIAEVdNrOiXb1uQYa5ciOL3aK1CMfZd6+jAKJxIFNPE0 6lrqE6FrsajmMQVsILbNOC+XsANsS8g8iLMJizAyjtLKki1zsc26weJv7XZhXtoo8tbu 2sJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766510380; x=1767115180; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kHzs3BD6a+q8LRnlmiLzH3xOmNz9JKocpErVtV3u+xk=; b=G3gKRXL1/ncIp2tc+fslcKOCGXQZigbFBw+oQaAMYyhFZ0Zt6G6d2hZ9EVrp9VrwO7 eXm0d4YYh+Ijkm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wVNbtJWIUgSq1V1a2nMl5MLixp2jR1RBcMRLq6HzFozpq4GGBCAoox8A== X-Received: by 2002:a05:6820:f004:b0:659:9a49:8eea with SMTP id 006d021491bc7-65d0e3a9cb9mr7432898eaf.30.1766510379759; Tue, 23 Dec 2025 09:19:39 -0800 (PST) Received: from ?IPV6:2600:8803:e7e4:500:fe29:88f1:f763:378b? ([2600:8803:e7e4:500:fe29:88f1:f763:378b]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-65d0f69ba9bsm8889471eaf.10.2025.12.23.09.19.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Dec 2025 09:19:39 -0800 (PST) Message-ID: <92d07935-b2b5-4cf3-bd45-654d77cdc23b@baylibre.com> Date: Tue, 23 Dec 2025 11:19:38 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/7] iio: core: Add and export __iio_dev_mode_lock() To: Kurt Borja , Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Benson Leung , Antoniu Miclaus , Gwendal Grignou , Shrikant Raskar , Per-Daniel Olsson Cc: =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Guenter Roeck , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev References: <20251211-lock-impr-v2-0-6fb47bdaaf24@gmail.com> <20251211-lock-impr-v2-1-6fb47bdaaf24@gmail.com> Content-Language: en-US From: David Lechner In-Reply-To: <20251211-lock-impr-v2-1-6fb47bdaaf24@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/11/25 8:45 PM, Kurt Borja wrote: > Add infallible wrappers around the internal IIO mode lock. Not sure what "infallible" is supposed to mean in this context. Maybe referring to autocleanup? > > 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 I wouldn't even say "strongly recommend". Just say "use these instead". In the exceptions, likely the autocleanup version should be used as is the case currently. > + * 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); > >