Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-22 Thread Mark Brown
On Fri, May 19, 2017 at 11:36:00PM -0700, Stefan Agner wrote:

> The case I observed this is when reprobing
> drivers/pinctrl/freescale/pinctrl-imx.c. In this driver
> regmap_attach_dev is used in imx_pinctrl_probe. When the driver gets
> removed and probed again, the above warning appears since the debugfs
> entries have not been removed in between...

There's a jump somewhere between the problem you're reporting here and
devres being a fix - surely the problem here is that we're not cleaning
things up properly on destruction of the regmap?

> Afaics, at least for external users, using devres for debugfs makes
> sense since regmap (m) is already using devres...

We should be able to destroy a regmap separately to removal of a device.
If we're requiring managed access something is wrong.

> We can drop this change, but then we have to add a private version of
> regmap_attach_dev which does not add resource managed cleanup of
> regmap_debugfs_exit...

I'm sorry but I'm still not following the logic here.


signature.asc
Description: PGP signature


Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-22 Thread Mark Brown
On Fri, May 19, 2017 at 11:36:00PM -0700, Stefan Agner wrote:

> The case I observed this is when reprobing
> drivers/pinctrl/freescale/pinctrl-imx.c. In this driver
> regmap_attach_dev is used in imx_pinctrl_probe. When the driver gets
> removed and probed again, the above warning appears since the debugfs
> entries have not been removed in between...

There's a jump somewhere between the problem you're reporting here and
devres being a fix - surely the problem here is that we're not cleaning
things up properly on destruction of the regmap?

> Afaics, at least for external users, using devres for debugfs makes
> sense since regmap (m) is already using devres...

We should be able to destroy a regmap separately to removal of a device.
If we're requiring managed access something is wrong.

> We can drop this change, but then we have to add a private version of
> regmap_attach_dev which does not add resource managed cleanup of
> regmap_debugfs_exit...

I'm sorry but I'm still not following the logic here.


signature.asc
Description: PGP signature


Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-20 Thread Stefan Agner
On 2017-05-19 09:46, Mark Brown wrote:
> On Mon, May 15, 2017 at 01:08:27AM -0700, Stefan Agner wrote:
> 
>> Instead of manually cleanup regmap_debugfs_exit, use devres action
>> to do the cleanup. This also works for external users of
>> regmap_attach_dev.
> 
> Why?  It's also not clear to me that this will work if something creates
> a regmap, frees it and then creates another one on the same device
> without a reprobe.  There have been a few devices that did that as part
> of enumeration of the device, they created a simple regmap to read ID
> registers then replaced it with a more complete description of the
> actual device they found.
> 
>> This fixes warnings when reloading certain drivers making use of
>> regmap_debugfs_exit:
>>   imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory
> 
> How?  (and this should be in the changelog.)
> 

The case I observed this is when reprobing
drivers/pinctrl/freescale/pinctrl-imx.c. In this driver
regmap_attach_dev is used in imx_pinctrl_probe. When the driver gets
removed and probed again, the above warning appears since the debugfs
entries have not been removed in between...

Afaics, at least for external users, using devres for debugfs makes
sense since regmap (m) is already using devres...

>> @@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
>>  struct regmap_async *async;
>>
>>  regcache_exit(map);
>> -regmap_debugfs_exit(map);
>>  regmap_range_exit(map);
>>  if (map->bus && map->bus->free_context)
>>  map->bus->free_context(map->bus_context);
> 
> This isn't obviously correct, it reorders the cleanup such that the
> debugfs entries will only get removed when the device is removed which
> means that the debugfs entries will be hanging around after the regmap
> has been deinstantiated.  In the common case where it too was allocated
> as a managed resource that'll work out but if for some reason it wasn't
> allocated as as managed resource then the debug entry will be
> dealocated after the regmap.

Hm, yeah I see that is a problem.

We can drop this change, but then we have to add a private version of
regmap_attach_dev which does not add resource managed cleanup of
regmap_debugfs_exit...

--
Stefan


Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-20 Thread Stefan Agner
On 2017-05-19 09:46, Mark Brown wrote:
> On Mon, May 15, 2017 at 01:08:27AM -0700, Stefan Agner wrote:
> 
>> Instead of manually cleanup regmap_debugfs_exit, use devres action
>> to do the cleanup. This also works for external users of
>> regmap_attach_dev.
> 
> Why?  It's also not clear to me that this will work if something creates
> a regmap, frees it and then creates another one on the same device
> without a reprobe.  There have been a few devices that did that as part
> of enumeration of the device, they created a simple regmap to read ID
> registers then replaced it with a more complete description of the
> actual device they found.
> 
>> This fixes warnings when reloading certain drivers making use of
>> regmap_debugfs_exit:
>>   imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory
> 
> How?  (and this should be in the changelog.)
> 

The case I observed this is when reprobing
drivers/pinctrl/freescale/pinctrl-imx.c. In this driver
regmap_attach_dev is used in imx_pinctrl_probe. When the driver gets
removed and probed again, the above warning appears since the debugfs
entries have not been removed in between...

Afaics, at least for external users, using devres for debugfs makes
sense since regmap (m) is already using devres...

>> @@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
>>  struct regmap_async *async;
>>
>>  regcache_exit(map);
>> -regmap_debugfs_exit(map);
>>  regmap_range_exit(map);
>>  if (map->bus && map->bus->free_context)
>>  map->bus->free_context(map->bus_context);
> 
> This isn't obviously correct, it reorders the cleanup such that the
> debugfs entries will only get removed when the device is removed which
> means that the debugfs entries will be hanging around after the regmap
> has been deinstantiated.  In the common case where it too was allocated
> as a managed resource that'll work out but if for some reason it wasn't
> allocated as as managed resource then the debug entry will be
> dealocated after the regmap.

