On Wed, 23 Jan 2019 07:34:27 +0100
Greg Kroah-Hartman <gre...@linuxfoundation.org> wrote:

> On Wed, Jan 23, 2019 at 07:33:05AM +0100, Greg Kroah-Hartman wrote:
> > On Wed, Jan 23, 2019 at 09:11:41AM +0900, Masami Hiramatsu wrote:
> > > On Tue, 22 Jan 2019 16:21:44 +0100
> > > Greg Kroah-Hartman <gre...@linuxfoundation.org> 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.
> > > 
> > > Ah, OK. It simplifies the code. But I have a question below,
> > > 
> > > > 
> > > > Cc: Masami Hiramatsu <mhira...@kernel.org>
> > > > Cc: Kees Cook <keesc...@chromium.org>
> > > > Cc: Josef Bacik <jba...@fb.com>
> > > > Cc: Thomas Gleixner <t...@linutronix.de>
> > > > Cc: "Naveen N. Rao" <naveen.n....@linux.vnet.ibm.com>
> > > > Cc: zhong jiang <zhongji...@huawei.com>
> > > > Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
> > > > ---
> > > >  kernel/fail_function.c | 23 +++++------------------
> > > >  1 file changed, 5 insertions(+), 18 deletions(-)
> > > > 
> > > > diff --git a/kernel/fail_function.c b/kernel/fail_function.c
> > > > index 17f75b545f66..afc779be5ebb 100644
> > > > --- a/kernel/fail_function.c
> > > > +++ b/kernel/fail_function.c
> > > > @@ -152,20 +152,13 @@ static int fei_retval_get(void *data, u64 *val)
> > > >  DEFINE_DEBUGFS_ATTRIBUTE(fei_retval_ops, fei_retval_get, 
> > > > fei_retval_set,
> > > >                          "%llx\n");
> > > >  
> > > > -static int fei_debugfs_add_attr(struct fei_attr *attr)
> > > > +static void fei_debugfs_add_attr(struct fei_attr *attr)
> > > >  {
> > > >         struct dentry *dir;
> > > >  
> > > >         dir = debugfs_create_dir(attr->kp.symbol_name, fei_debugfs_dir);
> > > > -       if (!dir)
> > > > -               return -ENOMEM;
> > > > -
> > > > -       if (!debugfs_create_file("retval", 0600, dir, attr, 
> > > > &fei_retval_ops)) {
> > > > -               debugfs_remove_recursive(dir);
> > > > -               return -ENOMEM;
> > > > -       }
> > > >  
> > > > -       return 0;
> > > 
> > > Don't we need to check dir here? If above debugfs_create_dir() returns 
> > > NULL,
> > > it seems we will create "retval" under root directory of debugfs.
> > 
> > If NULL is returned, your system is out of memory and worse things are
> > about to happen :)
> 
> But you aren't the first to ask about this, I guess I should just return
> ENOMEM and then the follow-on files will not be created.  I'll go make
> that change to the core of debugfs to help prevent this problem.

I got it, and yes, returning -ENOMEM sounds good to me, especially, in this 
case.

Acked-by: Masami Hiramatsu <mhira...@kernel.org>

Thanks!

> 
> thanks,
> 
> greg k-h


-- 
Masami Hiramatsu <mhira...@kernel.org>

Reply via email to