From nobody Sun Feb 8 22:05:40 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