public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regmap: detach regmap from dev on regmap_exit
@ 2024-11-22 15:16 Cosmin Tanislav
  2024-11-25 12:22 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Cosmin Tanislav @ 2024-11-22 15:16 UTC (permalink / raw)
  Cc: Mark Brown, Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel,
	Cosmin Tanislav

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.

Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
---
 drivers/base/regmap/regmap.c | 13 +++++++++++++
 include/linux/regmap.h       |  1 +
 2 files changed, 14 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 53131a7ede0a6..6205c475ed594 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -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);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index fd41baccbf3eb..2a72111f33c4f 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -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
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] regmap: detach regmap from dev on regmap_exit
  2024-11-22 15:16 [PATCH] regmap: detach regmap from dev on regmap_exit Cosmin Tanislav
@ 2024-11-25 12:22 ` Mark Brown
  2024-11-25 20:44   ` Cosmin Tanislav
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2024-11-25 12:22 UTC (permalink / raw)
  To: Cosmin Tanislav; +Cc: Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On Fri, Nov 22, 2024 at 05:16:30PM +0200, Cosmin Tanislav wrote:

> +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?

> @@ -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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regmap: detach regmap from dev on regmap_exit
  2024-11-25 12:22 ` Mark Brown
@ 2024-11-25 20:44   ` Cosmin Tanislav
  0 siblings, 0 replies; 3+ messages in thread
From: Cosmin Tanislav @ 2024-11-25 20:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel



On 11/25/24 2:22 PM, Mark Brown wrote:
> On Fri, Nov 22, 2024 at 05:16:30PM +0200, Cosmin Tanislav wrote:
> 
>> +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.

>> @@ -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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-25 20:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-22 15:16 [PATCH] regmap: detach regmap from dev on regmap_exit Cosmin Tanislav
2024-11-25 12:22 ` Mark Brown
2024-11-25 20:44   ` Cosmin Tanislav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox