2020-03-11 02:44:04

by Joe Perches

[permalink] [raw]
Subject: [PATCH] sfc: ethtool: Refactor to remove fallthrough comments in case blocks

Converting fallthrough comments to fallthrough; creates warnings
in this code when compiled with gcc.

This code is overly complicated and reads rather better with a
little refactoring and no fallthrough uses at all.

Remove the fallthrough comments and simplify the written source
code while reducing the object code size.

Consolidate duplicated switch/case blocks for IPV4 and IPV6.

defconfig x86-64 with sfc:

$ size drivers/net/ethernet/sfc/ethtool.o*
text data bss dec hex filename
10055 12 0 10067 2753 drivers/net/ethernet/sfc/ethtool.o.new
10135 12 0 10147 27a3 drivers/net/ethernet/sfc/ethtool.o.old

Signed-off-by: Joe Perches <[email protected]>
---
drivers/net/ethernet/sfc/ethtool.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/sfc/ethtool.c b/drivers/net/ethernet/sfc/ethtool.c
index 993b57..9a637cd 100644
--- a/drivers/net/ethernet/sfc/ethtool.c
+++ b/drivers/net/ethernet/sfc/ethtool.c
@@ -582,6 +582,7 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,

case ETHTOOL_GRXFH: {
struct efx_rss_context *ctx = &efx->rss_context;
+ __u64 data;

mutex_lock(&efx->rss_lock);
if (info->flow_type & FLOW_RSS && info->rss_context) {
@@ -591,35 +592,38 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
goto out_unlock;
}
}
- info->data = 0;
+
+ data = 0;
if (!efx_rss_active(ctx)) /* No RSS */
- goto out_unlock;
+ goto out_setdata_unlock;
+
switch (info->flow_type & ~FLOW_RSS) {
case UDP_V4_FLOW:
- if (ctx->rx_hash_udp_4tuple)
- /* fall through */
- case TCP_V4_FLOW:
- info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
- /* fall through */
- case SCTP_V4_FLOW:
- case AH_ESP_V4_FLOW:
- case IPV4_FLOW:
- info->data |= RXH_IP_SRC | RXH_IP_DST;
- break;
case UDP_V6_FLOW:
if (ctx->rx_hash_udp_4tuple)
- /* fall through */
+ data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
+ RXH_IP_SRC | RXH_IP_DST);
+ else
+ data = RXH_IP_SRC | RXH_IP_DST;
+ break;
+ case TCP_V4_FLOW:
case TCP_V6_FLOW:
- info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
- /* fall through */
+ data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
+ RXH_IP_SRC | RXH_IP_DST);
+ break;
+ case SCTP_V4_FLOW:
case SCTP_V6_FLOW:
+ case AH_ESP_V4_FLOW:
case AH_ESP_V6_FLOW:
+ case IPV4_FLOW:
case IPV6_FLOW:
- info->data |= RXH_IP_SRC | RXH_IP_DST;
+ data = RXH_IP_SRC | RXH_IP_DST;
break;
default:
break;
}
+out_setdata_unlock:
+ info->data = data;
out_unlock:
mutex_unlock(&efx->rss_lock);
return rc;



2020-03-12 09:51:36

by Martin Habets

[permalink] [raw]
Subject: Re: [PATCH] sfc: ethtool: Refactor to remove fallthrough comments in case blocks

On 11/03/2020 02:41, Joe Perches wrote:
> Converting fallthrough comments to fallthrough; creates warnings
> in this code when compiled with gcc.
>
> This code is overly complicated and reads rather better with a
> little refactoring and no fallthrough uses at all.
>
> Remove the fallthrough comments and simplify the written source
> code while reducing the object code size.
>
> Consolidate duplicated switch/case blocks for IPV4 and IPV6.
>
> defconfig x86-64 with sfc:
>
> $ size drivers/net/ethernet/sfc/ethtool.o*
> text data bss dec hex filename
> 10055 12 0 10067 2753 drivers/net/ethernet/sfc/ethtool.o.new
> 10135 12 0 10147 27a3 drivers/net/ethernet/sfc/ethtool.o.old
>
> Signed-off-by: Joe Perches <[email protected]>

Acked-by: Martin Habets <[email protected]>

> ---
> drivers/net/ethernet/sfc/ethtool.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/sfc/ethtool.c b/drivers/net/ethernet/sfc/ethtool.c
> index 993b57..9a637cd 100644
> --- a/drivers/net/ethernet/sfc/ethtool.c
> +++ b/drivers/net/ethernet/sfc/ethtool.c
> @@ -582,6 +582,7 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
>
> case ETHTOOL_GRXFH: {
> struct efx_rss_context *ctx = &efx->rss_context;
> + __u64 data;
>
> mutex_lock(&efx->rss_lock);
> if (info->flow_type & FLOW_RSS && info->rss_context) {
> @@ -591,35 +592,38 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
> goto out_unlock;
> }
> }
> - info->data = 0;
> +
> + data = 0;
> if (!efx_rss_active(ctx)) /* No RSS */
> - goto out_unlock;
> + goto out_setdata_unlock;
> +
> switch (info->flow_type & ~FLOW_RSS) {
> case UDP_V4_FLOW:
> - if (ctx->rx_hash_udp_4tuple)
> - /* fall through */
> - case TCP_V4_FLOW:
> - info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
> - /* fall through */
> - case SCTP_V4_FLOW:
> - case AH_ESP_V4_FLOW:
> - case IPV4_FLOW:
> - info->data |= RXH_IP_SRC | RXH_IP_DST;
> - break;
> case UDP_V6_FLOW:
> if (ctx->rx_hash_udp_4tuple)
> - /* fall through */
> + data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> + RXH_IP_SRC | RXH_IP_DST);
> + else
> + data = RXH_IP_SRC | RXH_IP_DST;
> + break;
> + case TCP_V4_FLOW:
> case TCP_V6_FLOW:
> - info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
> - /* fall through */
> + data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> + RXH_IP_SRC | RXH_IP_DST);
> + break;
> + case SCTP_V4_FLOW:
> case SCTP_V6_FLOW:
> + case AH_ESP_V4_FLOW:
> case AH_ESP_V6_FLOW:
> + case IPV4_FLOW:
> case IPV6_FLOW:
> - info->data |= RXH_IP_SRC | RXH_IP_DST;
> + data = RXH_IP_SRC | RXH_IP_DST;
> break;
> default:
> break;
> }
> +out_setdata_unlock:
> + info->data = data;
> out_unlock:
> mutex_unlock(&efx->rss_lock);
> return rc;
>
>

2020-03-12 18:30:41

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] sfc: ethtool: Refactor to remove fallthrough comments in case blocks

From: Joe Perches <[email protected]>
Date: Tue, 10 Mar 2020 19:41:41 -0700

> Converting fallthrough comments to fallthrough; creates warnings
> in this code when compiled with gcc.
>
> This code is overly complicated and reads rather better with a
> little refactoring and no fallthrough uses at all.
>
> Remove the fallthrough comments and simplify the written source
> code while reducing the object code size.
>
> Consolidate duplicated switch/case blocks for IPV4 and IPV6.
>
> defconfig x86-64 with sfc:
>
> $ size drivers/net/ethernet/sfc/ethtool.o*
> text data bss dec hex filename
> 10055 12 0 10067 2753 drivers/net/ethernet/sfc/ethtool.o.new
> 10135 12 0 10147 27a3 drivers/net/ethernet/sfc/ethtool.o.old
>
> Signed-off-by: Joe Perches <[email protected]>

Applied to net-next.