linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86: acer-wmi: use true and false for boolean values
@ 2018-08-05  0:18 Gustavo A. R. Silva
  2018-08-05 10:26 ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2018-08-05  0:18 UTC (permalink / raw)
  To: Lee, Chun-Yi, Darren Hart, Andy Shevchenko
  Cc: platform-driver-x86, linux-kernel, Gustavo A. R. Silva

Return statements in functions returning bool should use true or false
instead of an integer value.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/platform/x86/acer-wmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 8952173..ede92be 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -673,9 +673,9 @@ static void __init find_quirks(void)
 static bool has_cap(u32 cap)
 {
 	if ((interface->capability & cap) != 0)
-		return 1;
+		return true;
 
-	return 0;
+	return false;
 }
 
 /*
-- 
2.7.4


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

* Re: [PATCH] platform/x86: acer-wmi: use true and false for boolean values
  2018-08-05  0:18 [PATCH] platform/x86: acer-wmi: use true and false for boolean values Gustavo A. R. Silva
@ 2018-08-05 10:26 ` Andy Shevchenko
  2018-08-06 16:41   ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2018-08-05 10:26 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Lee, Chun-Yi, Darren Hart, Andy Shevchenko, Platform Driver,
	Linux Kernel Mailing List

On Sun, Aug 5, 2018 at 3:18 AM, Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
> Return statements in functions returning bool should use true or false
> instead of an integer value.
>
> This code was detected with the help of Coccinelle.

>  static bool has_cap(u32 cap)
>  {
>         if ((interface->capability & cap) != 0)
> -               return 1;
> +               return true;
>
> -       return 0;
> +       return false;
>  }

this entire function can be oneliner:

return !!(...);


-- 
With Best Regards,
Andy Shevchenko

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

* RE: [PATCH] platform/x86: acer-wmi: use true and false for boolean values
  2018-08-05 10:26 ` Andy Shevchenko
@ 2018-08-06 16:41   ` David Laight
  2018-08-06 16:42     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2018-08-06 16:41 UTC (permalink / raw)
  To: 'Andy Shevchenko', Gustavo A. R. Silva
  Cc: Lee, Chun-Yi, Darren Hart, Andy Shevchenko, Platform Driver,
	Linux Kernel Mailing List

From: Andy Shevchenko
> Sent: 05 August 2018 11:26
> 
> On Sun, Aug 5, 2018 at 3:18 AM, Gustavo A. R. Silva
> <gustavo@embeddedor.com> wrote:
> > Return statements in functions returning bool should use true or false
> > instead of an integer value.
> >
> > This code was detected with the help of Coccinelle.
> 
> >  static bool has_cap(u32 cap)
> >  {
> >         if ((interface->capability & cap) != 0)
> > -               return 1;
> > +               return true;
> >
> > -       return 0;
> > +       return false;
> >  }
> 
> this entire function can be oneliner:
> 
> return !!(...);

Why the !! ?? Just:
	return (interface->capability & cap) != 0;

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

* Re: [PATCH] platform/x86: acer-wmi: use true and false for boolean values
  2018-08-06 16:41   ` David Laight
@ 2018-08-06 16:42     ` Joe Perches
  2018-08-06 17:24       ` Gustavo A. R. Silva
  2018-08-06 19:06       ` Andy Shevchenko
  0 siblings, 2 replies; 6+ messages in thread
From: Joe Perches @ 2018-08-06 16:42 UTC (permalink / raw)
  To: David Laight, 'Andy Shevchenko', Gustavo A. R. Silva
  Cc: Lee, Chun-Yi, Darren Hart, Andy Shevchenko, Platform Driver,
	Linux Kernel Mailing List

On Mon, 2018-08-06 at 16:41 +0000, David Laight wrote:
> From: Andy Shevchenko
> > Sent: 05 August 2018 11:26
> > 
> > On Sun, Aug 5, 2018 at 3:18 AM, Gustavo A. R. Silva
> > <gustavo@embeddedor.com> wrote:
> > > Return statements in functions returning bool should use true or false
> > > instead of an integer value.
> > > 
> > > This code was detected with the help of Coccinelle.
> > >  static bool has_cap(u32 cap)
> > >  {
> > >         if ((interface->capability & cap) != 0)
> > > -               return 1;
> > > +               return true;
> > > 
> > > -       return 0;
> > > +       return false;
> > >  }
> > 
> > this entire function can be oneliner:
> > 
> > return !!(...);
> 
> Why the !! ?? Just:
> 	return (interface->capability & cap) != 0;

Because the return is bool you don't need the !! either.
The compiler does that.


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

* Re: [PATCH] platform/x86: acer-wmi: use true and false for boolean values
  2018-08-06 16:42     ` Joe Perches
@ 2018-08-06 17:24       ` Gustavo A. R. Silva
  2018-08-06 19:06       ` Andy Shevchenko
  1 sibling, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2018-08-06 17:24 UTC (permalink / raw)
  To: Joe Perches, David Laight, 'Andy Shevchenko'
  Cc: Lee, Chun-Yi, Darren Hart, Andy Shevchenko, Platform Driver,
	Linux Kernel Mailing List



On 08/06/2018 11:42 AM, Joe Perches wrote:
> On Mon, 2018-08-06 at 16:41 +0000, David Laight wrote:
>> From: Andy Shevchenko
>>> Sent: 05 August 2018 11:26
>>>
>>> On Sun, Aug 5, 2018 at 3:18 AM, Gustavo A. R. Silva
>>> <gustavo@embeddedor.com> wrote:
>>>> Return statements in functions returning bool should use true or false
>>>> instead of an integer value.
>>>>
>>>> This code was detected with the help of Coccinelle.
>>>>  static bool has_cap(u32 cap)
>>>>  {
>>>>         if ((interface->capability & cap) != 0)
>>>> -               return 1;
>>>> +               return true;
>>>>
>>>> -       return 0;
>>>> +       return false;
>>>>  }
>>>
>>> this entire function can be oneliner:
>>>
>>> return !!(...);
>>
>> Why the !! ?? Just:
>> 	return (interface->capability & cap) != 0;
> 
> Because the return is bool you don't need the !! either.
> The compiler does that.
> 

Hi all,

I'll send v2 with the suggested improvements.

Thanks for your feedback.
--
Gustavo

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

* Re: [PATCH] platform/x86: acer-wmi: use true and false for boolean values
  2018-08-06 16:42     ` Joe Perches
  2018-08-06 17:24       ` Gustavo A. R. Silva
@ 2018-08-06 19:06       ` Andy Shevchenko
  1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2018-08-06 19:06 UTC (permalink / raw)
  To: Joe Perches
  Cc: David Laight, Gustavo A. R. Silva, Lee, Chun-Yi, Darren Hart,
	Andy Shevchenko, Platform Driver, Linux Kernel Mailing List

On Mon, Aug 6, 2018 at 7:42 PM, Joe Perches <joe@perches.com> wrote:
> On Mon, 2018-08-06 at 16:41 +0000, David Laight wrote:
>> From: Andy Shevchenko
>> > Sent: 05 August 2018 11:26

>> > >  static bool has_cap(u32 cap)
>> > >  {
>> > >         if ((interface->capability & cap) != 0)
>> > > -               return 1;
>> > > +               return true;
>> > >
>> > > -       return 0;
>> > > +       return false;
>> > >  }
>> >
>> > this entire function can be oneliner:
>> >
>> > return !!(...);
>>
>> Why the !! ?? Just:
>>       return (interface->capability & cap) != 0;
>
> Because the return is bool you don't need the !! either.
> The compiler does that.

True, I use that pattern, but in most cases the return value is int
and this is just to guarantee the 0,1 possible range.

-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2018-08-06 19:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-05  0:18 [PATCH] platform/x86: acer-wmi: use true and false for boolean values Gustavo A. R. Silva
2018-08-05 10:26 ` Andy Shevchenko
2018-08-06 16:41   ` David Laight
2018-08-06 16:42     ` Joe Perches
2018-08-06 17:24       ` Gustavo A. R. Silva
2018-08-06 19:06       ` Andy Shevchenko

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).