linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions
@ 2019-06-12 15:35 Greg Kroah-Hartman
  2019-06-12 16:58 ` Joel Fernandes
  2019-06-14 12:58 ` [tip:core/debugobjects] debugobjects: No need to check return value of debugfs_create() tip-bot for Greg Kroah-Hartman
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-12 15:35 UTC (permalink / raw)
  To: Qian Cai, Thomas Gleixner, Andrew Morton, Waiman Long,
	Joel Fernandes (Google),
	Zhong Jiang
  Cc: linux-kernel

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Cc: Qian Cai <cai@gmx.us>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Waiman Long <longman@redhat.com>
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Cc: Zhong Jiang <zhongjiang@huawei.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 lib/debugobjects.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 55437fd5128b..2ac42286cd08 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {
 
 static int __init debug_objects_init_debugfs(void)
 {
-	struct dentry *dbgdir, *dbgstats;
+	struct dentry *dbgdir;
 
 	if (!debug_objects_enabled)
 		return 0;
 
 	dbgdir = debugfs_create_dir("debug_objects", NULL);
-	if (!dbgdir)
-		return -ENOMEM;
 
-	dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
-				       &debug_stats_fops);
-	if (!dbgstats)
-		goto err;
+	debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops);
 
 	return 0;
-
-err:
-	debugfs_remove(dbgdir);
-
-	return -ENOMEM;
 }
 __initcall(debug_objects_init_debugfs);
 
-- 
2.22.0


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

