Re: [PATCH] vfs: use kstrdup()

From: Cyrill Gorcunov
Date: Mon Jul 21 2008 - 04:44:58 EST


[Li Zefan - Mon, Jul 21, 2008 at 04:28:17PM +0800]
| Cyrill Gorcunov wrote:
| > [Al Viro - Mon, Jul 21, 2008 at 08:03:46AM +0100]
| > |
| > [...]
| > | The right thing here is to consider failing allocation of ->mnt_devname
| > | as failure of the entire alloc.
| > |
| >
| > Al, what about the patch below? I'm not sure if Li's version already
| > in someone tree so it's from-the-scratch. If this ok, i think Li could
| > update his version and resend.
| >
|
| It's already in -mm tree, but Andrew can drop it and queue the new one.
|
| > - Cyrill -
| > ---
| >
| > Index: linux-2.6.git/fs/namespace.c
| > ===================================================================
| > --- linux-2.6.git.orig/fs/namespace.c 2008-07-21 11:34:37.000000000 +0400
| > +++ linux-2.6.git/fs/namespace.c 2008-07-21 12:00:01.000000000 +0400
| > @@ -112,9 +112,13 @@ struct vfsmount *alloc_vfsmnt(const char
| > int err;
| >
| > err = mnt_alloc_id(mnt);
| > - if (err) {
| > - kmem_cache_free(mnt_cache, mnt);
| > - return NULL;
| > + if (err)
| > + goto err;
| > +
| > + if (name) {
| > + mnt->mnt_devname = kstrdup(name, GFP_KERNEL);
| > + if (!mnt->mnt_devname)
|
| should call mnt_free_id() here.
|
| > + goto err;
| > }
| >
| > atomic_set(&mnt->mnt_count, 1);
| > @@ -127,16 +131,12 @@ struct vfsmount *alloc_vfsmnt(const char
| > INIT_LIST_HEAD(&mnt->mnt_slave_list);
| > INIT_LIST_HEAD(&mnt->mnt_slave);
| > atomic_set(&mnt->__mnt_writers, 0);
| > - if (name) {
| > - int size = strlen(name) + 1;
| > - char *newname = kmalloc(size, GFP_KERNEL);
| > - if (newname) {
| > - memcpy(newname, name, size);
| > - mnt->mnt_devname = newname;
| > - }
| > - }
| > }
| > return mnt;
| > +
| > +err:
| > + kmem_cache_free(mnt_cache, mnt);
| > + return NULL;
| > }
| >
| > /*
| >
| >
|

well, as only Al find new version more or less correct we could
update yours.

- Cyrill -
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/