b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From 447d290a58bd335d68f665713842365d3d6447df Mon Sep 17 00:00:00 2001 |
| 2 | From: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 3 | Date: Wed, 6 Jan 2021 11:51:33 +0200 |
| 4 | Subject: [PATCH] net: dsa: move switchdev event implementation under the same |
| 5 | switch/case statement |
| 6 | |
| 7 | We'll need to start listening to SWITCHDEV_FDB_{ADD,DEL}_TO_DEVICE |
| 8 | events even for interfaces where dsa_slave_dev_check returns false, so |
| 9 | we need that check inside the switch-case statement for SWITCHDEV_FDB_*. |
| 10 | |
| 11 | This movement also avoids a useless allocation / free of switchdev_work |
| 12 | on the untreated "default event" case. |
| 13 | |
| 14 | Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 15 | Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> |
| 16 | Signed-off-by: Jakub Kicinski <kuba@kernel.org> |
| 17 | --- |
| 18 | net/dsa/slave.c | 35 ++++++++++++++++------------------- |
| 19 | 1 file changed, 16 insertions(+), 19 deletions(-) |
| 20 | |
| 21 | --- a/net/dsa/slave.c |
| 22 | +++ b/net/dsa/slave.c |
| 23 | @@ -1638,31 +1638,29 @@ static int dsa_slave_switchdev_event(str |
| 24 | struct dsa_port *dp; |
| 25 | int err; |
| 26 | |
| 27 | - if (event == SWITCHDEV_PORT_ATTR_SET) { |
| 28 | + switch (event) { |
| 29 | + case SWITCHDEV_PORT_ATTR_SET: |
| 30 | err = switchdev_handle_port_attr_set(dev, ptr, |
| 31 | dsa_slave_dev_check, |
| 32 | dsa_slave_port_attr_set); |
| 33 | return notifier_from_errno(err); |
| 34 | - } |
| 35 | - |
| 36 | - if (!dsa_slave_dev_check(dev)) |
| 37 | - return NOTIFY_DONE; |
| 38 | + case SWITCHDEV_FDB_ADD_TO_DEVICE: |
| 39 | + case SWITCHDEV_FDB_DEL_TO_DEVICE: |
| 40 | + if (!dsa_slave_dev_check(dev)) |
| 41 | + return NOTIFY_DONE; |
| 42 | |
| 43 | - dp = dsa_slave_to_port(dev); |
| 44 | + dp = dsa_slave_to_port(dev); |
| 45 | |
| 46 | - switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); |
| 47 | - if (!switchdev_work) |
| 48 | - return NOTIFY_BAD; |
| 49 | - |
| 50 | - INIT_WORK(&switchdev_work->work, |
| 51 | - dsa_slave_switchdev_event_work); |
| 52 | - switchdev_work->ds = dp->ds; |
| 53 | - switchdev_work->port = dp->index; |
| 54 | - switchdev_work->event = event; |
| 55 | + switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); |
| 56 | + if (!switchdev_work) |
| 57 | + return NOTIFY_BAD; |
| 58 | + |
| 59 | + INIT_WORK(&switchdev_work->work, |
| 60 | + dsa_slave_switchdev_event_work); |
| 61 | + switchdev_work->ds = dp->ds; |
| 62 | + switchdev_work->port = dp->index; |
| 63 | + switchdev_work->event = event; |
| 64 | |
| 65 | - switch (event) { |
| 66 | - case SWITCHDEV_FDB_ADD_TO_DEVICE: /* fall through */ |
| 67 | - case SWITCHDEV_FDB_DEL_TO_DEVICE: |
| 68 | fdb_info = ptr; |
| 69 | |
| 70 | if (!fdb_info->added_by_user) { |
| 71 | @@ -1675,13 +1673,12 @@ static int dsa_slave_switchdev_event(str |
| 72 | switchdev_work->vid = fdb_info->vid; |
| 73 | |
| 74 | dev_hold(dev); |
| 75 | + dsa_schedule_work(&switchdev_work->work); |
| 76 | break; |
| 77 | default: |
| 78 | - kfree(switchdev_work); |
| 79 | return NOTIFY_DONE; |
| 80 | } |
| 81 | |
| 82 | - dsa_schedule_work(&switchdev_work->work); |
| 83 | return NOTIFY_OK; |
| 84 | } |
| 85 | |