]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] vfs: use kstrdup() and check failing allocation
authorLi Zefan <lizf@cn.fujitsu.com>
Mon, 21 Jul 2008 10:06:36 +0000 (18:06 +0800)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 27 Jul 2008 00:53:24 +0000 (20:53 -0400)
- use kstrdup() instead of kmalloc() + memcpy()
- return NULL if allocating ->mnt_devname failed
- mnt_devname should be const

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c
include/linux/mount.h

index c4fcf48acef88f79208dd2d506fc2a8781409438..26380f599534b91e09fa4254c7c3c1c1fedaaad6 100644 (file)
@@ -112,9 +112,13 @@ struct vfsmount *alloc_vfsmnt(const char *name)
                int err;
 
                err = mnt_alloc_id(mnt);
-               if (err) {
-                       kmem_cache_free(mnt_cache, mnt);
-                       return NULL;
+               if (err)
+                       goto out_free_cache;
+
+               if (name) {
+                       mnt->mnt_devname = kstrdup(name, GFP_KERNEL);
+                       if (!mnt->mnt_devname)
+                               goto out_free_id;
                }
 
                atomic_set(&mnt->mnt_count, 1);
@@ -127,16 +131,14 @@ struct vfsmount *alloc_vfsmnt(const char *name)
                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;
+
+out_free_id:
+       mnt_free_id(mnt);
+out_free_cache:
+       kmem_cache_free(mnt_cache, mnt);
+       return NULL;
 }
 
 /*
index 4374d1adeb4b755b4227bccf1f3afaa0b214fc35..b5efaa2132ab2ff79b624e09ab7eba0adcd18a04 100644 (file)
@@ -47,7 +47,7 @@ struct vfsmount {
        struct list_head mnt_child;     /* and going through their mnt_child */
        int mnt_flags;
        /* 4 bytes hole on 64bits arches */
-       char *mnt_devname;              /* Name of device e.g. /dev/dsk/hda1 */
+       const char *mnt_devname;        /* Name of device e.g. /dev/dsk/hda1 */
        struct list_head mnt_list;
        struct list_head mnt_expire;    /* link in fs-specific expiry list */
        struct list_head mnt_share;     /* circular list of shared mounts */