Re: [net-next][PATCH] inet: Use switch case instead of multiple condition checks

2018-05-09 Thread Joe Perches
On Thu, 2018-05-10 at 13:37 +0800, Li RongQing wrote:
> inet_csk_reset_xmit_timer uses multiple equality condition checks,
> so it is better to use switch case instead of them
[]
> diff --git a/include/net/inet_connection_sock.h 
> b/include/net/inet_connection_sock.h
[]
> @@ -239,22 +239,31 @@ static inline void inet_csk_reset_xmit_timer(struct 
> sock *sk, const int what,
>   when = max_when;
>   }
>  
> - if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
> - what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
> - what == ICSK_TIME_REO_TIMEOUT) {
> + switch (what) {
> + case ICSK_TIME_RETRANS:
> + /* fall through */
> + case ICSK_TIME_PROBE0:
> + /* fall through */
> + case ICSK_TIME_EARLY_RETRANS:
> + /* fall through */
> + case ICSK_TIME_LOSS_PROBE:
> + /* fall through */
> + case ICSK_TIME_REO_TIMEOUT:

Please remove the /* fall through */ lines
and use consecutive case labels like:

case ICSK_TIME_RETRANS:
case ICSK_TIME_PROBE0:
case ICSK_TIME_EARLY_RETRANS:
case ICSK_TIME_LOSS_PROBE:
case ICSK_TIME_REO_TIMEOUT:



Re: [net-next][PATCH] inet: Use switch case instead of multiple condition checks

2018-05-09 Thread Eric Dumazet


On 05/09/2018 10:37 PM, Li RongQing wrote:
> inet_csk_reset_xmit_timer uses multiple equality condition checks,
> so it is better to use switch case instead of them
> 

Why is it better ?

I prefer the concise form, and compiler really should not care.





[net-next][PATCH] inet: Use switch case instead of multiple condition checks

2018-05-09 Thread Li RongQing
inet_csk_reset_xmit_timer uses multiple equality condition checks,
so it is better to use switch case instead of them

after this patch, the increased image size is acceptable

Before  After
size of net/ipv4/tcp_output.o:  721640  721648
size of vmlinux:400236400   400236401

Signed-off-by: Li RongQing 
---
 include/net/inet_connection_sock.h | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/net/inet_connection_sock.h 
b/include/net/inet_connection_sock.h
index 2ab6667275df..d2e9314cf43d 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -239,22 +239,31 @@ static inline void inet_csk_reset_xmit_timer(struct sock 
*sk, const int what,
when = max_when;
}
 
-   if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
-   what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
-   what == ICSK_TIME_REO_TIMEOUT) {
+   switch (what) {
+   case ICSK_TIME_RETRANS:
+   /* fall through */
+   case ICSK_TIME_PROBE0:
+   /* fall through */
+   case ICSK_TIME_EARLY_RETRANS:
+   /* fall through */
+   case ICSK_TIME_LOSS_PROBE:
+   /* fall through */
+   case ICSK_TIME_REO_TIMEOUT:
icsk->icsk_pending = what;
icsk->icsk_timeout = jiffies + when;
sk_reset_timer(sk, >icsk_retransmit_timer, 
icsk->icsk_timeout);
-   } else if (what == ICSK_TIME_DACK) {
+   break;
+   case ICSK_TIME_DACK:
icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
icsk->icsk_ack.timeout = jiffies + when;
sk_reset_timer(sk, >icsk_delack_timer, 
icsk->icsk_ack.timeout);
-   }
+   break;
 #ifdef INET_CSK_DEBUG
-   else {
+   default:
pr_debug("%s", inet_csk_timer_bug_msg);
-   }
+   break;
 #endif
+   }
 }
 
 static inline unsigned long
-- 
2.16.2