Skip to contentSkip to conversation

fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare()

PATCH In review Nathan Chancellor 3 participants 6 messages Oct 4, 2022 – Nov 12, 2022 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare()

Clang warns:

  fs/ntfs3/namei.c:445:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  if (toupper(c1) != toupper(c2)) {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/linux/ctype.h:64:20: note: expanded from macro 'toupper'
  #define toupper(c) __toupper(c)
                    ^
  fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
          __putname(uni1);
                    ^~~~
  ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
  #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                        ^~~~
  fs/ntfs3/namei.c:445:3: note: remove the 'if' if its condition is always false
                  if (toupper(c1) != toupper(c2)) {
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  fs/ntfs3/namei.c:434:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  if (!lm--) {
                      ^~~~~
  fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
          __putname(uni1);
                    ^~~~
  ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
  #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                        ^~~~
  fs/ntfs3/namei.c:434:3: note: remove the 'if' if its condition is always false
                  if (!lm--) {
                  ^~~~~~~~~~~~
  fs/ntfs3/namei.c:430:22: note: initialize the variable 'uni1' to silence this warning
          struct cpu_str *uni1, *uni2;
                              ^
                              = NULL
  2 errors generated.

There is no point in calling __putname() in these particular error paths, as there has been no corresponding __getname() call yet. Just return directly in these blocks to clear up the warning.

---

v2:
* Pick up Nick's reviewed-by tag.
v1: https://lore.kernel.org/[email protected]/

 fs/ntfs3/namei.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
fs/ntfs3/namei.c +4 -8
index 315763eb05ff..5d3a6ce3f05f 100644
@@ -431,10 +431,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 
 	/* First try fast implementation. */
 	for (;;) {
-		if (!lm--) {
-			ret = len1 == len2 ? 0 : 1;
-			goto out;
-		}
+		if (!lm--)
+			return len1 == len2 ? 0 : 1;
 
 		if ((c1 = *n1++) == (c2 = *n2++))
 			continue;
@@ -442,10 +440,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 		if (c1 >= 0x80 || c2 >= 0x80)
 			break;
 
-		if (toupper(c1) != toupper(c2)) {
-			ret = 1;
-			goto out;
-		}
+		if (toupper(c1) != toupper(c2))
+			return 1;
 	}
 
 	/*

base-commit: d45da67caedacd500879de5e649360cc70777af7

Signature · 1 line
2.37.3
#1 lore raw

PATCH v2 2/2 fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()

'a == b ? 0 : 1' is logically equivalent to 'a != b'.

---

v2: New patch.

 fs/ntfs3/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/namei.c +1 -1
index 5d3a6ce3f05f..6b0d2c01d6ff 100644
@@ -432,7 +432,7 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 	/* First try fast implementation. */
 	for (;;) {
 		if (!lm--)
-			return len1 == len2 ? 0 : 1;
+			return len1 != len2;
 
 		if ((c1 = *n1++) == (c2 = *n2++))
 			continue;
Signature · 1 line
2.37.3
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()

Quoted 5 lines · Nathan Chancellor

'a == b ? 0 : 1' is logically equivalent to 'a != b'.

Thanks for the patch!

Quoted 23 lines

---

v2: New patch.

 fs/ntfs3/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/namei.c +1 -2
index 5d3a6ce3f05f..6b0d2c01d6ff 100644
@@ -432,7 +432,7 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
        /* First try fast implementation. */
        for (;;) {
                if (!lm--)
-                       return len1 == len2 ? 0 : 1;
+                       return len1 != len2;
 
                if ((c1 = *n1++) == (c2 = *n2++))
                        continue;
--

2.37.3

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw

Re: [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()

In reply to Nathan Chancellor
Quoted 16 lines · Nathan Chancellor

'a == b ? 0 : 1' is logically equivalent to 'a != b'.

---

v2: New patch.

  fs/ntfs3/namei.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/namei.c +0 -0
index 5d3a6ce3f05f..6b0d2c01d6ff 100644

fs/ntfs3/namei.c static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1, · line 438

Quoted 8 lines
fs/ntfs3/namei.c +1 -1
@@ -432,7 +432,7 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
  	/* First try fast implementation. */
  	for (;;) {
  		if (!lm--)
-			return len1 == len2 ? 0 : 1;
+			return len1 != len2;
 
  		if ((c1 = *n1++) == (c2 = *n2++))
  			continue;

Thank you for your work, applied!
First patch was already applied.

#4 lore raw
In reply to Nathan Chancellor

Ping? This is still breaking our builds in -next...

Quoted 88 lines · Nathan Chancellor

Clang warns:

  fs/ntfs3/namei.c:445:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  if (toupper(c1) != toupper(c2)) {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/linux/ctype.h:64:20: note: expanded from macro 'toupper'
  #define toupper(c) __toupper(c)
                    ^
  fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
          __putname(uni1);
                    ^~~~
  ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
  #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                        ^~~~
  fs/ntfs3/namei.c:445:3: note: remove the 'if' if its condition is always false
                  if (toupper(c1) != toupper(c2)) {
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  fs/ntfs3/namei.c:434:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  if (!lm--) {
                      ^~~~~
  fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
          __putname(uni1);
                    ^~~~
  ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
  #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                        ^~~~
  fs/ntfs3/namei.c:434:3: note: remove the 'if' if its condition is always false
                  if (!lm--) {
                  ^~~~~~~~~~~~
  fs/ntfs3/namei.c:430:22: note: initialize the variable 'uni1' to silence this warning
          struct cpu_str *uni1, *uni2;
                              ^
                              = NULL
  2 errors generated.

There is no point in calling __putname() in these particular error paths, as there has been no corresponding __getname() call yet. Just return directly in these blocks to clear up the warning.

---

v2:
* Pick up Nick's reviewed-by tag.
v1: https://lore.kernel.org/[email protected]/

 fs/ntfs3/namei.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
fs/ntfs3/namei.c +4 -8
index 315763eb05ff..5d3a6ce3f05f 100644
@@ -431,10 +431,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 
 	/* First try fast implementation. */
 	for (;;) {
-		if (!lm--) {
-			ret = len1 == len2 ? 0 : 1;
-			goto out;
-		}
+		if (!lm--)
+			return len1 == len2 ? 0 : 1;
 
 		if ((c1 = *n1++) == (c2 = *n2++))
 			continue;
@@ -442,10 +440,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 		if (c1 >= 0x80 || c2 >= 0x80)
 			break;
 
-		if (toupper(c1) != toupper(c2)) {
-			ret = 1;
-			goto out;
-		}
+		if (toupper(c1) != toupper(c2))
+			return 1;
 	}
 
 	/*

base-commit: d45da67caedacd500879de5e649360cc70777af7

Signature · 1 line
2.37.3
#5 lore raw
Quoted 2 lines · Nathan Chancellor

Ping? This is still breaking our builds in -next...

Thanks for patch, applied!

Quoted 89 lines · Nathan Chancellor
Quoted 88 lines

Clang warns:

   fs/ntfs3/namei.c:445:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                   if (toupper(c1) != toupper(c2)) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
   ./include/linux/ctype.h:64:20: note: expanded from macro 'toupper'
   #define toupper(c) __toupper(c)
                     ^
   fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
           __putname(uni1);
                     ^~~~
   ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
   #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                         ^~~~
   fs/ntfs3/namei.c:445:3: note: remove the 'if' if its condition is always false
                   if (toupper(c1) != toupper(c2)) {
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/ntfs3/namei.c:434:7: error: variable 'uni1' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                   if (!lm--) {
                       ^~~~~
   fs/ntfs3/namei.c:487:12: note: uninitialized use occurs here
           __putname(uni1);
                     ^~~~
   ./include/linux/fs.h:2789:65: note: expanded from macro '__putname'
   #define __putname(name)         kmem_cache_free(names_cachep, (void *)(name))
                                                                         ^~~~
   fs/ntfs3/namei.c:434:3: note: remove the 'if' if its condition is always false
                   if (!lm--) {
                   ^~~~~~~~~~~~
   fs/ntfs3/namei.c:430:22: note: initialize the variable 'uni1' to silence this warning
           struct cpu_str *uni1, *uni2;
                               ^
                               = NULL
   2 errors generated.

There is no point in calling __putname() in these particular error paths, as there has been no corresponding __getname() call yet. Just return directly in these blocks to clear up the warning.

---

v2:
* Pick up Nick's reviewed-by tag.
v1: https://lore.kernel.org/[email protected]/

  fs/ntfs3/namei.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
fs/ntfs3/namei.c +4 -8
index 315763eb05ff..5d3a6ce3f05f 100644
@@ -431,10 +431,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
 
  	/* First try fast implementation. */
  	for (;;) {
-		if (!lm--) {
-			ret = len1 == len2 ? 0 : 1;
-			goto out;
-		}
+		if (!lm--)
+			return len1 == len2 ? 0 : 1;
 
  		if ((c1 = *n1++) == (c2 = *n2++))
  			continue;
@@ -442,10 +440,8 @@ static int ntfs_d_compare(const struct dentry *dentry, unsigned int len1,
  		if (c1 >= 0x80 || c2 >= 0x80)
  			break;
 
-		if (toupper(c1) != toupper(c2)) {
-			ret = 1;
-			goto out;
-		}
+		if (toupper(c1) != toupper(c2))
+			return 1;
  	}
 
  	/*

base-commit: d45da67caedacd500879de5e649360cc70777af7

Signature · 1 line
2.37.3