提交 29eb981a 编写于 作者: C Chuck Lever 提交者: Trond Myklebust

NFS: Clean-up: Replace nfs_copy_user_string with strndup_user

The new string utility function strndup_user can be used instead of
nfs_copy_user_string, eliminating an unnecessary duplication of function.
Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 5680d48b
...@@ -785,27 +785,6 @@ static void nfs4_fill_super(struct super_block *sb) ...@@ -785,27 +785,6 @@ static void nfs4_fill_super(struct super_block *sb)
nfs_initialise_sb(sb); nfs_initialise_sb(sb);
} }
static void *nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
{
void *p = NULL;
if (!src->len)
return ERR_PTR(-EINVAL);
if (src->len < maxlen)
maxlen = src->len;
if (dst == NULL) {
p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
if (p == NULL)
return ERR_PTR(-ENOMEM);
}
if (copy_from_user(dst, src->data, maxlen)) {
kfree(p);
return ERR_PTR(-EFAULT);
}
dst[maxlen] = '\0';
return dst;
}
/* /*
* Get the superblock for an NFS4 mountpoint * Get the superblock for an NFS4 mountpoint
*/ */
...@@ -819,8 +798,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type, ...@@ -819,8 +798,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
rpc_authflavor_t authflavour; rpc_authflavor_t authflavour;
struct nfs_fh mntfh; struct nfs_fh mntfh;
struct dentry *mntroot; struct dentry *mntroot;
char *mntpath = NULL, *hostname = NULL, ip_addr[16]; char *p, *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
void *p;
int error; int error;
if (data == NULL) { if (data == NULL) {
...@@ -857,39 +835,39 @@ static int nfs4_get_sb(struct file_system_type *fs_type, ...@@ -857,39 +835,39 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
dprintk("%s: Invalid number of RPC auth flavours %d.\n", dprintk("%s: Invalid number of RPC auth flavours %d.\n",
__FUNCTION__, data->auth_flavourlen); __FUNCTION__, data->auth_flavourlen);
error = -EINVAL; error = -EINVAL;
goto out_err_noserver; goto out;
} }
if (copy_from_user(&authflavour, data->auth_flavours, if (copy_from_user(&authflavour, data->auth_flavours,
sizeof(authflavour))) { sizeof(authflavour))) {
error = -EFAULT; error = -EFAULT;
goto out_err_noserver; goto out;
} }
} }
p = nfs_copy_user_string(NULL, &data->hostname, NFS4_MAXNAMLEN); p = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
if (IS_ERR(p)) if (IS_ERR(p))
goto out_err; goto out_err;
hostname = p; hostname = p;
p = nfs_copy_user_string(NULL, &data->mnt_path, NFS4_MAXPATHLEN); p = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
if (IS_ERR(p)) if (IS_ERR(p))
goto out_err; goto out_err;
mntpath = p; mntpath = p;
dprintk("MNTPATH: %s\n", mntpath); dprintk("MNTPATH: %s\n", mntpath);
p = nfs_copy_user_string(ip_addr, &data->client_addr, p = strndup_user(data->client_addr.data, 16);
sizeof(ip_addr) - 1);
if (IS_ERR(p)) if (IS_ERR(p))
goto out_err; goto out_err;
ip_addr = p;
/* Get a volume representation */ /* Get a volume representation */
server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr, server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
authflavour, &mntfh); authflavour, &mntfh);
if (IS_ERR(server)) { if (IS_ERR(server)) {
error = PTR_ERR(server); error = PTR_ERR(server);
goto out_err_noserver; goto out;
} }
/* Get a superblock - note that we may end up sharing one that already exists */ /* Get a superblock - note that we may end up sharing one that already exists */
...@@ -919,25 +897,26 @@ static int nfs4_get_sb(struct file_system_type *fs_type, ...@@ -919,25 +897,26 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
s->s_flags |= MS_ACTIVE; s->s_flags |= MS_ACTIVE;
mnt->mnt_sb = s; mnt->mnt_sb = s;
mnt->mnt_root = mntroot; mnt->mnt_root = mntroot;
error = 0;
out:
kfree(ip_addr);
kfree(mntpath); kfree(mntpath);
kfree(hostname); kfree(hostname);
return 0; return error;
out_err: out_err:
error = PTR_ERR(p); error = PTR_ERR(p);
goto out_err_noserver; goto out;
out_free: out_free:
nfs_free_server(server); nfs_free_server(server);
out_err_noserver: goto out;
kfree(mntpath);
kfree(hostname);
return error;
error_splat_super: error_splat_super:
up_write(&s->s_umount); up_write(&s->s_umount);
deactivate_super(s); deactivate_super(s);
goto out_err_noserver; goto out;
} }
static void nfs4_kill_super(struct super_block *sb) static void nfs4_kill_super(struct super_block *sb)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册