Skip to contentSkip to conversation

smc: return booleans instead of integers

PATCH In review Gustavo A. R. Silva 4 participants 5 messages Jan 19, 2018 – Jan 23, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 smc: return booleans instead of integers

Return statements in functions returning bool should use true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

---
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(-)
net/smc/smc.h +2 -2
index 0bee9d1..6328565 100644
@@ -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
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 23 lines · Gustavo A. R. Silva

Return statements in functions returning bool should use true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

---
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(-)
net/smc/smc.h +0 -1
index 0bee9d1..6328565 100644
@@ -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;

net/smc/smc.h static inline int smc_uncompress_bufsize(u8 compressed) · line 264

Quoted 10 lines
net/smc/smc.h +2 -1
+		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

#2 lore raw

Quoting Ursula Braun <[email protected]>:

[...]

Quoted 4 lines

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

#3 lore raw
In reply to Ursula Braun
Quoted 13 lines · Ursula Braun
Quoted 11 lines · Gustavo A. R. Silva

Return statements in functions returning bool should use true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

---
Changes in v2:
- Fix function using_ipsec as suggested by Ursula Braun.
- Update subject line.

Quoted 4 lines

net/smc/smc.h

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

[]

Quoted 6 lines

net/smc/smc.h static inline int smc_uncompress_bufsize(u8 compressed) · line 256

Quoted 6 lines
net/smc/smc.h +1 -1
@@ -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;
#4 lore raw
Quoted 28 lines · Joe Perches
Quoted 13 lines · Ursula Braun
Quoted 11 lines · Gustavo A. R. Silva

Return statements in functions returning bool should use true/false instead of 1/0.

This issue was detected with the help of Coccinelle.

---
Changes in v2:
- Fix function using_ipsec as suggested by Ursula Braun.
- Update subject line.

Quoted 4 lines

net/smc/smc.h

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

[]

Quoted 6 lines

net/smc/smc.h static inline int smc_uncompress_bufsize(u8 compressed) · line 256

Quoted 6 lines
net/smc/smc.h +1 -1
@@ -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

Quoted 6 lines
	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?