public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Fix use of logical '&&' with constant operand
@ 2025-03-04 10:52 WangYuli
  2025-03-04 12:00 ` Huacai Chen
  2025-03-13 21:57 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: WangYuli @ 2025-03-04 10:52 UTC (permalink / raw)
  To: chenhuacai, kernel
  Cc: yangtiezhu, maobibo, guoweikang.kernel, agordeev, ast,
	usamaarif642, jiaxun.yang, wangyuli, loongarch, linux-kernel,
	zhanjun, niecheng1, chenlinxuan, donmor3000, Wentao Guan

Fix follow error with clang-19:

arch/loongarch/kernel/setup.c:335:40: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand]
  335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
      |                                               ^  ~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/setup.c:335:40: note: use '&' for a bitwise operation
  335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
      |                                               ^~
      |                                               &
arch/loongarch/kernel/setup.c:335:40: note: remove constant to silence this warning
  335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
      |                                               ^~~~~~~~~~~~~~~~~~~~
1 error generated.

Fixes: 83da30d73b86 ("LoongArch: Fix CMDLINE_EXTEND and CMDLINE_BOOTLOADER handling")
Co-developed-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Yuli Wang <wangyuli@uniontech.com>
---
 arch/loongarch/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index edcfdfcad7d2..834bea7f42da 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -332,7 +332,7 @@ static void __init bootcmdline_init(char **cmdline_p)
 	 * Append built-in command line to the bootloader command line if
 	 * CONFIG_CMDLINE_EXTEND is enabled.
 	 */
-	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
+	if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && !!CONFIG_CMDLINE[0]) {
 		strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
 		strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 	}
-- 
2.47.2


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

* Re: [PATCH] LoongArch: Fix use of logical '&&' with constant operand
  2025-03-04 10:52 [PATCH] LoongArch: Fix use of logical '&&' with constant operand WangYuli
@ 2025-03-04 12:00 ` Huacai Chen
  2025-03-12  2:38   ` WangYuli
  2025-03-13 21:57 ` David Laight
  1 sibling, 1 reply; 4+ messages in thread
From: Huacai Chen @ 2025-03-04 12:00 UTC (permalink / raw)
  To: WangYuli
  Cc: kernel, yangtiezhu, maobibo, guoweikang.kernel, agordeev, ast,
	usamaarif642, jiaxun.yang, loongarch, linux-kernel, zhanjun,
	niecheng1, chenlinxuan, donmor3000, Wentao Guan

On Tue, Mar 4, 2025 at 6:53 PM WangYuli <wangyuli@uniontech.com> wrote:
>
> Fix follow error with clang-19:
>
> arch/loongarch/kernel/setup.c:335:40: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand]
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^  ~~~~~~~~~~~~~~~~~
> arch/loongarch/kernel/setup.c:335:40: note: use '&' for a bitwise operation
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^~
>       |                                               &
> arch/loongarch/kernel/setup.c:335:40: note: remove constant to silence this warning
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^~~~~~~~~~~~~~~~~~~~
> 1 error generated.
Are you kidding me? CONFIG_CMDLINE[0] is a constant for a specific
config but the config is variable across buildings. So the "constant"
for compilers is not as "constant" for people. Compiler warnings
should be double-checked by people, right?

Huacai

>
> Fixes: 83da30d73b86 ("LoongArch: Fix CMDLINE_EXTEND and CMDLINE_BOOTLOADER handling")
> Co-developed-by: Wentao Guan <guanwentao@uniontech.com>
> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
> Signed-off-by: Yuli Wang <wangyuli@uniontech.com>
> ---
>  arch/loongarch/kernel/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index edcfdfcad7d2..834bea7f42da 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -332,7 +332,7 @@ static void __init bootcmdline_init(char **cmdline_p)
>          * Append built-in command line to the bootloader command line if
>          * CONFIG_CMDLINE_EXTEND is enabled.
>          */
> -       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
> +       if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && !!CONFIG_CMDLINE[0]) {
>                 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
>                 strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
>         }
> --
> 2.47.2
>

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

