diff mbox

platform/x86: peaq-wmi: silence a static checker warning

Message ID 20170718092849.nim5tiaycdenfyfz@mwanda (mailing list archive)
State Superseded, archived
Delegated to: Andy Shevchenko
Headers show

Commit Message

Dan Carpenter July 18, 2017, 9:28 a.m. UTC
Static checkers complain because:

	if (peaq_ignore_events_counter && --peaq_ignore_events_counter >= 0)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The second part of the condition is always true because
"peaq_ignore_events_counter" is unsigned.  It doesn't cause a problem
because the first part of the condition prevents underflows, but it's
simple enough to make the static checker happy.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Andy Shevchenko July 18, 2017, 3:08 p.m. UTC | #1
On Tue, Jul 18, 2017 at 12:28 PM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> Static checkers complain because:
>
>         if (peaq_ignore_events_counter && --peaq_ignore_events_counter >= 0)
>                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The second part of the condition is always true because
> "peaq_ignore_events_counter" is unsigned.  It doesn't cause a problem
> because the first part of the condition prevents underflows, but it's
> simple enough to make the static checker happy.

Isn't it the same to

if (peaq_ignore_events_counter && peaq_ignore_events_counter--)

?
Dan Carpenter July 18, 2017, 7:02 p.m. UTC | #2
On Tue, Jul 18, 2017 at 06:08:30PM +0300, Andy Shevchenko wrote:
> On Tue, Jul 18, 2017 at 12:28 PM, Dan Carpenter
> <dan.carpenter@oracle.com> wrote:
> > Static checkers complain because:
> >
> >         if (peaq_ignore_events_counter && --peaq_ignore_events_counter >= 0)
> >                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > The second part of the condition is always true because
> > "peaq_ignore_events_counter" is unsigned.  It doesn't cause a problem
> > because the first part of the condition prevents underflows, but it's
> > simple enough to make the static checker happy.
> 
> Isn't it the same to
> 
> if (peaq_ignore_events_counter && peaq_ignore_events_counter--)
> 
> ?

Yeah.  That's probably a little cleaner.  I'll resend.

regards,
dan carpenter
diff mbox

Patch

diff --git a/drivers/platform/x86/peaq-wmi.c b/drivers/platform/x86/peaq-wmi.c
index 77d1f90b0794..ab5d5b060587 100644
--- a/drivers/platform/x86/peaq-wmi.c
+++ b/drivers/platform/x86/peaq-wmi.c
@@ -20,7 +20,7 @@ 
 
 MODULE_ALIAS("wmi:"PEAQ_DOLBY_BUTTON_GUID);
 
-static unsigned int peaq_ignore_events_counter;
+static int peaq_ignore_events_counter;
 static struct input_polled_dev *peaq_poll_dev;
 
 /*