diff options
author | Fabian Frederick <fabf@skynet.be> | 2015-04-16 15:46:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:04:04 -0400 |
commit | a3cef4cd6886c755d2148739699751900b51a365 (patch) | |
tree | 49e364b4aaee42340108e3653d268f10b89529e0 | |
parent | f01fa5fb35c132587855be788297771e94b84330 (diff) |
fs/hfsplus: move xattr_name allocation in hfsplus_getxattr()
security/trusted/user/osx getxattr did the same
xattr_name initialization. Move that operation in hfsplus_getxattr().
Tested with security/trusted/user getfattr/setfattr
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/hfsplus/xattr.c | 38 | ||||
-rw-r--r-- | fs/hfsplus/xattr.h | 12 | ||||
-rw-r--r-- | fs/hfsplus/xattr_security.c | 19 | ||||
-rw-r--r-- | fs/hfsplus/xattr_trusted.c | 19 | ||||
-rw-r--r-- | fs/hfsplus/xattr_user.c | 17 |
5 files changed, 38 insertions, 67 deletions
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c index d98094a9f476..087f8da9e565 100644 --- a/fs/hfsplus/xattr.c +++ b/fs/hfsplus/xattr.c | |||
@@ -560,6 +560,30 @@ failed_getxattr_init: | |||
560 | return res; | 560 | return res; |
561 | } | 561 | } |
562 | 562 | ||
563 | ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, | ||
564 | void *value, size_t size, | ||
565 | const char *prefix, size_t prefixlen) | ||
566 | { | ||
567 | int res; | ||
568 | char *xattr_name; | ||
569 | |||
570 | if (!strcmp(name, "")) | ||
571 | return -EINVAL; | ||
572 | |||
573 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, | ||
574 | GFP_KERNEL); | ||
575 | if (!xattr_name) | ||
576 | return -ENOMEM; | ||
577 | |||
578 | strcpy(xattr_name, prefix); | ||
579 | strcpy(xattr_name + prefixlen, name); | ||
580 | |||
581 | res = __hfsplus_getxattr(dentry->d_inode, xattr_name, value, size); | ||
582 | kfree(xattr_name); | ||
583 | return res; | ||
584 | |||
585 | } | ||
586 | |||
563 | static inline int can_list(const char *xattr_name) | 587 | static inline int can_list(const char *xattr_name) |
564 | { | 588 | { |
565 | if (!xattr_name) | 589 | if (!xattr_name) |
@@ -806,9 +830,6 @@ end_removexattr: | |||
806 | static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, | 830 | static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, |
807 | void *buffer, size_t size, int type) | 831 | void *buffer, size_t size, int type) |
808 | { | 832 | { |
809 | char *xattr_name; | ||
810 | int res; | ||
811 | |||
812 | if (!strcmp(name, "")) | 833 | if (!strcmp(name, "")) |
813 | return -EINVAL; | 834 | return -EINVAL; |
814 | 835 | ||
@@ -818,16 +839,9 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, | |||
818 | */ | 839 | */ |
819 | if (is_known_namespace(name)) | 840 | if (is_known_namespace(name)) |
820 | return -EOPNOTSUPP; | 841 | return -EOPNOTSUPP; |
821 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN | ||
822 | + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); | ||
823 | if (!xattr_name) | ||
824 | return -ENOMEM; | ||
825 | strcpy(xattr_name, XATTR_MAC_OSX_PREFIX); | ||
826 | strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name); | ||
827 | 842 | ||
828 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); | 843 | return hfsplus_getxattr(dentry, name, buffer, size, |
829 | kfree(xattr_name); | 844 | XATTR_MAC_OSX_PREFIX, XATTR_MAC_OSX_PREFIX_LEN); |
830 | return res; | ||
831 | } | 845 | } |
832 | 846 | ||
833 | static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, | 847 | static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, |
diff --git a/fs/hfsplus/xattr.h b/fs/hfsplus/xattr.h index 288530cf80b5..570d406a65e3 100644 --- a/fs/hfsplus/xattr.h +++ b/fs/hfsplus/xattr.h | |||
@@ -28,15 +28,11 @@ static inline int hfsplus_setxattr(struct dentry *dentry, const char *name, | |||
28 | } | 28 | } |
29 | 29 | ||
30 | ssize_t __hfsplus_getxattr(struct inode *inode, const char *name, | 30 | ssize_t __hfsplus_getxattr(struct inode *inode, const char *name, |
31 | void *value, size_t size); | 31 | void *value, size_t size); |
32 | 32 | ||
33 | static inline ssize_t hfsplus_getxattr(struct dentry *dentry, | 33 | ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, |
34 | const char *name, | 34 | void *value, size_t size, |
35 | void *value, | 35 | const char *prefix, size_t prefixlen); |
36 | size_t size) | ||
37 | { | ||
38 | return __hfsplus_getxattr(dentry->d_inode, name, value, size); | ||
39 | } | ||
40 | 36 | ||
41 | ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); | 37 | ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); |
42 | 38 | ||
diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security.c index 6ec5e107691f..e67d52889448 100644 --- a/fs/hfsplus/xattr_security.c +++ b/fs/hfsplus/xattr_security.c | |||
@@ -16,22 +16,9 @@ | |||
16 | static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, | 16 | static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, |
17 | void *buffer, size_t size, int type) | 17 | void *buffer, size_t size, int type) |
18 | { | 18 | { |
19 | char *xattr_name; | 19 | return hfsplus_getxattr(dentry, name, buffer, size, |
20 | int res; | 20 | XATTR_SECURITY_PREFIX, |
21 | 21 | XATTR_SECURITY_PREFIX_LEN); | |
22 | if (!strcmp(name, "")) | ||
23 | return -EINVAL; | ||
24 | |||
25 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, | ||
26 | GFP_KERNEL); | ||
27 | if (!xattr_name) | ||
28 | return -ENOMEM; | ||
29 | strcpy(xattr_name, XATTR_SECURITY_PREFIX); | ||
30 | strcpy(xattr_name + XATTR_SECURITY_PREFIX_LEN, name); | ||
31 | |||
32 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); | ||
33 | kfree(xattr_name); | ||
34 | return res; | ||
35 | } | 22 | } |
36 | 23 | ||
37 | static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, | 24 | static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, |
diff --git a/fs/hfsplus/xattr_trusted.c b/fs/hfsplus/xattr_trusted.c index 3c5f27e4746a..0b7d78f2d4e9 100644 --- a/fs/hfsplus/xattr_trusted.c +++ b/fs/hfsplus/xattr_trusted.c | |||
@@ -14,22 +14,9 @@ | |||
14 | static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, | 14 | static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, |
15 | void *buffer, size_t size, int type) | 15 | void *buffer, size_t size, int type) |
16 | { | 16 | { |
17 | char *xattr_name; | 17 | return hfsplus_getxattr(dentry, name, buffer, size, |
18 | int res; | 18 | XATTR_TRUSTED_PREFIX, |
19 | 19 | XATTR_TRUSTED_PREFIX_LEN); | |
20 | if (!strcmp(name, "")) | ||
21 | return -EINVAL; | ||
22 | |||
23 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, | ||
24 | GFP_KERNEL); | ||
25 | if (!xattr_name) | ||
26 | return -ENOMEM; | ||
27 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); | ||
28 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); | ||
29 | |||
30 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); | ||
31 | kfree(xattr_name); | ||
32 | return res; | ||
33 | } | 20 | } |
34 | 21 | ||
35 | static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, | 22 | static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, |
diff --git a/fs/hfsplus/xattr_user.c b/fs/hfsplus/xattr_user.c index 2b625a538b64..f8860df28842 100644 --- a/fs/hfsplus/xattr_user.c +++ b/fs/hfsplus/xattr_user.c | |||
@@ -14,22 +14,9 @@ | |||
14 | static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, | 14 | static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, |
15 | void *buffer, size_t size, int type) | 15 | void *buffer, size_t size, int type) |
16 | { | 16 | { |
17 | char *xattr_name; | ||
18 | int res; | ||
19 | |||
20 | if (!strcmp(name, "")) | ||
21 | return -EINVAL; | ||
22 | |||
23 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, | ||
24 | GFP_KERNEL); | ||
25 | if (!xattr_name) | ||
26 | return -ENOMEM; | ||
27 | strcpy(xattr_name, XATTR_USER_PREFIX); | ||
28 | strcpy(xattr_name + XATTR_USER_PREFIX_LEN, name); | ||
29 | 17 | ||
30 | res = hfsplus_getxattr(dentry, xattr_name, buffer, size); | 18 | return hfsplus_getxattr(dentry, name, buffer, size, |
31 | kfree(xattr_name); | 19 | XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
32 | return res; | ||
33 | } | 20 | } |
34 | 21 | ||
35 | static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, | 22 | static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, |