Skip to contentSkip to conversation

fs/ntfs3: use strcmp to determin attribute type

PATCH Superseded Yuan Can 2 participants 3 messages Sep 13, 2022 – Sep 24, 2022 NTFS3 filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 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.

---
 fs/ntfs3/xattr.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
fs/ntfs3/xattr.c +6 -14
index 7de8718c68a9..1776f0e783ea 100644
@@ -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;
@@ -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;
Signature · 1 line
2.17.1
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Yuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc5 next-20220913]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yuan-Can/fs-ntfs3-use-strcmp-to-determin-attribute-type/20220913-145102
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e839a756012b6cad7a4eeb67b0598ac3f349f863
config: hexagon-randconfig-r041-20220912 (https://download.01.org/0day-ci/archive/20220913/[email protected]/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 1546df49f5a6d09df78f569e4137ddb365a3e827)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/a3c3b0ca90ba6141ef6b740a3c1189277e49b0ae
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yuan-Can/fs-ntfs3-use-strcmp-to-determin-attribute-type/20220913-145102
git checkout a3c3b0ca90ba6141ef6b740a3c1189277e49b0ae
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/ufs/core/ fs/f2fs/ fs/ntfs3/

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

>> fs/ntfs3/xattr.c:869:33: error: use of undeclared identifier 'name_len'; did you mean 'range_len'?
           err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL);
                                          ^~~~~~~~
                                          range_len
   include/linux/range.h:11:19: note: 'range_len' declared here
   static inline u64 range_len(const struct range *range)
                     ^
   fs/ntfs3/xattr.c:993:33: error: use of undeclared identifier 'name_len'; did you mean 'range_len'?
           err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0);
                                          ^~~~~~~~
                                          range_len
   include/linux/range.h:11:19: note: 'range_len' declared here
   static inline u64 range_len(const struct range *range)
                     ^

2 errors generated.

vim +869 fs/ntfs3/xattr.c

be71b5cba2e648 Konstantin Komarov 2021-08-13  777  
be71b5cba2e648 Konstantin Komarov 2021-08-13  778  static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
be71b5cba2e648 Konstantin Komarov 2021-08-13  779  			 struct inode *inode, const char *name, void *buffer,
be71b5cba2e648 Konstantin Komarov 2021-08-13  780  			 size_t size)
be71b5cba2e648 Konstantin Komarov 2021-08-13  781  {
be71b5cba2e648 Konstantin Komarov 2021-08-13  782  	int err;
be71b5cba2e648 Konstantin Komarov 2021-08-13  783  	struct ntfs_inode *ni = ntfs_i(inode);
be71b5cba2e648 Konstantin Komarov 2021-08-13  784  
e8b8e97f91b80f Kari Argillander   2021-08-03  785  	/* Dispatch request. */
a3c3b0ca90ba61 Yuan Can           2022-09-13  786  	if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  787  		/* system.dos_attrib */
be71b5cba2e648 Konstantin Komarov 2021-08-13  788  		if (!buffer) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  789  			err = sizeof(u8);
be71b5cba2e648 Konstantin Komarov 2021-08-13  790  		} else if (size < sizeof(u8)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  791  			err = -ENODATA;
be71b5cba2e648 Konstantin Komarov 2021-08-13  792  		} else {
be71b5cba2e648 Konstantin Komarov 2021-08-13  793  			err = sizeof(u8);
be71b5cba2e648 Konstantin Komarov 2021-08-13  794  			*(u8 *)buffer = le32_to_cpu(ni->std_fa);
be71b5cba2e648 Konstantin Komarov 2021-08-13  795  		}
be71b5cba2e648 Konstantin Komarov 2021-08-13  796  		goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  797  	}
be71b5cba2e648 Konstantin Komarov 2021-08-13  798  
a3c3b0ca90ba61 Yuan Can           2022-09-13  799  	if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  800  		/* system.ntfs_attrib */
be71b5cba2e648 Konstantin Komarov 2021-08-13  801  		if (!buffer) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  802  			err = sizeof(u32);
be71b5cba2e648 Konstantin Komarov 2021-08-13  803  		} else if (size < sizeof(u32)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  804  			err = -ENODATA;
be71b5cba2e648 Konstantin Komarov 2021-08-13  805  		} else {
be71b5cba2e648 Konstantin Komarov 2021-08-13  806  			err = sizeof(u32);
be71b5cba2e648 Konstantin Komarov 2021-08-13  807  			*(u32 *)buffer = le32_to_cpu(ni->std_fa);
be71b5cba2e648 Konstantin Komarov 2021-08-13  808  		}
be71b5cba2e648 Konstantin Komarov 2021-08-13  809  		goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  810  	}
be71b5cba2e648 Konstantin Komarov 2021-08-13  811  
a3c3b0ca90ba61 Yuan Can           2022-09-13  812  	if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  813  		/* system.ntfs_security*/
be71b5cba2e648 Konstantin Komarov 2021-08-13  814  		struct SECURITY_DESCRIPTOR_RELATIVE *sd = NULL;
be71b5cba2e648 Konstantin Komarov 2021-08-13  815  		size_t sd_size = 0;
be71b5cba2e648 Konstantin Komarov 2021-08-13  816  
be71b5cba2e648 Konstantin Komarov 2021-08-13  817  		if (!is_ntfs3(ni->mi.sbi)) {
e8b8e97f91b80f Kari Argillander   2021-08-03  818  			/* We should get nt4 security. */
be71b5cba2e648 Konstantin Komarov 2021-08-13  819  			err = -EINVAL;
be71b5cba2e648 Konstantin Komarov 2021-08-13  820  			goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  821  		} else if (le32_to_cpu(ni->std_security_id) <
be71b5cba2e648 Konstantin Komarov 2021-08-13  822  			   SECURITY_ID_FIRST) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  823  			err = -ENOENT;
be71b5cba2e648 Konstantin Komarov 2021-08-13  824  			goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  825  		}
be71b5cba2e648 Konstantin Komarov 2021-08-13  826  
be71b5cba2e648 Konstantin Komarov 2021-08-13  827  		err = ntfs_get_security_by_id(ni->mi.sbi, ni->std_security_id,
be71b5cba2e648 Konstantin Komarov 2021-08-13  828  					      &sd, &sd_size);
be71b5cba2e648 Konstantin Komarov 2021-08-13  829  		if (err)
be71b5cba2e648 Konstantin Komarov 2021-08-13  830  			goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  831  
be71b5cba2e648 Konstantin Komarov 2021-08-13  832  		if (!is_sd_valid(sd, sd_size)) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  833  			ntfs_inode_warn(
be71b5cba2e648 Konstantin Komarov 2021-08-13  834  				inode,
be71b5cba2e648 Konstantin Komarov 2021-08-13  835  				"looks like you get incorrect security descriptor id=%u",
be71b5cba2e648 Konstantin Komarov 2021-08-13  836  				ni->std_security_id);
be71b5cba2e648 Konstantin Komarov 2021-08-13  837  		}
be71b5cba2e648 Konstantin Komarov 2021-08-13  838  
be71b5cba2e648 Konstantin Komarov 2021-08-13  839  		if (!buffer) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  840  			err = sd_size;
be71b5cba2e648 Konstantin Komarov 2021-08-13  841  		} else if (size < sd_size) {
be71b5cba2e648 Konstantin Komarov 2021-08-13  842  			err = -ENODATA;
be71b5cba2e648 Konstantin Komarov 2021-08-13  843  		} else {
be71b5cba2e648 Konstantin Komarov 2021-08-13  844  			err = sd_size;
be71b5cba2e648 Konstantin Komarov 2021-08-13  845  			memcpy(buffer, sd, sd_size);
be71b5cba2e648 Konstantin Komarov 2021-08-13  846  		}
195c52bdd5d5ec Kari Argillander   2021-08-24  847  		kfree(sd);
be71b5cba2e648 Konstantin Komarov 2021-08-13  848  		goto out;
be71b5cba2e648 Konstantin Komarov 2021-08-13  849  	}
be71b5cba2e648 Konstantin Komarov 2021-08-13  850  
87e21c99bad763 Konstantin Komarov 2021-10-22  851  #ifdef CONFIG_NTFS3_FS_POSIX_ACL
87e21c99bad763 Konstantin Komarov 2021-10-22  852  	if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
87e21c99bad763 Konstantin Komarov 2021-10-22  853  	     !memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
87e21c99bad763 Konstantin Komarov 2021-10-22  854  		     sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
87e21c99bad763 Konstantin Komarov 2021-10-22  855  	    (name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
87e21c99bad763 Konstantin Komarov 2021-10-22  856  	     !memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
87e21c99bad763 Konstantin Komarov 2021-10-22  857  		     sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
87e21c99bad763 Konstantin Komarov 2021-10-22  858  		/* TODO: init_user_ns? */
87e21c99bad763 Konstantin Komarov 2021-10-22  859  		err = ntfs_xattr_get_acl(
87e21c99bad763 Konstantin Komarov 2021-10-22  860  			&init_user_ns, inode,
87e21c99bad763 Konstantin Komarov 2021-10-22  861  			name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
87e21c99bad763 Konstantin Komarov 2021-10-22  862  				? ACL_TYPE_ACCESS
87e21c99bad763 Konstantin Komarov 2021-10-22  863  				: ACL_TYPE_DEFAULT,
87e21c99bad763 Konstantin Komarov 2021-10-22  864  			buffer, size);
87e21c99bad763 Konstantin Komarov 2021-10-22  865  		goto out;
87e21c99bad763 Konstantin Komarov 2021-10-22  866  	}
87e21c99bad763 Konstantin Komarov 2021-10-22  867  #endif
e8b8e97f91b80f Kari Argillander   2021-08-03  868  	/* Deal with NTFS extended attribute. */
be71b5cba2e648 Konstantin Komarov 2021-08-13 @869  	err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL);
be71b5cba2e648 Konstantin Komarov 2021-08-13  870  
be71b5cba2e648 Konstantin Komarov 2021-08-13  871  out:
be71b5cba2e648 Konstantin Komarov 2021-08-13  872  	return err;
be71b5cba2e648 Konstantin Komarov 2021-08-13  873  }
be71b5cba2e648 Konstantin Komarov 2021-08-13  874  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
author
#2 lore raw
Quoted 31 lines · kernel test robot

