platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/olpc: fix 'logical not is only applied to the left hand side'
@ 2022-07-15 15:15 Alexander Lobakin
  2022-07-15 15:45 ` Yury Norov
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Lobakin @ 2022-07-15 15:15 UTC (permalink / raw)
  To: Yury Norov
  Cc: Alexander Lobakin, Guenter Roeck, Darren Hart, Andy Shevchenko,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	platform-driver-x86, stable, linux-kernel, kernel test robot

The bitops compile-time optimization series revealed one more
problem in olpc-xo1-sci.c:send_ebook_state(), resulted in GCC
warnings:

arch/x86/platform/olpc/olpc-xo1-sci.c: In function 'send_ebook_state':
arch/x86/platform/olpc/olpc-xo1-sci.c:83:63: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   83 |         if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state)
      |                                                               ^~
arch/x86/platform/olpc/olpc-xo1-sci.c:83:13: note: add parentheses around left hand side expression to silence this warning

Despite this code working as intended, this redundant double
negation of boolean value, together with comparing to `char`
with no explicit conversion to bool, makes compilers think
the author made some unintentional logical mistakes here.
Make it the other way around and negate the char instead
to silence the warnings.

Fixes: d2aa37411b8e ("x86/olpc/xo1/sci: Produce wakeup events for buttons and switches")
Cc: stable@vger.kernel.org # 3.5+
Reported-by: Guenter Roeck <linux@roeck-us.net>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-and-tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 arch/x86/platform/olpc/olpc-xo1-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c
index f03a6883dcc6..89f25af4b3c3 100644
--- a/arch/x86/platform/olpc/olpc-xo1-sci.c
+++ b/arch/x86/platform/olpc/olpc-xo1-sci.c
@@ -80,7 +80,7 @@ static void send_ebook_state(void)
 		return;
 	}
 
-	if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state)
+	if (test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == !!state)
 		return; /* Nothing new to report. */
 
 	input_report_switch(ebook_switch_idev, SW_TABLET_MODE, state);
-- 
2.36.1


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

* Re: [PATCH] x86/olpc: fix 'logical not is only applied to the left hand side'
  2022-07-15 15:15 [PATCH] x86/olpc: fix 'logical not is only applied to the left hand side' Alexander Lobakin
@ 2022-07-15 15:45 ` Yury Norov
  0 siblings, 0 replies; 2+ messages in thread
From: Yury Norov @ 2022-07-15 15:45 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Guenter Roeck, Darren Hart, Andy Shevchenko, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	platform-driver-x86, stable, linux-kernel, kernel test robot

On Fri, Jul 15, 2022 at 05:15:36PM +0200, Alexander Lobakin wrote:
> The bitops compile-time optimization series revealed one more
> problem in olpc-xo1-sci.c:send_ebook_state(), resulted in GCC
> warnings:
> 
> arch/x86/platform/olpc/olpc-xo1-sci.c: In function 'send_ebook_state':
> arch/x86/platform/olpc/olpc-xo1-sci.c:83:63: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
>    83 |         if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state)
>       |                                                               ^~
> arch/x86/platform/olpc/olpc-xo1-sci.c:83:13: note: add parentheses around left hand side expression to silence this warning
> 
> Despite this code working as intended, this redundant double
> negation of boolean value, together with comparing to `char`
> with no explicit conversion to bool, makes compilers think
> the author made some unintentional logical mistakes here.
> Make it the other way around and negate the char instead
> to silence the warnings.
> 
> Fixes: d2aa37411b8e ("x86/olpc/xo1/sci: Produce wakeup events for buttons and switches")
> Cc: stable@vger.kernel.org # 3.5+
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Reported-by: kernel test robot <lkp@intel.com>
> Reviewed-and-tested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>

Applied, thanks!

> ---
>  arch/x86/platform/olpc/olpc-xo1-sci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c
> index f03a6883dcc6..89f25af4b3c3 100644
> --- a/arch/x86/platform/olpc/olpc-xo1-sci.c
> +++ b/arch/x86/platform/olpc/olpc-xo1-sci.c
> @@ -80,7 +80,7 @@ static void send_ebook_state(void)
>  		return;
>  	}
>  
> -	if (!!test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == state)
> +	if (test_bit(SW_TABLET_MODE, ebook_switch_idev->sw) == !!state)
>  		return; /* Nothing new to report. */
>  
>  	input_report_switch(ebook_switch_idev, SW_TABLET_MODE, state);
> -- 
> 2.36.1

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

end of thread, other threads:[~2022-07-15 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 15:15 [PATCH] x86/olpc: fix 'logical not is only applied to the left hand side' Alexander Lobakin
2022-07-15 15:45 ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).