All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare()
@ 2022-10-04 23:23 Nathan Chancellor
  2022-10-04 23:23 ` [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator " Nathan Chancellor
  2022-10-21 17:10 ` [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized " Nathan Chancellor
  0 siblings, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2022-10-04 23:23 UTC (permalink / raw)
  To: Konstantin Komarov
  Cc: Nick Desaulniers, Tom Rix, ntfs3, llvm, patches, linux-kernel,
	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.

Fixes: a3a956c78efa ("fs/ntfs3: Add option "nocase"")
Link: https://github.com/ClangBuiltLinux/linux/issues/1729
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---

v2:
    * Pick up Nick's reviewed-by tag.
v1: https://lore.kernel.org/20221004144145.1345772-1-nathan@kernel.org/

 fs/ntfs3/namei.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 315763eb05ff..5d3a6ce3f05f 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -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
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()
  2022-10-04 23:23 [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare() Nathan Chancellor
@ 2022-10-04 23:23 ` Nathan Chancellor
  2022-10-04 23:26   ` Nick Desaulniers
  2022-11-12 18:11   ` Konstantin Komarov
  2022-10-21 17:10 ` [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized " Nathan Chancellor
  1 sibling, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2022-10-04 23:23 UTC (permalink / raw)
  To: Konstantin Komarov
  Cc: Nick Desaulniers, Tom Rix, ntfs3, llvm, patches, linux-kernel,
	Nathan Chancellor

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

Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---

v2: New patch.

 fs/ntfs3/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 5d3a6ce3f05f..6b0d2c01d6ff 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()
  2022-10-04 23:23 ` [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator " Nathan Chancellor
@ 2022-10-04 23:26   ` Nick Desaulniers
  2022-11-12 18:11   ` Konstantin Komarov
  1 sibling, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2022-10-04 23:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Konstantin Komarov, Tom Rix, ntfs3, llvm, patches, linux-kernel

On Tue, Oct 4, 2022 at 4:24 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> 'a == b ? 0 : 1' is logically equivalent to 'a != b'.
>
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
> v2: New patch.
>
>  fs/ntfs3/namei.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
> index 5d3a6ce3f05f..6b0d2c01d6ff 100644
> --- a/fs/ntfs3/namei.c
> +++ b/fs/ntfs3/namei.c
> @@ -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
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare()
  2022-10-04 23:23 [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare() Nathan Chancellor
  2022-10-04 23:23 ` [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator " Nathan Chancellor
@ 2022-10-21 17:10 ` Nathan Chancellor
  2022-10-26 16:56   ` Konstantin Komarov
  1 sibling, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2022-10-21 17:10 UTC (permalink / raw)
  To: Konstantin Komarov
  Cc: Nick Desaulniers, Tom Rix, ntfs3, llvm, patches, linux-kernel

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

On Tue, Oct 04, 2022 at 04:23:58PM -0700, Nathan Chancellor wrote:
> 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.
> 
> Fixes: a3a956c78efa ("fs/ntfs3: Add option "nocase"")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1729
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> 
> v2:
>     * Pick up Nick's reviewed-by tag.
> v1: https://lore.kernel.org/20221004144145.1345772-1-nathan@kernel.org/
> 
>  fs/ntfs3/namei.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
> index 315763eb05ff..5d3a6ce3f05f 100644
> --- a/fs/ntfs3/namei.c
> +++ b/fs/ntfs3/namei.c
> @@ -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
> -- 
> 2.37.3
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare()
  2022-10-21 17:10 ` [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized " Nathan Chancellor
@ 2022-10-26 16:56   ` Konstantin Komarov
  0 siblings, 0 replies; 6+ messages in thread
From: Konstantin Komarov @ 2022-10-26 16:56 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Tom Rix, ntfs3, llvm, patches, linux-kernel



On 10/21/22 20:10, Nathan Chancellor wrote:
> Ping? This is still breaking our builds in -next...
> 

Thanks for patch, applied!

> On Tue, Oct 04, 2022 at 04:23:58PM -0700, Nathan Chancellor wrote:
>> 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.
>>
>> Fixes: a3a956c78efa ("fs/ntfs3: Add option "nocase"")
>> Link: https://github.com/ClangBuiltLinux/linux/issues/1729
>> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
>> ---
>>
>> v2:
>>      * Pick up Nick's reviewed-by tag.
>> v1: https://lore.kernel.org/20221004144145.1345772-1-nathan@kernel.org/
>>
>>   fs/ntfs3/namei.c | 12 ++++--------
>>   1 file changed, 4 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
>> index 315763eb05ff..5d3a6ce3f05f 100644
>> --- a/fs/ntfs3/namei.c
>> +++ b/fs/ntfs3/namei.c
>> @@ -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
>> -- 
>> 2.37.3
>>
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator in ntfs_d_compare()
  2022-10-04 23:23 ` [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator " Nathan Chancellor
  2022-10-04 23:26   ` Nick Desaulniers
@ 2022-11-12 18:11   ` Konstantin Komarov
  1 sibling, 0 replies; 6+ messages in thread
From: Konstantin Komarov @ 2022-11-12 18:11 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Tom Rix, ntfs3, llvm, patches, linux-kernel



On 10/5/22 02:23, Nathan Chancellor wrote:
> 'a == b ? 0 : 1' is logically equivalent to 'a != b'.
> 
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> 
> v2: New patch.
> 
>   fs/ntfs3/namei.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
> index 5d3a6ce3f05f..6b0d2c01d6ff 100644
> --- a/fs/ntfs3/namei.c
> +++ b/fs/ntfs3/namei.c
> @@ -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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-12 18:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04 23:23 [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized in ntfs_d_compare() Nathan Chancellor
2022-10-04 23:23 ` [PATCH -next v2 2/2] fs/ntfs3: Eliminate unnecessary ternary operator " Nathan Chancellor
2022-10-04 23:26   ` Nick Desaulniers
2022-11-12 18:11   ` Konstantin Komarov
2022-10-21 17:10 ` [PATCH -next v2 1/2] fs/ntfs3: Don't use uni1 uninitialized " Nathan Chancellor
2022-10-26 16:56   ` Konstantin Komarov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.