[PATCH v3 1/2] regmap: Add an optional lockdep class to struct regmap_config

From: Arun Iyengar via B4 Relay

Date: Sat Nov 28 2026 - 14:06:38 EST


From: Arun Iyengar <aiyengar1990@xxxxxxxxx>

The lockdep class of regmap's own lock is per regmap_init_*() call site.
Maps made at one call site, such as all syscons, share it, so lockdep
mixes up their unrelated lock chains.

Let the caller give each map its own class with config->lock_key.

Suggested-by: Lee Jones <lee@xxxxxxxxxx>
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/base/regmap/regmap.c | 3 +++
include/linux/regmap.h | 3 +++
2 files changed, 6 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 0ba82fcc55bf..3534d27909a0 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -720,6 +720,9 @@ static int regmap_set_lock(struct regmap *map, const struct regmap_config *confi
return 0;
}

+ if (config->lock_key)
+ lock_key = config->lock_key;
+
if (fast_io) {
if (config->use_raw_spinlock) {
raw_spin_lock_init(&map->raw_spinlock);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 6194948ff9ed..872de9b3dcd5 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -347,6 +347,8 @@ typedef void (*regmap_unlock)(void *);
* @lock_arg: This field is passed as the only argument of lock/unlock
* functions (ignored in case regular lock/unlock functions
* are not overridden).
+ * @lock_key: Optional lockdep class for regmap's own lock, instead of
+ * one per call site. Must stay registered while the map exists.
* @max_register: Optional, specifies the maximum valid register address.
* @max_register_is_0: Optional, specifies that zero value in @max_register
* should be taken into account. This is a workaround to
@@ -445,6 +447,7 @@ struct regmap_config {
regmap_lock lock;
regmap_unlock unlock;
void *lock_arg;
+ struct lock_class_key *lock_key;

unsigned int max_register;
bool max_register_is_0;

--
2.55.0