From: Greg KH <greg@kroah.com>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: "Serge E. Hallyn" <serge@hallyn.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: securityfs_create_dir strange comment
Date: Tue, 20 Feb 2007 20:05:26 -0800 [thread overview]
Message-ID: <20070221040526.GA8207@kroah.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0702210042140.7132@yvahk01.tjqt.qr>
On Wed, Feb 21, 2007 at 12:45:40AM +0100, Jan Engelhardt wrote:
>
> On Feb 20 2007 14:26, Greg KH wrote:
> >On Tue, Feb 20, 2007 at 03:18:49PM -0600, Serge E. Hallyn wrote:
> >> Quoting Jan Engelhardt (jengelh@linux01.gwdg.de):
> >> > Hello list,
> >> >
> >> >
> >> > in security/inode.c, the comment for securityfs_create_dir() reads:
> >> >
> >> > If securityfs is not enabled in the kernel, the value -ENODEV
> >> > will be returned. It is not wise to check for this value, but
> >> > rather, check for NULL or !NULL instead as to eliminate the need
> >> > for #ifdef in the calling code.
> >> >
> >> > What is the actual callee that can return NULL - and what should
> >> > module_init() of a module return when securityfs_create_dir() returns
> >> > NULL?
> >>
> >> Hmm, this came from GregKH. It does seem based on the code that
> >> checking for -ENODEV is necessary, so I don't understand the comment.
> >
> >If securityfs_create_dir() returns NULL, then something bad happened and
> >your code needs to properly recover from it.
> >
> >Other than that, I don't understand the issue here.
>
> Consider:
>
> static __init int mymodule_init(void)
> {
> struct dentry *de;
> de = securityfs_create_dir("foobar", NULL);
>
> /* case 1 */
> if(IS_ERR(de))
> return PTR_ERR(de);
>
> /* case 2 */
> if(de == NULL)
> return WHAT_HERE; /* -EIO? */
> }
>
> There are two error cases. One: when the function gives us an error code.
> Two: When it returns NULL, without an error code. This looks bogus to me.
> What error is it, when there is no error? - And what should I return to
> modprobe in that case?
Try this instead:
if (!de)
return -ENOMEM;
if ((IS_ERR(de)) && (PTR_ERR(de) != -ENODEV))
return PTR_ERR(de);
return 0;
That should cover everything properly, right?
thanks,
greg k-h
next prev parent reply other threads:[~2007-02-21 4:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-18 15:45 securityfs_create_dir strange comment Jan Engelhardt
2007-02-20 21:18 ` Serge E. Hallyn
2007-02-20 22:26 ` Greg KH
2007-02-20 23:45 ` Jan Engelhardt
2007-02-21 4:05 ` Greg KH [this message]
2007-02-21 17:07 ` Jan Engelhardt
2007-02-21 17:29 ` Greg KH
2007-02-21 17:46 ` Jan Engelhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070221040526.GA8207@kroah.com \
--to=greg@kroah.com \
--cc=jengelh@linux01.gwdg.de \
--cc=linux-kernel@vger.kernel.org \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox