fs/ntfs3: use strcmp to determin attribute type
PATCH v2 1/1 fs/ntfs3: use strcmp to determin 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]>
--- fs/ntfs3/xattr.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
fs/ntfs3/xattr.c +8 -16
@@ -720,11 +720,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, {int err;struct ntfs_inode *ni =ntfs_i (inode); -size_t name_len =strlen (name);/* Dispatch request. */ -if (name_len ==sizeof (SYSTEM_DOS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_DOS_ATTRIB ,sizeof (SYSTEM_DOS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_DOS_ATTRIB )) {/* system.dos_attrib */ if (!buffer) { err =sizeof (u8);
@@ -737,8 +735,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_NTFS_ATTRIB ,sizeof (SYSTEM_NTFS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_NTFS_ATTRIB )) {/* system.ntfs_attrib */ if (!buffer) { err =sizeof (u32);
@@ -751,8 +748,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_SECURITY ) -1 && - !memcmp (name,SYSTEM_NTFS_SECURITY ,sizeof (SYSTEM_NTFS_SECURITY ))) { +if (!strcmp (name,SYSTEM_NTFS_SECURITY )) {/* system.ntfs_security*/ struct SECURITY_DESCRIPTOR_RELATIVE *sd =NULL ;size_t sd_size =0 ;
@@ -792,7 +788,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, }/* Deal with NTFS extended attribute. */ - err =ntfs_get_ea (inode, name, name_len, buffer, size,NULL ); + err =ntfs_get_ea (inode, name,strlen (name), buffer, size,NULL ); out:return err;
@@ -809,20 +805,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, {int err = -EINVAL ;struct ntfs_inode *ni =ntfs_i (inode); -size_t name_len =strlen (name);enum FILE_ATTRIBUTE new_fa;/* Dispatch request. */ -if (name_len ==sizeof (SYSTEM_DOS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_DOS_ATTRIB ,sizeof (SYSTEM_DOS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_DOS_ATTRIB )) {if (sizeof (u8) != size) goto out; new_fa =cpu_to_le32 (*(u8 *)value); goto set_new_fa; } -if (name_len ==sizeof (SYSTEM_NTFS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_NTFS_ATTRIB ,sizeof (SYSTEM_NTFS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_NTFS_ATTRIB )) {if (size !=sizeof (u32)) goto out; new_fa =cpu_to_le32 (*(u32 *)value);
@@ -860,8 +853,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_SECURITY ) -1 && - !memcmp (name,SYSTEM_NTFS_SECURITY ,sizeof (SYSTEM_NTFS_SECURITY ))) { +if (!strcmp (name,SYSTEM_NTFS_SECURITY )) {/* system.ntfs_security*/ __le32 security_id;bool inserted;
@@ -904,7 +896,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, }/* Deal with NTFS extended attribute. */ - err =ntfs_set_ea (inode, name, name_len, value, size, flags,0 ); + err =ntfs_set_ea (inode, name,strlen (name), value, size, flags,0 ); out: inode->i_ctime =current_time (inode);
Signature · 1 line
2.17.1
Konstantin Komarov
maintainerQuoted 89 lines · Yuan Can
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]>--- fs/ntfs3/xattr.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)fs/ntfs3/xattr.c +7
-15@@ -720,11 +720,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, {int err;struct ntfs_inode *ni =ntfs_i (inode); -size_t name_len =strlen (name);/* Dispatch request. */ -if (name_len ==sizeof (SYSTEM_DOS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_DOS_ATTRIB ,sizeof (SYSTEM_DOS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_DOS_ATTRIB )) {/* system.dos_attrib */ if (!buffer) { err =sizeof (u8);@@ -737,8 +735,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_NTFS_ATTRIB ,sizeof (SYSTEM_NTFS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_NTFS_ATTRIB )) {/* system.ntfs_attrib */ if (!buffer) { err =sizeof (u32);@@ -751,8 +748,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_SECURITY ) -1 && - !memcmp (name,SYSTEM_NTFS_SECURITY ,sizeof (SYSTEM_NTFS_SECURITY ))) { +if (!strcmp (name,SYSTEM_NTFS_SECURITY )) {/* system.ntfs_security*/ struct SECURITY_DESCRIPTOR_RELATIVE *sd =NULL ;size_t sd_size =0 ;@@ -792,7 +788,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, }/* Deal with NTFS extended attribute. */ - err =ntfs_get_ea (inode, name, name_len, buffer, size,NULL ); + err =ntfs_get_ea (inode, name,strlen (name), buffer, size,NULL ); out:return err;@@ -809,20 +805,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, {int err = -EINVAL ;struct ntfs_inode *ni =ntfs_i (inode); -size_t name_len =strlen (name);enum FILE_ATTRIBUTE new_fa;/* Dispatch request. */ -if (name_len ==sizeof (SYSTEM_DOS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_DOS_ATTRIB ,sizeof (SYSTEM_DOS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_DOS_ATTRIB )) {if (sizeof (u8) != size) goto out; new_fa =cpu_to_le32 (*(u8 *)value); goto set_new_fa; } -if (name_len ==sizeof (SYSTEM_NTFS_ATTRIB ) -1 && - !memcmp (name,SYSTEM_NTFS_ATTRIB ,sizeof (SYSTEM_NTFS_ATTRIB ))) { +if (!strcmp (name,SYSTEM_NTFS_ATTRIB )) {if (size !=sizeof (u32)) goto out; new_fa =cpu_to_le32 (*(u32 *)value);@@ -860,8 +853,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, goto out; } -if (name_len ==sizeof (SYSTEM_NTFS_SECURITY ) -1 && - !memcmp (name,SYSTEM_NTFS_SECURITY ,sizeof (SYSTEM_NTFS_SECURITY ))) { +if (!strcmp (name,SYSTEM_NTFS_SECURITY )) {/* system.ntfs_security*/ __le32 security_id;bool inserted;
fs/ntfs3/xattr.c static noinline int ntfs_setxattr(const struct xattr_handler *handler, · line 902
Quoted 8 lines
fs/ntfs3/xattr.c +1
-1@@ -904,7 +896,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, }/* Deal with NTFS extended attribute. */ - err =ntfs_set_ea (inode, name, name_len, value, size, flags,0 ); + err =ntfs_set_ea (inode, name,strlen (name), value, size, flags,0 ); out: inode->i_ctime =current_time (inode);
Thank you for your work!
I've fixed code under CONFIG_NTFS3_FS_POSIX_ACL and applied.