From nobody Sun Feb 8 14:10:31 2026 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) (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 5D1A133B96B for ; Sun, 18 Jan 2026 15:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751097; cv=none; b=k2M1p9TRnGru7cR4r4/msQdfpGPKKFxlfDyUWGRRWMsCQuqNRkV1mj2WCjmfsNl+grEmnU+cVuRt5lmTmvlmyBKp27cFQC5zQg4avBl2waLqfmH5QrzbKhvIWvRlzlkZPFxS8LAv1Q+YnYYjd+71fpNQXJs9JtDJOre3VVF/RZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751097; c=relaxed/simple; bh=V5GRFxOK+CqYOqKjTag3VDmILaHUud2L5Y/Wvb3b2ns=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ah61e8Eq+RPsWC213wgiVuHPuI05R3jb1jgBATCpWeWD4rn9ZYkd6h4gl+W0W1nA7Prev8YLAp4AnH1XGhTstIhIrvLkVCXahgI9TP/8gvJIOHVOEJ+lKBSr/g6HB1illfjpGEavw5eq/7imcxULJU/QMoEpcwMEe50Xkshmop4= 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=DEaIzD2b; arc=none smtp.client-ip=209.85.222.52 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="DEaIzD2b" Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-9371f6f2813so1011480241.0 for ; Sun, 18 Jan 2026 07:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768751094; x=1769355894; 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=Y6CY6gggGU9QCCuY3V8jLvoji+Ol4m8zqn3+Qzz+4w0=; b=DEaIzD2bhdioW2brvbkMlA0FY30Wbnpc37xCzmeNtheqhIkixGeLubWOL3CHY0gLpy YOftSldJgxUsoQGqaQNcMOtHT31FUraL5cx6K4OQY9EtK4utxSpoDJKizomjHAhtezmV WD8Nt2y7H0/G/1LKL+zPdJ4WJCGshjNiwqh24MjBAhbnTkfMwTkPDwPYdz6zZYa9lqo1 GdwyFMw8f20GwRw/6e4SVzzHoUZwiBlE5yP7qopuC5JvI8YJr43LfCzbUsbJknhErmC0 Nz1nTBHOWz2bTqX6kY6Y6hBSt/OuPQdcKa6xO2aF5ZjwhHiOtXcvQKHnV4Vswkb00pNS S+tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768751094; x=1769355894; 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=Y6CY6gggGU9QCCuY3V8jLvoji+Ol4m8zqn3+Qzz+4w0=; b=VuUINpkqvm5rMCPUDeQTEyWa9Gd8g4bnl6QjPchtJFm/uqpqcNm9jH07kUyEyPLzx2 lbtWTYqu2X52tdXz4P14gn+83yuGujoj8Q+ImPmfnePGCvIZ51izKMVrKgIhwQ28r/mi zo/Wrd73WYNhHQn96JTQXqpQlSHk+NcKZC7gnIOSZI5iJ8/+G3hUe5JLF3CNishKq5Oj nTwEU/imWMJIuZ5v04YoAbr1OkmPgO6lAh88j/ZoczF/NqJYIHtl6xIuRFKaDxW2I8Kx 4YyAXAsVa7kFwVO2cIWs8zdcbMsTwTZy3ufXczHHN7CpQbgIL6cu07MCgBon5ULrvSua 77Cg== X-Forwarded-Encrypted: i=1; AJvYcCUmimMqqlNY0mKuYJX6FweT87XTVVpdBGIvuNDyXoXB+AbesRcVLykhsg5/slZmQXwqknyb2XpGxDtuiws=@vger.kernel.org X-Gm-Message-State: AOJu0YwgAFAk6w9lueT7FJ4335tPRKM93FPPYb/YigpHuPqD8SponwTM jAHR5j59/YD+6tNpP+415r6kdarcuTuzvUxOa2WkIgc1oBv+uuKTXK6q X-Gm-Gg: AY/fxX6bKMBDNDxlueNano/pE55JkJqtF06XTsL3ydX2XVn7SE/lDbWXeg4RbqZdQFb HB2uRIrRRH/hu9X2hvmWP0wiUcr6cC0Nkj4oCEihU4tkuLApzxqxNWfl4Nb6J6XLlJJv7WXuReN Ny0I34NEHjfPSZgiQ56G/KU/CbMaDG8jqhBLQV6fRl6j6RaDekb1HoEjiTx91aF8B7uaUhkL/W4 R6nykoalegxxZFlnKveviUAhUTbsJu43QXZSe3l7vAbXX/Z5SGZ+avWJIirOTD2rypxotKixqR5 4K8Aw1f8ZZUCAoXvgz9HZ3A+uaIFIhkLCkniOciimXsRp36V23ctyvbwfj0uUDgJtrg7RR5xzWh EDfCahyl6K1QHE/9O0vDt21cdxelWbn9Wa2XGHgjXkRLkIZ8G5KxWDYRNODth1RB/dm8Lzzul0B Hfryp62DtE/wMB X-Received: by 2002:a05:6102:5109:b0:5d5:f544:a88e with SMTP id ada2fe7eead31-5f1a71b9607mr2391425137.35.1768751094087; Sun, 18 Jan 2026 07:44:54 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6d3ca2esm2832731137.10.2026.01.18.07.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jan 2026 07:44:53 -0800 (PST) From: Kurt Borja Date: Sun, 18 Jan 2026 10:44:28 -0500 Subject: [PATCH v4 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: <20260118-lock-impr-v4-1-6c8d0aee8ed2@gmail.com> References: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> In-Reply-To: <20260118-lock-impr-v4-0-6c8d0aee8ed2@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=2874; i=kuurtb@gmail.com; h=from:subject:message-id; bh=V5GRFxOK+CqYOqKjTag3VDmILaHUud2L5Y/Wvb3b2ns=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJk5/z8sc/oo426zjDHXauYmqYyS97EeL/jsHxnmBZ97X znPpHBxRykLgxgXg6yYIkt7wqJvj6Ly3vodCL0PM4eVCWQIAxenAExEO5GR4Unwj3N67c++vLfs nMpTKrZhudQD4c9pEl/YIiInteix+TD8Mzy+0LlwaTZz3fKHAl2zj+8Jum72PuukhPjN5mm/7Z9 lcwIA 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..9693a6bb3917 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