* [PATCH] vfs: use kstrdup() and check failing allocation
@ 2008-07-21 10:06 Li Zefan
2008-07-21 10:16 ` Cyrill Gorcunov
0 siblings, 1 reply; 5+ messages in thread
From: Li Zefan @ 2008-07-21 10:06 UTC (permalink / raw)
To: Al Viro; +Cc: Andrew Morton, Cyrill Gorcunov, Pekka Enberg, LKML
- 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>
---
Andrew, please drop vfs-use-kstrdup.patch
---
fs/namespace.c | 24 +++++++++++++-----------
include/linux/mount.h | 2 +-
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 4f6f763..e52e11f 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -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;
}
/*
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 4374d1a..b5efaa2 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -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 */
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] vfs: use kstrdup() and check failing allocation
2008-07-21 10:06 [PATCH] vfs: use kstrdup() and check failing allocation Li Zefan
@ 2008-07-21 10:16 ` Cyrill Gorcunov
2008-07-21 10:18 ` Pekka Enberg
2008-07-21 13:24 ` Al Viro
0 siblings, 2 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2008-07-21 10:16 UTC (permalink / raw)
To: Li Zefan; +Cc: Al Viro, Andrew Morton, Pekka Enberg, LKML
[Li Zefan - Mon, Jul 21, 2008 at 06:06:36PM +0800]
| - 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>
| ---
|
| Andrew, please drop vfs-use-kstrdup.patch
|
| ---
Thanks Li. I think Al will be fine with this version.
So if you needed:
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
- Cyrill -
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vfs: use kstrdup() and check failing allocation
2008-07-21 10:16 ` Cyrill Gorcunov
@ 2008-07-21 10:18 ` Pekka Enberg
2008-07-21 13:24 ` Al Viro
1 sibling, 0 replies; 5+ messages in thread
From: Pekka Enberg @ 2008-07-21 10:18 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: Li Zefan, Al Viro, Andrew Morton, LKML
On Mon, 2008-07-21 at 14:16 +0400, Cyrill Gorcunov wrote:
> [Li Zefan - Mon, Jul 21, 2008 at 06:06:36PM +0800]
> | - 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>
> | ---
> |
> | Andrew, please drop vfs-use-kstrdup.patch
> |
> | ---
>
> Thanks Li. I think Al will be fine with this version.
>
> So if you needed:
> Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vfs: use kstrdup() and check failing allocation
2008-07-21 10:16 ` Cyrill Gorcunov
2008-07-21 10:18 ` Pekka Enberg
@ 2008-07-21 13:24 ` Al Viro
2008-07-21 14:56 ` Cyrill Gorcunov
1 sibling, 1 reply; 5+ messages in thread
From: Al Viro @ 2008-07-21 13:24 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: Li Zefan, Andrew Morton, Pekka Enberg, LKML
On Mon, Jul 21, 2008 at 02:16:23PM +0400, Cyrill Gorcunov wrote:
> [Li Zefan - Mon, Jul 21, 2008 at 06:06:36PM +0800]
> | - 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>
> | ---
> |
> | Andrew, please drop vfs-use-kstrdup.patch
> |
> | ---
>
> Thanks Li. I think Al will be fine with this version.
>
> So if you needed:
> Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vfs: use kstrdup() and check failing allocation
2008-07-21 13:24 ` Al Viro
@ 2008-07-21 14:56 ` Cyrill Gorcunov
0 siblings, 0 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2008-07-21 14:56 UTC (permalink / raw)
To: Al Viro; +Cc: Li Zefan, Andrew Morton, Pekka Enberg, LKML
[Al Viro - Mon, Jul 21, 2008 at 02:24:29PM +0100]
[...]
| > So if you needed:
| > Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
|
| Applied.
|
Thanks Al!
- Cyrill -
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-07-21 14:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-21 10:06 [PATCH] vfs: use kstrdup() and check failing allocation Li Zefan
2008-07-21 10:16 ` Cyrill Gorcunov
2008-07-21 10:18 ` Pekka Enberg
2008-07-21 13:24 ` Al Viro
2008-07-21 14:56 ` Cyrill Gorcunov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.