mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PM / Domains: Ensure genpd name is set before creating debugfs entry
@ 2017-07-28 18:48 Dave Gerlach
  2017-07-28 18:55 ` Dave Gerlach
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Gerlach @ 2017-07-28 18:48 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Kevin Hilman
  Cc: linux-kernel, linux-pm, Thara Gopinath, Dave Gerlach

Commit b6a1d093f96b ("PM / Domains: Extend generic power domain
debugfs") extends the existing generic power domain debugfs to provide
more information about each genpd, however it creates a debugfs
directory for each based on the name of the genpd. While it is a good
idea to populate the name field of each genpd, up until this commit it
was not required. However, attempting to call debugfs_create_dir with a
null name value causes a NULL pointer dereference panic.

In order to keep things working as they did before the aforementioned
patch, check to see if name has been populated and if not, skip creating
the extended debugfs info path and warn that name is needed to get this
extended info.

Fixes: b6a1d093f96b ("PM / Domains: Extend generic power domain debugfs")
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
---
 drivers/base/power/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 43fd08e50ae9..77f7ea6f7fc3 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2575,6 +2575,12 @@ static int __init pm_genpd_debug_init(void)
 		return -ENOMEM;
 
 	list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
+		if (!genpd->name) {
+			pr_warn("%s: Must populate name of genpd for extended debugfs info.",
+				__func__);
+			continue;
+		}
+
 		d = debugfs_create_dir(genpd->name, pm_genpd_debugfs_dir);
 		if (!d)
 			return -ENOMEM;
-- 
2.13.0

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

* Re: [PATCH] PM / Domains: Ensure genpd name is set before creating debugfs entry
  2017-07-28 18:48 [PATCH] PM / Domains: Ensure genpd name is set before creating debugfs entry Dave Gerlach
@ 2017-07-28 18:55 ` Dave Gerlach
  2017-07-29  8:04   ` Ulf Hansson
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Gerlach @ 2017-07-28 18:55 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Kevin Hilman
  Cc: linux-kernel, linux-pm, Thara Gopinath

Hi,
On 07/28/2017 01:48 PM, Dave Gerlach wrote:
> Commit b6a1d093f96b ("PM / Domains: Extend generic power domain
> debugfs") extends the existing generic power domain debugfs to provide
> more information about each genpd, however it creates a debugfs
> directory for each based on the name of the genpd. While it is a good
> idea to populate the name field of each genpd, up until this commit it
> was not required. However, attempting to call debugfs_create_dir with a
> null name value causes a NULL pointer dereference panic.
> 
> In order to keep things working as they did before the aforementioned
> patch, check to see if name has been populated and if not, skip creating
> the extended debugfs info path and warn that name is needed to get this
> extended info.
> 
> Fixes: b6a1d093f96b ("PM / Domains: Extend generic power domain debugfs")
> Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
> ---

As changelog describes, commit b6a1d093f96b ("PM / Domains: Extend generic power
domain debugfs") currently causes a NULL pointer dereference panic if no name is
assigned for a struct generic_pm_domain registered with the framework. Before
this patch no name was required, so this patch is a first attempt to keep things
that way and just warn the user that they can't get extended debugfs info
without providing a genpd name.

Of course a name is always a good idea, so I'm not sure if this patch is how we
want to go about preventing this panic or perhaps just making the name mandatory
and checking during probe, but I figured I'd kick the discussion off with a
suggestion by sending this patch.

Regards,
Dave

>  drivers/base/power/domain.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 43fd08e50ae9..77f7ea6f7fc3 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2575,6 +2575,12 @@ static int __init pm_genpd_debug_init(void)
>  		return -ENOMEM;
>  
>  	list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
> +		if (!genpd->name) {
> +			pr_warn("%s: Must populate name of genpd for extended debugfs info.",
> +				__func__);
> +			continue;
> +		}
> +
>  		d = debugfs_create_dir(genpd->name, pm_genpd_debugfs_dir);
>  		if (!d)
>  			return -ENOMEM;
> 

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

* Re: [PATCH] PM / Domains: Ensure genpd name is set before creating debugfs entry
  2017-07-28 18:55 ` Dave Gerlach
@ 2017-07-29  8:04   ` Ulf Hansson
  0 siblings, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2017-07-29  8:04 UTC (permalink / raw)
  To: Dave Gerlach
  Cc: Rafael J . Wysocki, Kevin Hilman, linux-kernel, linux-pm, Thara Gopinath

On 28 July 2017 at 20:55, Dave Gerlach <d-gerlach@ti.com> wrote:
> Hi,
> On 07/28/2017 01:48 PM, Dave Gerlach wrote:
>> Commit b6a1d093f96b ("PM / Domains: Extend generic power domain
>> debugfs") extends the existing generic power domain debugfs to provide
>> more information about each genpd, however it creates a debugfs
>> directory for each based on the name of the genpd. While it is a good
>> idea to populate the name field of each genpd, up until this commit it
>> was not required. However, attempting to call debugfs_create_dir with a
>> null name value causes a NULL pointer dereference panic.
>>
>> In order to keep things working as they did before the aforementioned
>> patch, check to see if name has been populated and if not, skip creating
>> the extended debugfs info path and warn that name is needed to get this
>> extended info.
>>
>> Fixes: b6a1d093f96b ("PM / Domains: Extend generic power domain debugfs")
>> Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
>> ---
>
> As changelog describes, commit b6a1d093f96b ("PM / Domains: Extend generic power
> domain debugfs") currently causes a NULL pointer dereference panic if no name is
> assigned for a struct generic_pm_domain registered with the framework. Before
> this patch no name was required, so this patch is a first attempt to keep things
> that way and just warn the user that they can't get extended debugfs info
> without providing a genpd name.
>
> Of course a name is always a good idea, so I'm not sure if this patch is how we
> want to go about preventing this panic or perhaps just making the name mandatory
> and checking during probe, but I figured I'd kick the discussion off with a
> suggestion by sending this patch.

Instead of making it mandatory, why not assign ->name a generic name
(genpd0, genpd1, genpd2, etc ) in case it isn't set.

In that way, all debugfs prints using ->name, should at least show
something... and the bug you report should also be fixed..

Kind regards
Uffe

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

end of thread, other threads:[~2017-07-29  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28 18:48 [PATCH] PM / Domains: Ensure genpd name is set before creating debugfs entry Dave Gerlach
2017-07-28 18:55 ` Dave Gerlach
2017-07-29  8:04   ` Ulf Hansson

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

all inboxes | Powered by JetHome®