Skip to content

Commit d45da67

Browse files
Yuan Canaalexandrovich
authored andcommitted
fs/ntfs3: Use strcmp to determine attribute type
The way of determin attribute type is just matching name with the predefined string, do this with strcmp to simplify the code. Signed-off-by: Yuan Can <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 887bfc5 commit d45da67

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

fs/ntfs3/xattr.c

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
781781
{
782782
int err;
783783
struct ntfs_inode *ni = ntfs_i(inode);
784-
size_t name_len = strlen(name);
785784

786785
/* Dispatch request. */
787-
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 &&
788-
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
786+
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
789787
/* system.dos_attrib */
790788
if (!buffer) {
791789
err = sizeof(u8);
@@ -798,8 +796,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
798796
goto out;
799797
}
800798

801-
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 &&
802-
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
799+
if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
803800
/* system.ntfs_attrib */
804801
if (!buffer) {
805802
err = sizeof(u32);
@@ -812,8 +809,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
812809
goto out;
813810
}
814811

815-
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 &&
816-
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
812+
if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
817813
/* system.ntfs_security*/
818814
struct SECURITY_DESCRIPTOR_RELATIVE *sd = NULL;
819815
size_t sd_size = 0;
@@ -853,24 +849,20 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
853849
}
854850

855851
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
856-
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
857-
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
858-
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
859-
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
860-
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
861-
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
852+
if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
853+
!strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
862854
/* TODO: init_user_ns? */
863855
err = ntfs_xattr_get_acl(
864856
&init_user_ns, inode,
865-
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
857+
strlen(name) == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
866858
? ACL_TYPE_ACCESS
867859
: ACL_TYPE_DEFAULT,
868860
buffer, size);
869861
goto out;
870862
}
871863
#endif
872864
/* Deal with NTFS extended attribute. */
873-
err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL);
865+
err = ntfs_get_ea(inode, name, strlen(name), buffer, size, NULL);
874866

875867
out:
876868
return err;
@@ -887,20 +879,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
887879
{
888880
int err = -EINVAL;
889881
struct ntfs_inode *ni = ntfs_i(inode);
890-
size_t name_len = strlen(name);
891882
enum FILE_ATTRIBUTE new_fa;
892883

893884
/* Dispatch request. */
894-
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 &&
895-
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
885+
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
896886
if (sizeof(u8) != size)
897887
goto out;
898888
new_fa = cpu_to_le32(*(u8 *)value);
899889
goto set_new_fa;
900890
}
901891

902-
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 &&
903-
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
892+
if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
904893
if (size != sizeof(u32))
905894
goto out;
906895
new_fa = cpu_to_le32(*(u32 *)value);
@@ -938,8 +927,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
938927
goto out;
939928
}
940929

941-
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 &&
942-
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
930+
if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
943931
/* system.ntfs_security*/
944932
__le32 security_id;
945933
bool inserted;
@@ -982,23 +970,19 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
982970
}
983971

984972
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
985-
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
986-
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
987-
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
988-
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
989-
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
990-
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
973+
if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
974+
!strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
991975
err = ntfs_xattr_set_acl(
992976
mnt_userns, inode,
993-
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
977+
strlen(name) == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
994978
? ACL_TYPE_ACCESS
995979
: ACL_TYPE_DEFAULT,
996980
value, size);
997981
goto out;
998982
}
999983
#endif
1000984
/* Deal with NTFS extended attribute. */
1001-
err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0);
985+
err = ntfs_set_ea(inode, name, strlen(name), value, size, flags, 0);
1002986

1003987
out:
1004988
inode->i_ctime = current_time(inode);

0 commit comments

Comments
 (0)