Hi Yuan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc5 next-20220913]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yuan-Can/fs-ntfs3-use-strcmp-to-determin-attribute-type/20220913-145102
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e839a756012b6cad7a4eeb67b0598ac3f349f863
config: hexagon-randconfig-r041-20220912 (https://download.01.org/0day-ci/archive/20220913/202209132249.HHQnBWE6-lkp(a)intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 1546df49f5a6d09df78f569e4137ddb365a3e827)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/a3c3b0ca90ba6141ef6b740a3c1189277e49b0ae
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yuan-Can/fs-ntfs3-use-strcmp-to-determin-attribute-type/20220913-145102
git checkout a3c3b0ca90ba6141ef6b740a3c1189277e49b0ae
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/ufs/core/ fs/f2fs/ fs/ntfs3/

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

fs/ntfs3/xattr.c:869:33: error: use of undeclared identifier 'name_len'; did you mean 'range_len'?

Quoted 14 lines

err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL);
^~~~~~~~
range_len
include/linux/range.h:11:19: note: 'range_len' declared here
static inline u64 range_len(const struct range *range)
^
fs/ntfs3/xattr.c:993:33: error: use of undeclared identifier 'name_len'; did you mean 'range_len'?
err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0);
^~~~~~~~
range_len
include/linux/range.h:11:19: note: 'range_len' declared here
static inline u64 range_len(const struct range *range)
^
2 errors generated.

Thanks for the report, the error related problems are fix in the v2 patch.

Best regards,
Yuan Can