diff mbox series

[v2] smc: return booleans instead of integers

Message ID 20180119205450.GA10785@embeddedgus
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show
Series [v2] smc: return booleans instead of integers | expand

Commit Message

Gustavo A. R. Silva Jan. 19, 2018, 8:54 p.m. UTC
Return statements in functions returning bool should use
true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 - Fix function using_ipsec as suggested by Ursula Braun.
 - Update subject line.

 net/smc/smc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ursula Braun Jan. 22, 2018, 11:58 a.m. UTC | #1
On 01/19/2018 09:54 PM, Gustavo A. R. Silva wrote:
> Return statements in functions returning bool should use
> true/false instead of 1/0.
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> Changes in v2:
>  - Fix function using_ipsec as suggested by Ursula Braun.
>  - Update subject line.
> 
>  net/smc/smc.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/smc/smc.h b/net/smc/smc.h
> index 0bee9d1..6328565 100644
> --- a/net/smc/smc.h
> +++ b/net/smc/smc.h
> @@ -253,12 +253,12 @@ static inline int smc_uncompress_bufsize(u8 compressed)
>  static inline bool using_ipsec(struct smc_sock *smc)
>  {
>  	return (smc->clcsock->sk->sk_policy[0] ||
> -		smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
> +		smc->clcsock->sk->sk_policy[1]) ? true : false;
>  }
>  #else
>  static inline bool using_ipsec(struct smc_sock *smc)
>  {
> -	return 0;
> +	return false;
>  }
>  #endif
> 

Thanks, Gustavo. I have added the patch to our local repository. It will
be part of one of my next patch sets to be sent to Dave Miller.

Regards, Ursula
Gustavo A. R. Silva Jan. 22, 2018, 11:38 p.m. UTC | #2
Quoting Ursula Braun <ubraun@linux.vnet.ibm.com>:

[...]

>
> Thanks, Gustavo. I have added the patch to our local repository. It will
> be part of one of my next patch sets to be sent to Dave Miller.
>


Thanks, Ursula :)

--
Gustavo
Joe Perches Jan. 23, 2018, 12:31 a.m. UTC | #3
On Mon, 2018-01-22 at 12:58 +0100, Ursula Braun wrote:
> 
> On 01/19/2018 09:54 PM, Gustavo A. R. Silva wrote:
> > Return statements in functions returning bool should use
> > true/false instead of 1/0.
> > 
> > This issue was detected with the help of Coccinelle.
> > 
> > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > ---
> > Changes in v2:
> >  - Fix function using_ipsec as suggested by Ursula Braun.
> >  - Update subject line.
> > 
> >  net/smc/smc.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/net/smc/smc.h b/net/smc/smc.h
[]
> > @@ -253,12 +253,12 @@ static inline int smc_uncompress_bufsize(u8 compressed)
> >  static inline bool using_ipsec(struct smc_sock *smc)
> >  {
> >  	return (smc->clcsock->sk->sk_policy[0] ||
> > -		smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
> > +		smc->clcsock->sk->sk_policy[1]) ? true : false;

Generally, any bool return like

	return condition ? true : false;

could be written

	return condition;
Ursula Braun Jan. 23, 2018, 11:44 a.m. UTC | #4
On 01/23/2018 01:31 AM, Joe Perches wrote:
> On Mon, 2018-01-22 at 12:58 +0100, Ursula Braun wrote:
>>
>> On 01/19/2018 09:54 PM, Gustavo A. R. Silva wrote:
>>> Return statements in functions returning bool should use
>>> true/false instead of 1/0.
>>>
>>> This issue was detected with the help of Coccinelle.
>>>
>>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>>> ---
>>> Changes in v2:
>>>  - Fix function using_ipsec as suggested by Ursula Braun.
>>>  - Update subject line.
>>>
>>>  net/smc/smc.h | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/net/smc/smc.h b/net/smc/smc.h
> []
>>> @@ -253,12 +253,12 @@ static inline int smc_uncompress_bufsize(u8 compressed)
>>>  static inline bool using_ipsec(struct smc_sock *smc)
>>>  {
>>>  	return (smc->clcsock->sk->sk_policy[0] ||
>>> -		smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
>>> +		smc->clcsock->sk->sk_policy[1]) ? true : false;
> 
> Generally, any bool return like
> 
> 	return condition ? true : false;
> 
> could be written
> 
> 	return condition;
> 
This would be shorter, but is it really better readable/understandable?
Do you have a reference for us confirming your proposed style is the way to go?
diff mbox series

Patch

diff --git a/net/smc/smc.h b/net/smc/smc.h
index 0bee9d1..6328565 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -253,12 +253,12 @@  static inline int smc_uncompress_bufsize(u8 compressed)
 static inline bool using_ipsec(struct smc_sock *smc)
 {
 	return (smc->clcsock->sk->sk_policy[0] ||
-		smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
+		smc->clcsock->sk->sk_policy[1]) ? true : false;
 }
 #else
 static inline bool using_ipsec(struct smc_sock *smc)
 {
-	return 0;
+	return false;
 }
 #endif