* Re: [PATCH] LoongArch: Fix use of logical '&&' with constant operand
  2025-03-04 12:00 ` Huacai Chen
@ 2025-03-12  2:38   ` WangYuli
  0 siblings, 0 replies; 4+ messages in thread
From: WangYuli @ 2025-03-12  2:38 UTC (permalink / raw)
  To: Huacai Chen
  Cc: kernel, yangtiezhu, maobibo, guoweikang.kernel, agordeev, ast,
	usamaarif642, jiaxun.yang, loongarch, linux-kernel, zhanjun,
	niecheng1, chenlinxuan, donmor3000, Wentao Guan


[-- Attachment #1.1.1: Type: text/plain, Size: 1312 bytes --]

Hi Huacai,

On 2025/3/4 20:00, Huacai Chen wrote:
> Are you kidding me?

nope

> CONFIG_CMDLINE[0] is a constant for a specific
> config but the config is variable across buildings. So the "constant"
> for compilers is not as "constant" for people.

Perhaps I'm not fully understanding your point.

 From my vantage point, it appears that all that's necessary is to 
ascertain whether CONFIG_CMDLINE[0] is a null value.

Given that the ASCII representation of NUL is indeed 0, this method of 
boolean coercion followed by a logical conjunction with the antecedent 
boolean value should not impinge upon the intended operationality of 
this line of code, and it further obviates a compilation warning.

To be precise, amending !!CONFIG_CMDLINE[0] to (CONFIG_CMDLINE[0] == 0) 
or converting the logical AND to a bitwise AND operation would also 
likely engender a commensurate outcome.

I merely opted for one modification strategy and patched it.

> Compiler warnings
> should be double-checked by people, right?

Naturally.

Compilers are, in essence, just sophisticated software programs, and are 
susceptible to numerous imperfections.

Nonetheless, for the most part, the warnings and error reports they 
output are typically justified.


Thanks.

-- 
Yuli Wang*
*

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 645 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

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

* Re: [PATCH] LoongArch: Fix use of logical '&&' with constant operand
  2025-03-04 10:52 [PATCH] LoongArch: Fix use of logical '&&' with constant operand WangYuli
  2025-03-04 12:00 ` Huacai Chen
@ 2025-03-13 21:57 ` David Laight
  1 sibling, 0 replies; 4+ messages in thread
From: David Laight @ 2025-03-13 21:57 UTC (permalink / raw)
  To: WangYuli
  Cc: chenhuacai, kernel, yangtiezhu, maobibo, guoweikang.kernel,
	agordeev, ast, usamaarif642, jiaxun.yang, loongarch, linux-kernel,
	zhanjun, niecheng1, chenlinxuan, donmor3000, Wentao Guan

On Tue,  4 Mar 2025 18:52:46 +0800
WangYuli <wangyuli@uniontech.com> wrote:

> Fix follow error with clang-19:
> 
> arch/loongarch/kernel/setup.c:335:40: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand]
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^  ~~~~~~~~~~~~~~~~~
> arch/loongarch/kernel/setup.c:335:40: note: use '&' for a bitwise operation
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^~
>       |                                               &
> arch/loongarch/kernel/setup.c:335:40: note: remove constant to silence this warning
>   335 |         if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
>       |                                               ^~~~~~~~~~~~~~~~~~~~
> 1 error generated.

Isn't that just 'an error too far' ?

There is nothing really wrong with compile-time constants in conditionals.
The kernel is full of them.

Why not just disable the warning?

	David

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

end of thread, other threads:[~2025-03-13 21:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 10:52 [PATCH] LoongArch: Fix use of logical '&&' with constant operand WangYuli
2025-03-04 12:00 ` Huacai Chen
2025-03-12  2:38   ` WangYuli
2025-03-13 21:57 ` David Laight

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