linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/cma_debug: Avoid to use global cma_debugfs_root
@ 2019-02-21  4:01 Yue Hu
  2019-02-21  4:01 ` [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one() Yue Hu
  0 siblings, 1 reply; 8+ messages in thread
From: Yue Hu @ 2019-02-21  4:01 UTC (permalink / raw)
  To: akpm, mhocko, rientjes, joe; +Cc: linux-mm, linux-kernel, huyue2

From: Yue Hu <huyue2@yulong.com>

Currently cma_debugfs_root is at global space. That is unnecessary
since it will be only used by next cma_debugfs_add_one(). We can
just pass it to following calling, it will save global space. Also
remove useless idx parameter.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
 mm/cma_debug.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/mm/cma_debug.c b/mm/cma_debug.c
index f234672..2c2c869 100644
--- a/mm/cma_debug.c
+++ b/mm/cma_debug.c
@@ -21,8 +21,6 @@ struct cma_mem {
 	unsigned long n;
 };
 
-static struct dentry *cma_debugfs_root;
-
 static int cma_debugfs_get(void *data, u64 *val)
 {
 	unsigned long *p = data;
@@ -162,7 +160,7 @@ static int cma_alloc_write(void *data, u64 val)
 }
 DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n");
 
-static void cma_debugfs_add_one(struct cma *cma, int idx)
+static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
 {
 	struct dentry *tmp;
 	char name[16];
@@ -170,7 +168,7 @@ static void cma_debugfs_add_one(struct cma *cma, int idx)
 
 	scnprintf(name, sizeof(name), "cma-%s", cma->name);
 
-	tmp = debugfs_create_dir(name, cma_debugfs_root);
+	tmp = debugfs_create_dir(name, root_dentry);
 
 	debugfs_create_file("alloc", 0200, tmp, cma, &cma_alloc_fops);
 	debugfs_create_file("free", 0200, tmp, cma, &cma_free_fops);
@@ -188,6 +186,7 @@ static void cma_debugfs_add_one(struct cma *cma, int idx)
 
 static int __init cma_debugfs_init(void)
 {
+	struct dentry *cma_debugfs_root;
 	int i;
 
 	cma_debugfs_root = debugfs_create_dir("cma", NULL);
@@ -195,7 +194,7 @@ static int __init cma_debugfs_init(void)
 		return -ENOMEM;
 
 	for (i = 0; i < cma_area_count; i++)
-		cma_debugfs_add_one(&cma_areas[i], i);
+		cma_debugfs_add_one(&cma_areas[i], cma_debugfs_root);
 
 	return 0;
 }
-- 
1.9.1


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

* [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  4:01 [PATCH] mm/cma_debug: Avoid to use global cma_debugfs_root Yue Hu
@ 2019-02-21  4:01 ` Yue Hu
  2019-02-21  8:23   ` Michal Hocko
  0 siblings, 1 reply; 8+ messages in thread
From: Yue Hu @ 2019-02-21  4:01 UTC (permalink / raw)
  To: akpm, mhocko, rientjes, joe; +Cc: linux-mm, linux-kernel, huyue2

From: Yue Hu <huyue2@yulong.com>

If debugfs_create_dir() failed, the following debugfs_create_file()
will be meanless since it depends on non-NULL tmp dentry and it will
only waste CPU resource.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
 mm/cma_debug.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/cma_debug.c b/mm/cma_debug.c
index 2c2c869..3e9d984 100644
--- a/mm/cma_debug.c
+++ b/mm/cma_debug.c
@@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
 	scnprintf(name, sizeof(name), "cma-%s", cma->name);
 
 	tmp = debugfs_create_dir(name, root_dentry);
+	if (!tmp)
+		return;
 
 	debugfs_create_file("alloc", 0200, tmp, cma, &cma_alloc_fops);
 	debugfs_create_file("free", 0200, tmp, cma, &cma_free_fops);
-- 
1.9.1


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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  4:01 ` [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one() Yue Hu
@ 2019-02-21  8:23   ` Michal Hocko
  2019-02-21  8:36     ` Greg KH
  2019-02-21  8:56     ` Yue Hu
  0 siblings, 2 replies; 8+ messages in thread
From: Michal Hocko @ 2019-02-21  8:23 UTC (permalink / raw)
  To: Yue Hu; +Cc: akpm, rientjes, joe, linux-mm, linux-kernel, huyue2, Greg KH

On Thu 21-02-19 12:01:30, Yue Hu wrote:
> From: Yue Hu <huyue2@yulong.com>
> 
> If debugfs_create_dir() failed, the following debugfs_create_file()
> will be meanless since it depends on non-NULL tmp dentry and it will
> only waste CPU resource.

The file will be created in the debugfs root. But, more importantly.
Greg (CCed now) is working on removing the failure paths because he
believes they do not really matter for debugfs and they make code more
ugly. More importantly a check for NULL is not correct because you
get ERR_PTR after recent changes IIRC.

> 
> Signed-off-by: Yue Hu <huyue2@yulong.com>
> ---
>  mm/cma_debug.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/cma_debug.c b/mm/cma_debug.c
> index 2c2c869..3e9d984 100644
> --- a/mm/cma_debug.c
> +++ b/mm/cma_debug.c
> @@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
>  	scnprintf(name, sizeof(name), "cma-%s", cma->name);
>  
>  	tmp = debugfs_create_dir(name, root_dentry);
> +	if (!tmp)
> +		return;
>  
>  	debugfs_create_file("alloc", 0200, tmp, cma, &cma_alloc_fops);
>  	debugfs_create_file("free", 0200, tmp, cma, &cma_free_fops);
> -- 
> 1.9.1
> 

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  8:23   ` Michal Hocko
@ 2019-02-21  8:36     ` Greg KH
  2019-02-21  8:45       ` Michal Hocko
  2019-02-21  8:56     ` Yue Hu
  1 sibling, 1 reply; 8+ messages in thread
From: Greg KH @ 2019-02-21  8:36 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Yue Hu, akpm, rientjes, joe, linux-mm, linux-kernel, huyue2

On Thu, Feb 21, 2019 at 09:23:09AM +0100, Michal Hocko wrote:
> On Thu 21-02-19 12:01:30, Yue Hu wrote:
> > From: Yue Hu <huyue2@yulong.com>
> > 
> > If debugfs_create_dir() failed, the following debugfs_create_file()
> > will be meanless since it depends on non-NULL tmp dentry and it will
> > only waste CPU resource.
> 
> The file will be created in the debugfs root. But, more importantly.
> Greg (CCed now) is working on removing the failure paths because he
> believes they do not really matter for debugfs and they make code more
> ugly. More importantly a check for NULL is not correct because you
> get ERR_PTR after recent changes IIRC.
> 
> > 
> > Signed-off-by: Yue Hu <huyue2@yulong.com>
> > ---
> >  mm/cma_debug.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/mm/cma_debug.c b/mm/cma_debug.c
> > index 2c2c869..3e9d984 100644
> > --- a/mm/cma_debug.c
> > +++ b/mm/cma_debug.c
> > @@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
> >  	scnprintf(name, sizeof(name), "cma-%s", cma->name);
> >  
> >  	tmp = debugfs_create_dir(name, root_dentry);
> > +	if (!tmp)
> > +		return;

Ick, yes, this patch isn't ok, I've been doing lots of work to rip these
checks out :)

Thanks for catching this Michal.

greg k-h

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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  8:36     ` Greg KH
@ 2019-02-21  8:45       ` Michal Hocko
  2019-02-21  9:10         ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: Michal Hocko @ 2019-02-21  8:45 UTC (permalink / raw)
  To: Greg KH; +Cc: Yue Hu, akpm, rientjes, joe, linux-mm, linux-kernel, huyue2

On Thu 21-02-19 09:36:24, Greg KH wrote:
> On Thu, Feb 21, 2019 at 09:23:09AM +0100, Michal Hocko wrote:
> > On Thu 21-02-19 12:01:30, Yue Hu wrote:
> > > From: Yue Hu <huyue2@yulong.com>
> > > 
> > > If debugfs_create_dir() failed, the following debugfs_create_file()
> > > will be meanless since it depends on non-NULL tmp dentry and it will
> > > only waste CPU resource.
> > 
> > The file will be created in the debugfs root. But, more importantly.
> > Greg (CCed now) is working on removing the failure paths because he
> > believes they do not really matter for debugfs and they make code more
> > ugly. More importantly a check for NULL is not correct because you
> > get ERR_PTR after recent changes IIRC.
> > 
> > > 
> > > Signed-off-by: Yue Hu <huyue2@yulong.com>
> > > ---
> > >  mm/cma_debug.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/mm/cma_debug.c b/mm/cma_debug.c
> > > index 2c2c869..3e9d984 100644
> > > --- a/mm/cma_debug.c
> > > +++ b/mm/cma_debug.c
> > > @@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
> > >  	scnprintf(name, sizeof(name), "cma-%s", cma->name);
> > >  
> > >  	tmp = debugfs_create_dir(name, root_dentry);
> > > +	if (!tmp)
> > > +		return;
> 
> Ick, yes, this patch isn't ok, I've been doing lots of work to rip these
> checks out :)

Btw. I believe that it would help to clarify this stance in the
kerneldoc otherwise these checks will be returning back because the
general kernel development attitude is to check for errors. As I've said
previously debugfs being different is ugly but decision is yours.

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  8:23   ` Michal Hocko
  2019-02-21  8:36     ` Greg KH
@ 2019-02-21  8:56     ` Yue Hu
  2019-02-21  9:10       ` Greg KH
  1 sibling, 1 reply; 8+ messages in thread
From: Yue Hu @ 2019-02-21  8:56 UTC (permalink / raw)
  To: Michal Hocko; +Cc: akpm, rientjes, joe, linux-mm, linux-kernel, huyue2, Greg KH

On Thu, 21 Feb 2019 09:23:09 +0100
Michal Hocko <mhocko@kernel.org> wrote:

> On Thu 21-02-19 12:01:30, Yue Hu wrote:
> > From: Yue Hu <huyue2@yulong.com>
> > 
> > If debugfs_create_dir() failed, the following debugfs_create_file()
> > will be meanless since it depends on non-NULL tmp dentry and it will
> > only waste CPU resource.  
> 
> The file will be created in the debugfs root. But, more importantly.
> Greg (CCed now) is working on removing the failure paths because he
> believes they do not really matter for debugfs and they make code more
> ugly. More importantly a check for NULL is not correct because you
> get ERR_PTR after recent changes IIRC.

Same check logic in cma_debugfs_init(), i'm just finding they do not stay
the same.

> 
> > 
> > Signed-off-by: Yue Hu <huyue2@yulong.com>
> > ---
> >  mm/cma_debug.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/mm/cma_debug.c b/mm/cma_debug.c
> > index 2c2c869..3e9d984 100644
> > --- a/mm/cma_debug.c
> > +++ b/mm/cma_debug.c
> > @@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
> >  	scnprintf(name, sizeof(name), "cma-%s", cma->name);
> >  
> >  	tmp = debugfs_create_dir(name, root_dentry);
> > +	if (!tmp)
> > +		return;
> >  
> >  	debugfs_create_file("alloc", 0200, tmp, cma, &cma_alloc_fops);
> >  	debugfs_create_file("free", 0200, tmp, cma, &cma_free_fops);
> > -- 
> > 1.9.1
> >   
> 


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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  8:56     ` Yue Hu
@ 2019-02-21  9:10       ` Greg KH
  0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2019-02-21  9:10 UTC (permalink / raw)
  To: Yue Hu; +Cc: Michal Hocko, akpm, rientjes, joe, linux-mm, linux-kernel, huyue2

On Thu, Feb 21, 2019 at 04:56:42PM +0800, Yue Hu wrote:
> On Thu, 21 Feb 2019 09:23:09 +0100
> Michal Hocko <mhocko@kernel.org> wrote:
> 
> > On Thu 21-02-19 12:01:30, Yue Hu wrote:
> > > From: Yue Hu <huyue2@yulong.com>
> > > 
> > > If debugfs_create_dir() failed, the following debugfs_create_file()
> > > will be meanless since it depends on non-NULL tmp dentry and it will
> > > only waste CPU resource.  
> > 
> > The file will be created in the debugfs root. But, more importantly.
> > Greg (CCed now) is working on removing the failure paths because he
> > believes they do not really matter for debugfs and they make code more
> > ugly. More importantly a check for NULL is not correct because you
> > get ERR_PTR after recent changes IIRC.
> 
> Same check logic in cma_debugfs_init(), i'm just finding they do not stay
> the same.

I have patches to fix that up as well :)

thanks,

greg k-h

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

* Re: [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one()
  2019-02-21  8:45       ` Michal Hocko
@ 2019-02-21  9:10         ` Greg KH
  0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2019-02-21  9:10 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Yue Hu, akpm, rientjes, joe, linux-mm, linux-kernel, huyue2

On Thu, Feb 21, 2019 at 09:45:25AM +0100, Michal Hocko wrote:
> On Thu 21-02-19 09:36:24, Greg KH wrote:
> > On Thu, Feb 21, 2019 at 09:23:09AM +0100, Michal Hocko wrote:
> > > On Thu 21-02-19 12:01:30, Yue Hu wrote:
> > > > From: Yue Hu <huyue2@yulong.com>
> > > > 
> > > > If debugfs_create_dir() failed, the following debugfs_create_file()
> > > > will be meanless since it depends on non-NULL tmp dentry and it will
> > > > only waste CPU resource.
> > > 
> > > The file will be created in the debugfs root. But, more importantly.
> > > Greg (CCed now) is working on removing the failure paths because he
> > > believes they do not really matter for debugfs and they make code more
> > > ugly. More importantly a check for NULL is not correct because you
> > > get ERR_PTR after recent changes IIRC.
> > > 
> > > > 
> > > > Signed-off-by: Yue Hu <huyue2@yulong.com>
> > > > ---
> > > >  mm/cma_debug.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > > 
> > > > diff --git a/mm/cma_debug.c b/mm/cma_debug.c
> > > > index 2c2c869..3e9d984 100644
> > > > --- a/mm/cma_debug.c
> > > > +++ b/mm/cma_debug.c
> > > > @@ -169,6 +169,8 @@ static void cma_debugfs_add_one(struct cma *cma, struct dentry *root_dentry)
> > > >  	scnprintf(name, sizeof(name), "cma-%s", cma->name);
> > > >  
> > > >  	tmp = debugfs_create_dir(name, root_dentry);
> > > > +	if (!tmp)
> > > > +		return;
> > 
> > Ick, yes, this patch isn't ok, I've been doing lots of work to rip these
> > checks out :)
> 
> Btw. I believe that it would help to clarify this stance in the
> kerneldoc otherwise these checks will be returning back because the
> general kernel development attitude is to check for errors. As I've said
> previously debugfs being different is ugly but decision is yours.

Yes, I'll be doing that, thanks for the reminder.

greg k-h

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

end of thread, other threads:[~2019-02-21  9:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21  4:01 [PATCH] mm/cma_debug: Avoid to use global cma_debugfs_root Yue Hu
2019-02-21  4:01 ` [PATCH] mm/cma_debug: Check for null tmp in cma_debugfs_add_one() Yue Hu
2019-02-21  8:23   ` Michal Hocko
2019-02-21  8:36     ` Greg KH
2019-02-21  8:45       ` Michal Hocko
2019-02-21  9:10         ` Greg KH
2019-02-21  8:56     ` Yue Hu
2019-02-21  9:10       ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).