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
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_*.
11 This movement also avoids a useless allocation / free of switchdev_work
12 on the untreated "default event" case.
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>
18 net/dsa/slave.c | 35 ++++++++++++++++-------------------
19 1 file changed, 16 insertions(+), 19 deletions(-)
23 @@ -2122,31 +2122,29 @@ static int dsa_slave_switchdev_event(str
27 - if (event == SWITCHDEV_PORT_ATTR_SET) {
29 + case SWITCHDEV_PORT_ATTR_SET:
30 err = switchdev_handle_port_attr_set(dev, ptr,
32 dsa_slave_port_attr_set);
33 return notifier_from_errno(err);
36 - if (!dsa_slave_dev_check(dev))
38 + case SWITCHDEV_FDB_ADD_TO_DEVICE:
39 + case SWITCHDEV_FDB_DEL_TO_DEVICE:
40 + if (!dsa_slave_dev_check(dev))
43 - dp = dsa_slave_to_port(dev);
44 + dp = dsa_slave_to_port(dev);
46 - switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
47 - if (!switchdev_work)
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)
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;
66 - case SWITCHDEV_FDB_ADD_TO_DEVICE:
67 - case SWITCHDEV_FDB_DEL_TO_DEVICE:
70 if (!fdb_info->added_by_user) {
71 @@ -2159,13 +2157,12 @@ static int dsa_slave_switchdev_event(str
72 switchdev_work->vid = fdb_info->vid;
75 + dsa_schedule_work(&switchdev_work->work);
78 - kfree(switchdev_work);
82 - dsa_schedule_work(&switchdev_work->work);