Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests/vDSO: Fix assignment in condition without parentheses
@ 2024-04-29 20:34 Edward Liaw
  2024-04-30  0:17 ` Justin Stitt
  0 siblings, 1 reply; 2+ messages in thread
From: Edward Liaw @ 2024-04-29 20:34 UTC (permalink / raw)
  To: linux-kernel, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, H. Peter Anvin, Andy Lutomirski
  Cc: linux-kselftest, kernel-team, Edward Liaw, llvm

Fixes clang compiler warnings by adding parentheses:

parse_vdso.c:65:9: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
                if (g = h & 0xf0000000)
                    ~~^~~~~~~~~~~~~~~~
parse_vdso.c:65:9: note: place parentheses around the assignment to silence this warning
                if (g = h & 0xf0000000)
                      ^
                    (                 )
parse_vdso.c:65:9: note: use '==' to turn this assignment into an equality comparison
                if (g = h & 0xf0000000)
                      ^
                      ==

Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser")
Signed-off-by: Edward Liaw <edliaw@google.com>
---
 tools/testing/selftests/vDSO/parse_vdso.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c
index 413f75620a35..b9cf771006da 100644
--- a/tools/testing/selftests/vDSO/parse_vdso.c
+++ b/tools/testing/selftests/vDSO/parse_vdso.c
@@ -62,7 +62,7 @@ static unsigned long elf_hash(const unsigned char *name)
 	while (*name)
 	{
 		h = (h << 4) + *name++;
-		if (g = h & 0xf0000000)
+		if ((g = h & 0xf0000000))
 			h ^= g >> 24;
 		h &= ~g;
 	}
-- 
2.44.0.769.g3c40516874-goog


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

* Re: [PATCH] selftests/vDSO: Fix assignment in condition without parentheses
  2024-04-29 20:34 [PATCH] selftests/vDSO: Fix assignment in condition without parentheses Edward Liaw
@ 2024-04-30  0:17 ` Justin Stitt
  0 siblings, 0 replies; 2+ messages in thread
From: Justin Stitt @ 2024-04-30  0:17 UTC (permalink / raw)
  To: Edward Liaw
  Cc: linux-kernel, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, H. Peter Anvin, Andy Lutomirski, linux-kselftest,
	kernel-team, llvm

On Mon, Apr 29, 2024 at 08:34:36PM +0000, Edward Liaw wrote:
> Fixes clang compiler warnings by adding parentheses:
> 
> parse_vdso.c:65:9: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
>                 if (g = h & 0xf0000000)
>                     ~~^~~~~~~~~~~~~~~~
> parse_vdso.c:65:9: note: place parentheses around the assignment to silence this warning
>                 if (g = h & 0xf0000000)
>                       ^
>                     (                 )
> parse_vdso.c:65:9: note: use '==' to turn this assignment into an equality comparison
>                 if (g = h & 0xf0000000)
>                       ^
>                       ==
> 
> Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser")
> Signed-off-by: Edward Liaw <edliaw@google.com>

For readability's sake, I tend to prefer just taking the assignment out
of the if statement:

g = h & 0xf0000000;
then testing it:
if (g) ...

but as it stands it's fine and the warning goes away.

Reviewed-by: Justin Stitt <justinstitt@google.com>
> ---
>  tools/testing/selftests/vDSO/parse_vdso.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c
> index 413f75620a35..b9cf771006da 100644
> --- a/tools/testing/selftests/vDSO/parse_vdso.c
> +++ b/tools/testing/selftests/vDSO/parse_vdso.c
> @@ -62,7 +62,7 @@ static unsigned long elf_hash(const unsigned char *name)
>  	while (*name)
>  	{
>  		h = (h << 4) + *name++;
> -		if (g = h & 0xf0000000)
> +		if ((g = h & 0xf0000000))
>  			h ^= g >> 24;
>  		h &= ~g;
>  	}
> -- 
> 2.44.0.769.g3c40516874-goog
> 

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

end of thread, other threads:[~2024-04-30  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-29 20:34 [PATCH] selftests/vDSO: Fix assignment in condition without parentheses Edward Liaw
2024-04-30  0:17 ` Justin Stitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox