diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2008-07-21 06:06:36 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-07-26 20:53:24 -0400 |
commit | 88b387824fdaecb6ba0f471acf0aadf7d24739fd (patch) | |
tree | bd0e169bc0d2a802cd4ea58baf957bfa4602e956 | |
parent | 672b16b2f66c149888bd876a4f92342112205fe1 (diff) |
[PATCH] vfs: use kstrdup() and check failing allocation
- 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>
-rw-r--r-- | fs/namespace.c | 24 | ||||
-rw-r--r-- | include/linux/mount.h | 2 |
2 files changed, 14 insertions, 12 deletions
diff --git a/fs/namespace.c b/fs/namespace.c index c4fcf48acef8..26380f599534 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -112,9 +112,13 @@ struct vfsmount *alloc_vfsmnt(const char *name) | |||
112 | int err; | 112 | int err; |
113 | 113 | ||
114 | err = mnt_alloc_id(mnt); | 114 | err = mnt_alloc_id(mnt); |
115 | if (err) { | 115 | if (err) |
116 | kmem_cache_free(mnt_cache, mnt); | 116 | goto out_free_cache; |
117 | return NULL; | 117 | |
118 | if (name) { | ||
119 | mnt->mnt_devname = kstrdup(name, GFP_KERNEL); | ||
120 | if (!mnt->mnt_devname) | ||
121 | goto out_free_id; | ||
118 | } | 122 | } |
119 | 123 | ||
120 | atomic_set(&mnt->mnt_count, 1); | 124 | atomic_set(&mnt->mnt_count, 1); |
@@ -127,16 +131,14 @@ struct vfsmount *alloc_vfsmnt(const char *name) | |||
127 | INIT_LIST_HEAD(&mnt->mnt_slave_list); | 131 | INIT_LIST_HEAD(&mnt->mnt_slave_list); |
128 | INIT_LIST_HEAD(&mnt->mnt_slave); | 132 | INIT_LIST_HEAD(&mnt->mnt_slave); |
129 | atomic_set(&mnt->__mnt_writers, 0); | 133 | atomic_set(&mnt->__mnt_writers, 0); |
130 | if (name) { | ||
131 | int size = strlen(name) + 1; | ||
132 | char *newname = kmalloc(size, GFP_KERNEL); | ||
133 | if (newname) { | ||
134 | memcpy(newname, name, size); | ||
135 | mnt->mnt_devname = newname; | ||
136 | } | ||
137 | } | ||
138 | } | 134 | } |
139 | return mnt; | 135 | return mnt; |
136 | |||
137 | out_free_id: | ||
138 | mnt_free_id(mnt); | ||
139 | out_free_cache: | ||
140 | kmem_cache_free(mnt_cache, mnt); | ||
141 | return NULL; | ||
140 | } | 142 | } |
141 | 143 | ||
142 | /* | 144 | /* |
diff --git a/include/linux/mount.h b/include/linux/mount.h index 4374d1adeb4b..b5efaa2132ab 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h | |||
@@ -47,7 +47,7 @@ struct vfsmount { | |||
47 | struct list_head mnt_child; /* and going through their mnt_child */ | 47 | struct list_head mnt_child; /* and going through their mnt_child */ |
48 | int mnt_flags; | 48 | int mnt_flags; |
49 | /* 4 bytes hole on 64bits arches */ | 49 | /* 4 bytes hole on 64bits arches */ |
50 | char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ | 50 | const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ |
51 | struct list_head mnt_list; | 51 | struct list_head mnt_list; |
52 | struct list_head mnt_expire; /* link in fs-specific expiry list */ | 52 | struct list_head mnt_expire; /* link in fs-specific expiry list */ |
53 | struct list_head mnt_share; /* circular list of shared mounts */ | 53 | struct list_head mnt_share; /* circular list of shared mounts */ |