* Re: [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions
  2019-06-12 15:35 [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions Greg Kroah-Hartman
@ 2019-06-12 16:58 ` Joel Fernandes
  2019-06-12 17:10   ` Greg Kroah-Hartman
  2019-06-14 12:58 ` [tip:core/debugobjects] debugobjects: No need to check return value of debugfs_create() tip-bot for Greg Kroah-Hartman
  1 sibling, 1 reply; 5+ messages in thread
From: Joel Fernandes @ 2019-06-12 16:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Qian Cai, Thomas Gleixner, Andrew Morton, Waiman Long,
	Zhong Jiang, linux-kernel

On Wed, Jun 12, 2019 at 05:35:13PM +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 
> Cc: Qian Cai <cai@gmx.us>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Waiman Long <longman@redhat.com>
> Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
> Cc: Zhong Jiang <zhongjiang@huawei.com>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  lib/debugobjects.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/debugobjects.c b/lib/debugobjects.c
> index 55437fd5128b..2ac42286cd08 100644
> --- a/lib/debugobjects.c
> +++ b/lib/debugobjects.c
> @@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {
>  
>  static int __init debug_objects_init_debugfs(void)
>  {
> -	struct dentry *dbgdir, *dbgstats;
> +	struct dentry *dbgdir;
>  
>  	if (!debug_objects_enabled)
>  		return 0;
>  
>  	dbgdir = debugfs_create_dir("debug_objects", NULL);
> -	if (!dbgdir)
> -		return -ENOMEM;
>  
> -	dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
> -				       &debug_stats_fops);
> -	if (!dbgstats)
> -		goto err;
> +	debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops);


One weirdness is, if dbgdir is ever NULL, then debugfs_create_file() may end
up creating the stats file in the root.

In debugfs_create_file():
        /* If the parent is not specified, we create it in the root.
         * We need the root dentry to do this, which is in the super
         * block. A pointer to that is in the struct vfsmount that we
         * have around.
         */
        if (!parent)
                parent = debugfs_mount->mnt_root;

But I guess that's not a major issue since its debugfs :-) So LGTM,
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks,

 - Joel

>  
>  	return 0;
> -
> -err:
> -	debugfs_remove(dbgdir);
> -
> -	return -ENOMEM;
>  }
>  __initcall(debug_objects_init_debugfs);
>  
> -- 
> 2.22.0
> 

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

* Re: [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions
  2019-06-12 16:58 ` Joel Fernandes
@ 2019-06-12 17:10   ` Greg Kroah-Hartman
  2019-06-12 17:26     ` Joel Fernandes
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-12 17:10 UTC (permalink / raw)
  To: Joel Fernandes
  Cc: Qian Cai, Thomas Gleixner, Andrew Morton, Waiman Long,
	Zhong Jiang, linux-kernel

On Wed, Jun 12, 2019 at 12:58:19PM -0400, Joel Fernandes wrote:
> On Wed, Jun 12, 2019 at 05:35:13PM +0200, Greg Kroah-Hartman wrote:
> > When calling debugfs functions, there is no need to ever check the
> > return value.  The function can work or not, but the code logic should
> > never do something different based on this.
> > 
> > Cc: Qian Cai <cai@gmx.us>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Waiman Long <longman@redhat.com>
> > Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
> > Cc: Zhong Jiang <zhongjiang@huawei.com>
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >  lib/debugobjects.c | 14 ++------------
> >  1 file changed, 2 insertions(+), 12 deletions(-)
> > 
> > diff --git a/lib/debugobjects.c b/lib/debugobjects.c
> > index 55437fd5128b..2ac42286cd08 100644
> > --- a/lib/debugobjects.c
> > +++ b/lib/debugobjects.c
> > @@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {
> >  
> >  static int __init debug_objects_init_debugfs(void)
> >  {
> > -	struct dentry *dbgdir, *dbgstats;
> > +	struct dentry *dbgdir;
> >  
> >  	if (!debug_objects_enabled)
> >  		return 0;
> >  
> >  	dbgdir = debugfs_create_dir("debug_objects", NULL);
> > -	if (!dbgdir)
> > -		return -ENOMEM;
> >  
> > -	dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
> > -				       &debug_stats_fops);
> > -	if (!dbgstats)
> > -		goto err;
> > +	debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops);
> 
> 
> One weirdness is, if dbgdir is ever NULL, then debugfs_create_file() may end
> up creating the stats file in the root.

Yes, but dbgdir can not be NULL.

> In debugfs_create_file():
>         /* If the parent is not specified, we create it in the root.
>          * We need the root dentry to do this, which is in the super
>          * block. A pointer to that is in the struct vfsmount that we
>          * have around.
>          */
>         if (!parent)
>                 parent = debugfs_mount->mnt_root;

Yes, but debugfs_create_dir() will never return NULL.

> But I guess that's not a major issue since its debugfs :-) So LGTM,

Yup!

> Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks for the review.

greg k-h

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

* Re: [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions
  2019-06-12 17:10   ` Greg Kroah-Hartman
@ 2019-06-12 17:26     ` Joel Fernandes
  0 siblings, 0 replies; 5+ messages in thread
From: Joel Fernandes @ 2019-06-12 17:26 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Qian Cai, Thomas Gleixner, Andrew Morton, Waiman Long, Zhong Jiang, LKML

On Wed, Jun 12, 2019 at 1:10 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Wed, Jun 12, 2019 at 12:58:19PM -0400, Joel Fernandes wrote:
> > On Wed, Jun 12, 2019 at 05:35:13PM +0200, Greg Kroah-Hartman wrote:
> > > When calling debugfs functions, there is no need to ever check the
> > > return value.  The function can work or not, but the code logic should
> > > never do something different based on this.
> > >
> > > Cc: Qian Cai <cai@gmx.us>
> > > Cc: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: Andrew Morton <akpm@linux-foundation.org>
> > > Cc: Waiman Long <longman@redhat.com>
> > > Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
> > > Cc: Zhong Jiang <zhongjiang@huawei.com>
> > > Cc: linux-kernel@vger.kernel.org
> > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > ---
> > >  lib/debugobjects.c | 14 ++------------
> > >  1 file changed, 2 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/lib/debugobjects.c b/lib/debugobjects.c
> > > index 55437fd5128b..2ac42286cd08 100644
> > > --- a/lib/debugobjects.c
> > > +++ b/lib/debugobjects.c
> > > @@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {
> > >
> > >  static int __init debug_objects_init_debugfs(void)
> > >  {
> > > -   struct dentry *dbgdir, *dbgstats;
> > > +   struct dentry *dbgdir;
> > >
> > >     if (!debug_objects_enabled)
> > >             return 0;
> > >
> > >     dbgdir = debugfs_create_dir("debug_objects", NULL);
> > > -   if (!dbgdir)
> > > -           return -ENOMEM;
> > >
> > > -   dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
> > > -                                  &debug_stats_fops);
> > > -   if (!dbgstats)
> > > -           goto err;
> > > +   debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops);
> >
> >
> > One weirdness is, if dbgdir is ever NULL, then debugfs_create_file() may end
> > up creating the stats file in the root.
>
> Yes, but dbgdir can not be NULL.

Makes sense, thanks for clarification,

- Joel

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

* [tip:core/debugobjects] debugobjects: No need to check return value of debugfs_create()
  2019-06-12 15:35 [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions Greg Kroah-Hartman
  2019-06-12 16:58 ` Joel Fernandes
@ 2019-06-14 12:58 ` tip-bot for Greg Kroah-Hartman
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Greg Kroah-Hartman @ 2019-06-14 12:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: akpm, longman, tglx, cai, joel, zhongjiang, linux-kernel, hpa,
	mingo, gregkh

Commit-ID:  fecb0d95cdf752836cafdfffc1661f61ba4e2101
Gitweb:     https://git.kernel.org/tip/fecb0d95cdf752836cafdfffc1661f61ba4e2101
Author:     Greg Kroah-Hartman <gregkh@linuxfoundation.org>
AuthorDate: Wed, 12 Jun 2019 17:35:13 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 14 Jun 2019 14:51:14 +0200

debugobjects: No need to check return value of debugfs_create()

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Qian Cai <cai@gmx.us>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Waiman Long <longman@redhat.com>
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Cc: Zhong Jiang <zhongjiang@huawei.com>
Link: https://lkml.kernel.org/r/20190612153513.GA21082@kroah.com

---
 lib/debugobjects.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 55437fd5128b..2ac42286cd08 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {
 
 static int __init debug_objects_init_debugfs(void)
 {
-	struct dentry *dbgdir, *dbgstats;
+	struct dentry *dbgdir;
 
 	if (!debug_objects_enabled)
 		return 0;
 
 	dbgdir = debugfs_create_dir("debug_objects", NULL);
-	if (!dbgdir)
-		return -ENOMEM;
 
-	dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
-				       &debug_stats_fops);
-	if (!dbgstats)
-		goto err;
+	debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops);
 
 	return 0;
-
-err:
-	debugfs_remove(dbgdir);
-
-	return -ENOMEM;
 }
 __initcall(debug_objects_init_debugfs);
 

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

end of thread, other threads:[~2019-06-14 12:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 15:35 [PATCH] lib: debugobjects: no need to check return value of debugfs_create functions Greg Kroah-Hartman
2019-06-12 16:58 ` Joel Fernandes
2019-06-12 17:10   ` Greg Kroah-Hartman
2019-06-12 17:26     ` Joel Fernandes
2019-06-14 12:58 ` [tip:core/debugobjects] debugobjects: No need to check return value of debugfs_create() tip-bot for Greg Kroah-Hartman

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