Hm, yeah I see that is a problem.

We can drop this change, but then we have to add a private version of
regmap_attach_dev which does not add resource managed cleanup of
regmap_debugfs_exit...

--
Stefan


Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-19 Thread Mark Brown
On Mon, May 15, 2017 at 01:08:27AM -0700, Stefan Agner wrote:

> Instead of manually cleanup regmap_debugfs_exit, use devres action
> to do the cleanup. This also works for external users of
> regmap_attach_dev.

Why?  It's also not clear to me that this will work if something creates
a regmap, frees it and then creates another one on the same device
without a reprobe.  There have been a few devices that did that as part
of enumeration of the device, they created a simple regmap to read ID
registers then replaced it with a more complete description of the
actual device they found.

> This fixes warnings when reloading certain drivers making use of
> regmap_debugfs_exit:
>   imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory

How?  (and this should be in the changelog.)

> @@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
>   struct regmap_async *async;
>  
>   regcache_exit(map);
> - regmap_debugfs_exit(map);
>   regmap_range_exit(map);
>   if (map->bus && map->bus->free_context)
>   map->bus->free_context(map->bus_context);

This isn't obviously correct, it reorders the cleanup such that the
debugfs entries will only get removed when the device is removed which
means that the debugfs entries will be hanging around after the regmap
has been deinstantiated.  In the common case where it too was allocated
as a managed resource that'll work out but if for some reason it wasn't
allocated as as managed resource then the debugfs entry will be
dealocated after the regmap.

We should also be doing the debugfs cleanup before the regcache cleanup
but that's a separate and preexisting bug.


signature.asc
Description: PGP signature


Re: [PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-19 Thread Mark Brown
On Mon, May 15, 2017 at 01:08:27AM -0700, Stefan Agner wrote:

> Instead of manually cleanup regmap_debugfs_exit, use devres action
> to do the cleanup. This also works for external users of
> regmap_attach_dev.

Why?  It's also not clear to me that this will work if something creates
a regmap, frees it and then creates another one on the same device
without a reprobe.  There have been a few devices that did that as part
of enumeration of the device, they created a simple regmap to read ID
registers then replaced it with a more complete description of the
actual device they found.

> This fixes warnings when reloading certain drivers making use of
> regmap_debugfs_exit:
>   imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory

How?  (and this should be in the changelog.)

> @@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
>   struct regmap_async *async;
>  
>   regcache_exit(map);
> - regmap_debugfs_exit(map);
>   regmap_range_exit(map);
>   if (map->bus && map->bus->free_context)
>   map->bus->free_context(map->bus_context);

This isn't obviously correct, it reorders the cleanup such that the
debugfs entries will only get removed when the device is removed which
means that the debugfs entries will be hanging around after the regmap
has been deinstantiated.  In the common case where it too was allocated
as a managed resource that'll work out but if for some reason it wasn't
allocated as as managed resource then the debugfs entry will be
dealocated after the regmap.

We should also be doing the debugfs cleanup before the regcache cleanup
but that's a separate and preexisting bug.


signature.asc
Description: PGP signature


[PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-15 Thread Stefan Agner
Instead of manually cleanup regmap_debugfs_exit, use devres action
to do the cleanup. This also works for external users of
regmap_attach_dev.

Signed-off-by: Stefan Agner 
---
The cast is not that pretty, but I found it better than making
regmap_debugfs_exit type unsafe...

This fixes warnings when reloading certain drivers making use of
regmap_debugfs_exit:
  imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory

--
Stefan

 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index b9a779a4a739..0e32e0e2f00a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -528,6 +528,7 @@ int regmap_attach_dev(struct device *dev, struct regmap 
*map,
return -ENOMEM;
}
*m = map;
+   devm_add_action(dev, (void (*)(void *))regmap_debugfs_exit, map);
devres_add(dev, m);
 
return 0;
@@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
struct regmap_async *async;
 
regcache_exit(map);
-   regmap_debugfs_exit(map);
regmap_range_exit(map);
if (map->bus && map->bus->free_context)
map->bus->free_context(map->bus_context);
-- 
2.13.0



[PATCH] regmap: add regmap_debugfs_exit as devres action

2017-05-15 Thread Stefan Agner
Instead of manually cleanup regmap_debugfs_exit, use devres action
to do the cleanup. This also works for external users of
regmap_attach_dev.

Signed-off-by: Stefan Agner 
---
The cast is not that pretty, but I found it better than making
regmap_debugfs_exit type unsafe...

This fixes warnings when reloading certain drivers making use of
regmap_debugfs_exit:
  imx7d-pinctrl 3033.iomuxc: Failed to create debugfs directory

--
Stefan

 drivers/base/regmap/regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index b9a779a4a739..0e32e0e2f00a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -528,6 +528,7 @@ int regmap_attach_dev(struct device *dev, struct regmap 
*map,
return -ENOMEM;
}
*m = map;
+   devm_add_action(dev, (void (*)(void *))regmap_debugfs_exit, map);
devres_add(dev, m);
 
return 0;
@@ -1215,7 +1216,6 @@ void regmap_exit(struct regmap *map)
struct regmap_async *async;
 
regcache_exit(map);
-   regmap_debugfs_exit(map);
regmap_range_exit(map);
if (map->bus && map->bus->free_context)
map->bus->free_context(map->bus_context);
-- 
2.13.0