2010-11-28 20:09:07

by Vegard Nossum

[permalink] [raw]
Subject: proc: proc_self_follow_link() weirdness

Hi,

I came across this code in fs/proc/base.c:

static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
{
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
pid_t tgid = task_tgid_nr_ns(current, ns);
char *name = ERR_PTR(-ENOENT);
if (tgid) {
name = __getname();
if (!name)
name = ERR_PTR(-ENOMEM);
else
sprintf(name, "%d", tgid);
}
nd_set_link(nd, name);
return NULL;
}

This looks a bit weird to me; it seems that nd_set_link() will get
called with name = ERR_PTR(-ENOMEM) if __getname() fails. Is this the
intended behaviour? Shouldn't it return this ERR_PTR() instead?


Vegard


2010-11-28 21:55:04

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: proc: proc_self_follow_link() weirdness

On Sun, Nov 28, 2010 at 09:09:03PM +0100, Vegard Nossum wrote:
> Hi,
>
> I came across this code in fs/proc/base.c:
>
> static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
> {
> struct pid_namespace *ns = dentry->d_sb->s_fs_info;
> pid_t tgid = task_tgid_nr_ns(current, ns);
> char *name = ERR_PTR(-ENOENT);
> if (tgid) {
> name = __getname();
> if (!name)
> name = ERR_PTR(-ENOMEM);
> else
> sprintf(name, "%d", tgid);
> }
> nd_set_link(nd, name);
> return NULL;
> }
>
> This looks a bit weird to me; it seems that nd_set_link() will get
> called with name = ERR_PTR(-ENOMEM) if __getname() fails. Is this the
> intended behaviour? Shouldn't it return this ERR_PTR() instead?
>
>
> Vegard

nd_get_link callers do check for IS_ERR (directly or indirectly),
but to return 'name' here would be more appropriate I guess. Al?

Cyrill