Skip to content

Commit

Permalink
fs: namespace: suppress 'may be used uninitialized' warnings
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Tim Gardner <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
rtg-canonical authored and Al Viro committed Oct 9, 2014
1 parent 8ba7f6c commit b8850d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
10 changes: 6 additions & 4 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,17 +797,19 @@ COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
struct filename *dir;
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 = getname(dir_name);
retval = PTR_ERR(dir);
if (IS_ERR(dir))
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);
Expand Down
2 changes: 1 addition & 1 deletion fs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
* 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 struct vfsmount *lookup_mnt(struct path *);
extern int finish_automount(struct vfsmount *, struct path *);
Expand Down
26 changes: 8 additions & 18 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,21 +2514,9 @@ int copy_mount_options(const void __user * data, unsigned long *where)
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;
}

/*
Expand Down Expand Up @@ -2794,8 +2782,9 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
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);
Expand All @@ -2804,8 +2793,9 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
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);
Expand Down

0 comments on commit b8850d1

Please sign in to comment.