3.2.101-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tim Gardner tim.gardner@canonical.com
commit b8850d1fa8e2f6653e57daf6d08e58c5f5eb2c85 upstream.
The gcc version 4.9.1 compiler complains Even though it isn't possible for these variables to not get initialized before they are used.
fs/namespace.c: In function ‘SyS_mount’: fs/namespace.c:2720:8: warning: ‘kernel_dev’ may be used uninitialized in this function [-Wmaybe-uninitialized] ret = do_mount(kernel_dev, kernel_dir->name, kernel_type, flags, ^ fs/namespace.c:2699:8: note: ‘kernel_dev’ was declared here char *kernel_dev; ^ fs/namespace.c:2720:8: warning: ‘kernel_type’ may be used uninitialized in this function [-Wmaybe-uninitialized] ret = do_mount(kernel_dev, kernel_dir->name, kernel_type, flags, ^ fs/namespace.c:2697:8: note: ‘kernel_type’ was declared here char *kernel_type; ^
Fix the warnings by simplifying copy_mount_string() as suggested by Al Viro.
Cc: Alexander Viro viro@zeniv.linux.org.uk Signed-off-by: Tim Gardner tim.gardner@canonical.com Signed-off-by: Al Viro viro@zeniv.linux.org.uk Signed-off-by: Ben Hutchings ben@decadent.org.uk --- fs/compat.c | 10 ++++++---- fs/internal.h | 2 +- fs/namespace.c | 26 ++++++++------------------ 3 files changed, 15 insertions(+), 23 deletions(-)
--- a/fs/compat.c +++ b/fs/compat.c @@ -797,8 +797,9 @@ asmlinkage long compat_sys_mount(const c char *dir_page; int retval;
- retval = copy_mount_string(type, &kernel_type); - if (retval < 0) + kernel_type = copy_mount_string(type); + retval = PTR_ERR(kernel_type); + if (IS_ERR(kernel_type)) goto out;
dir_page = getname(dir_name); @@ -806,8 +807,9 @@ asmlinkage long compat_sys_mount(const c if (IS_ERR(dir_page)) goto out1;
- retval = copy_mount_string(dev_name, &kernel_dev); - if (retval < 0) + kernel_dev = copy_mount_string(dev_name); + retval = PTR_ERR(kernel_dev); + if (IS_ERR(kernel_dev)) goto out2;
retval = copy_mount_options(data, &data_page); --- a/fs/internal.h +++ b/fs/internal.h @@ -60,7 +60,7 @@ extern int check_unsafe_exec(struct linu * namespace.c */ extern int copy_mount_options(const void __user *, unsigned long *); -extern int copy_mount_string(const void __user *, char **); +extern char *copy_mount_string(const void __user *);
extern unsigned int mnt_get_count(struct vfsmount *mnt); extern struct vfsmount *__lookup_mnt(struct vfsmount *, struct dentry *, int); --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2253,21 +2253,9 @@ int copy_mount_options(const void __user return 0; }
-int copy_mount_string(const void __user *data, char **where) +char *copy_mount_string(const void __user *data) { - char *tmp; - - if (!data) { - *where = NULL; - return 0; - } - - tmp = strndup_user(data, PAGE_SIZE); - if (IS_ERR(tmp)) - return PTR_ERR(tmp); - - *where = tmp; - return 0; + return data ? strndup_user(data, PAGE_SIZE) : NULL; }
/* @@ -2535,8 +2523,9 @@ SYSCALL_DEFINE5(mount, char __user *, de char *kernel_dev; unsigned long data_page;
- ret = copy_mount_string(type, &kernel_type); - if (ret < 0) + kernel_type = copy_mount_string(type); + ret = PTR_ERR(kernel_type); + if (IS_ERR(kernel_type)) goto out_type;
kernel_dir = getname(dir_name); @@ -2545,8 +2534,9 @@ SYSCALL_DEFINE5(mount, char __user *, de goto out_dir; }
- ret = copy_mount_string(dev_name, &kernel_dev); - if (ret < 0) + kernel_dev = copy_mount_string(dev_name); + ret = PTR_ERR(kernel_dev); + if (IS_ERR(kernel_dev)) goto out_dev;
ret = copy_mount_options(data, &data_page);