Commit 0b2a6f23 authored by Richard Weinberger's avatar Richard Weinberger Committed by Al Viro

fs: xattr: Use kvfree()

... instead of open coding it.
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent bdb97e91
...@@ -324,7 +324,6 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, ...@@ -324,7 +324,6 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
{ {
int error; int error;
void *kvalue = NULL; void *kvalue = NULL;
void *vvalue = NULL; /* If non-NULL, we used vmalloc() */
char kname[XATTR_NAME_MAX + 1]; char kname[XATTR_NAME_MAX + 1];
if (flags & ~(XATTR_CREATE|XATTR_REPLACE)) if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
...@@ -341,10 +340,9 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, ...@@ -341,10 +340,9 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
return -E2BIG; return -E2BIG;
kvalue = kmalloc(size, GFP_KERNEL | __GFP_NOWARN); kvalue = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
if (!kvalue) { if (!kvalue) {
vvalue = vmalloc(size); kvalue = vmalloc(size);
if (!vvalue) if (!kvalue)
return -ENOMEM; return -ENOMEM;
kvalue = vvalue;
} }
if (copy_from_user(kvalue, value, size)) { if (copy_from_user(kvalue, value, size)) {
error = -EFAULT; error = -EFAULT;
...@@ -357,10 +355,8 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, ...@@ -357,10 +355,8 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
error = vfs_setxattr(d, kname, kvalue, size, flags); error = vfs_setxattr(d, kname, kvalue, size, flags);
out: out:
if (vvalue) kvfree(kvalue);
vfree(vvalue);
else
kfree(kvalue);
return error; return error;
} }
...@@ -428,7 +424,6 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, ...@@ -428,7 +424,6 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
{ {
ssize_t error; ssize_t error;
void *kvalue = NULL; void *kvalue = NULL;
void *vvalue = NULL;
char kname[XATTR_NAME_MAX + 1]; char kname[XATTR_NAME_MAX + 1];
error = strncpy_from_user(kname, name, sizeof(kname)); error = strncpy_from_user(kname, name, sizeof(kname));
...@@ -442,10 +437,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, ...@@ -442,10 +437,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
size = XATTR_SIZE_MAX; size = XATTR_SIZE_MAX;
kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
if (!kvalue) { if (!kvalue) {
vvalue = vmalloc(size); kvalue = vmalloc(size);
if (!vvalue) if (!kvalue)
return -ENOMEM; return -ENOMEM;
kvalue = vvalue;
} }
} }
...@@ -461,10 +455,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, ...@@ -461,10 +455,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
than XATTR_SIZE_MAX bytes. Not possible. */ than XATTR_SIZE_MAX bytes. Not possible. */
error = -E2BIG; error = -E2BIG;
} }
if (vvalue)
vfree(vvalue); kvfree(kvalue);
else
kfree(kvalue);
return error; return error;
} }
...@@ -521,17 +514,15 @@ listxattr(struct dentry *d, char __user *list, size_t size) ...@@ -521,17 +514,15 @@ listxattr(struct dentry *d, char __user *list, size_t size)
{ {
ssize_t error; ssize_t error;
char *klist = NULL; char *klist = NULL;
char *vlist = NULL; /* If non-NULL, we used vmalloc() */
if (size) { if (size) {
if (size > XATTR_LIST_MAX) if (size > XATTR_LIST_MAX)
size = XATTR_LIST_MAX; size = XATTR_LIST_MAX;
klist = kmalloc(size, __GFP_NOWARN | GFP_KERNEL); klist = kmalloc(size, __GFP_NOWARN | GFP_KERNEL);
if (!klist) { if (!klist) {
vlist = vmalloc(size); klist = vmalloc(size);
if (!vlist) if (!klist)
return -ENOMEM; return -ENOMEM;
klist = vlist;
} }
} }
...@@ -544,10 +535,9 @@ listxattr(struct dentry *d, char __user *list, size_t size) ...@@ -544,10 +535,9 @@ listxattr(struct dentry *d, char __user *list, size_t size)
than XATTR_LIST_MAX bytes. Not possible. */ than XATTR_LIST_MAX bytes. Not possible. */
error = -E2BIG; error = -E2BIG;
} }
if (vlist)
vfree(vlist); kvfree(klist);
else
kfree(klist);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment