diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2024-10-23 15:52:47 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-10-31 01:33:53 +0100 |
commit | a0af7162ccb501a22ac448ad94dad81757743725 (patch) | |
tree | 7373b5db23d6492eb61d772c8ee92c1f4ecda21e /net/dsa/user.c | |
parent | net: sched: propagate "skip_sw" flag to struct flow_cls_common_offload (diff) | |
download | linux-a0af7162ccb501a22ac448ad94dad81757743725.tar.xz linux-a0af7162ccb501a22ac448ad94dad81757743725.zip |
net: dsa: clean up dsa_user_add_cls_matchall()
The body is a bit hard to read, hard to extend, and has duplicated
conditions.
Clean up the "if (many conditions) else if (many conditions, some
of them repeated)" pattern by:
- Moving the repeated conditions out
- Replacing the repeated tests for the same variable with a switch/case
- Moving the protocol check inside the dsa_user_add_cls_matchall_mirred()
function call.
This is pure refactoring, no logic has been changed, though some tests
were reordered. The order does not matter - they are independent things
to be tested for.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20241023135251.1752488-3-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/dsa/user.c')
-rw-r--r-- | net/dsa/user.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/net/dsa/user.c b/net/dsa/user.c index 91a1fa5f8ab0..15f69fa6a38b 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -1376,6 +1376,9 @@ dsa_user_add_cls_matchall_mirred(struct net_device *dev, struct dsa_port *to_dp; int err; + if (cls->common.protocol != htons(ETH_P_ALL)) + return -EOPNOTSUPP; + if (!ds->ops->port_mirror_add) return -EOPNOTSUPP; @@ -1485,17 +1488,21 @@ static int dsa_user_add_cls_matchall(struct net_device *dev, struct tc_cls_matchall_offload *cls, bool ingress) { - int err = -EOPNOTSUPP; + const struct flow_action *action = &cls->rule->action; - if (cls->common.protocol == htons(ETH_P_ALL) && - flow_offload_has_one_action(&cls->rule->action) && - cls->rule->action.entries[0].id == FLOW_ACTION_MIRRED) - err = dsa_user_add_cls_matchall_mirred(dev, cls, ingress); - else if (flow_offload_has_one_action(&cls->rule->action) && - cls->rule->action.entries[0].id == FLOW_ACTION_POLICE) - err = dsa_user_add_cls_matchall_police(dev, cls, ingress); + if (!flow_offload_has_one_action(action)) + return -EOPNOTSUPP; - return err; + switch (action->entries[0].id) { + case FLOW_ACTION_MIRRED: + return dsa_user_add_cls_matchall_mirred(dev, cls, ingress); + case FLOW_ACTION_POLICE: + return dsa_user_add_cls_matchall_police(dev, cls, ingress); + default: + break; + } + + return -EOPNOTSUPP; } static void dsa_user_del_cls_matchall(struct net_device *dev, |