Skip to contentSkip to conversation

regmap: detach regmap from dev on regmap_exit

PATCH Superseded Cosmin Tanislav 2 participants 3 messages Nov 22, 2024 – Nov 25, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: detach regmap from dev on regmap_exit

At the end of __regmap_init(), if dev is not NULL, regmap_attach_dev() is called, which adds a devres reference to the regmap, to be able to retrieve a dev's regmap by name using dev_get_regmap().

When calling regmap_exit, the opposite does not happen, and the reference is kept until the dev is detached.

Add a regmap_detach_dev() function, export it and call it in regmap_exit(), to make sure that the devres reference is not kept.

---
 drivers/base/regmap/regmap.c | 13 +++++++++++++
 include/linux/regmap.h       |  1 +
 2 files changed, 14 insertions(+)
drivers/base/regmap/regmap.c +13 -0
index 53131a7ede0a6..6205c475ed594 100644
@@ -598,6 +598,18 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
 }
 EXPORT_SYMBOL_GPL(regmap_attach_dev);
 
+static int dev_get_regmap_match(struct device *dev, void *res, void *data);
+
+int regmap_detach_dev(struct device *dev, struct regmap *map)
+{
+	if (!dev)
+		return 0;
+
+	return devres_release(dev, dev_get_regmap_release,
+			      dev_get_regmap_match, (void *)map->name);
+}
+EXPORT_SYMBOL_GPL(regmap_detach_dev);
+
 static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus,
 					const struct regmap_config *config)
 {
@@ -1445,6 +1457,7 @@ void regmap_exit(struct regmap *map)
 {
 	struct regmap_async *async;
 
+	regmap_detach_dev(map->dev, map);
 	regcache_exit(map);
 
 	regmap_debugfs_exit(map);
include/linux/regmap.h +1 -0
index fd41baccbf3eb..2a72111f33c4f 100644
@@ -771,6 +771,7 @@ struct regmap *__devm_regmap_init_fsi(struct fsi_device *fsi_dev,
 				dev, bus, bus_context, config)
 int regmap_attach_dev(struct device *dev, struct regmap *map,
 		      const struct regmap_config *config);
+int regmap_detach_dev(struct device *dev, struct regmap *map);
 
 /**
  * regmap_init_i2c() - Initialise register map
Signature · 1 line
2.47.0
maintainer
#1 lore raw

drivers/base/regmap/regmap.c int regmap_attach_dev(struct device *dev, struct regmap *map, · line 611

Quoted 9 lines · Cosmin Tanislav
drivers/base/regmap/regmap.c +9 -0
+int regmap_detach_dev(struct device *dev, struct regmap *map)
+{
+	if (!dev)
+		return 0;
+
+	return devres_release(dev, dev_get_regmap_release,
+			      dev_get_regmap_match, (void *)map->name);
+}
+EXPORT_SYMBOL_GPL(regmap_detach_dev);

Why is this exported?

drivers/base/regmap/regmap.c void regmap_exit(struct regmap *map) · line 1463

Quoted 8 lines
drivers/base/regmap/regmap.c +1 -0
@@ -1445,6 +1457,7 @@ void regmap_exit(struct regmap *map)
 {
 	struct regmap_async *async;
 
+	regmap_detach_dev(map->dev, map);
 	regcache_exit(map);
 
 	regmap_debugfs_exit(map);

The one caller is in the same file so it can be static.

#2 lore raw
Quoted 14 lines · Mark Brown

drivers/base/regmap/regmap.c int regmap_attach_dev(struct device *dev, struct regmap *map, · line 611

Quoted 9 lines · Cosmin Tanislav
drivers/base/regmap/regmap.c +9 -0
+int regmap_detach_dev(struct device *dev, struct regmap *map)
+{
+	if (!dev)
+		return 0;
+
+	return devres_release(dev, dev_get_regmap_release,
+			      dev_get_regmap_match, (void *)map->name);
+}
+EXPORT_SYMBOL_GPL(regmap_detach_dev);

Why is this exported?

I only did it because regmap_attach_dev() was also exported. I can make it static for V2.

Quoted 10 lines

drivers/base/regmap/regmap.c void regmap_exit(struct regmap *map) · line 1463

Quoted 8 lines
drivers/base/regmap/regmap.c +1 -0
@@ -1445,6 +1457,7 @@ void regmap_exit(struct regmap *map)
  {
  	struct regmap_async *async;
 
+	regmap_detach_dev(map->dev, map);
  	regcache_exit(map);
 
  	regmap_debugfs_exit(map);

The one caller is in the same file so it can be static.