723-v5.12-net-dsa-move-switchdev-event-implementation-under-th.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 447d290a58bd335d68f665713842365d3d6447df Mon Sep 17 00:00:00 2001
  2. From: Vladimir Oltean <[email protected]>
  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. We'll need to start listening to SWITCHDEV_FDB_{ADD,DEL}_TO_DEVICE
  7. events even for interfaces where dsa_slave_dev_check returns false, so
  8. we need that check inside the switch-case statement for SWITCHDEV_FDB_*.
  9. This movement also avoids a useless allocation / free of switchdev_work
  10. on the untreated "default event" case.
  11. Signed-off-by: Vladimir Oltean <[email protected]>
  12. Reviewed-by: Florian Fainelli <[email protected]>
  13. Signed-off-by: Jakub Kicinski <[email protected]>
  14. ---
  15. net/dsa/slave.c | 35 ++++++++++++++++-------------------
  16. 1 file changed, 16 insertions(+), 19 deletions(-)
  17. --- a/net/dsa/slave.c
  18. +++ b/net/dsa/slave.c
  19. @@ -2159,31 +2159,29 @@ static int dsa_slave_switchdev_event(str
  20. struct dsa_port *dp;
  21. int err;
  22. - if (event == SWITCHDEV_PORT_ATTR_SET) {
  23. + switch (event) {
  24. + case SWITCHDEV_PORT_ATTR_SET:
  25. err = switchdev_handle_port_attr_set(dev, ptr,
  26. dsa_slave_dev_check,
  27. dsa_slave_port_attr_set);
  28. return notifier_from_errno(err);
  29. - }
  30. -
  31. - if (!dsa_slave_dev_check(dev))
  32. - return NOTIFY_DONE;
  33. + case SWITCHDEV_FDB_ADD_TO_DEVICE:
  34. + case SWITCHDEV_FDB_DEL_TO_DEVICE:
  35. + if (!dsa_slave_dev_check(dev))
  36. + return NOTIFY_DONE;
  37. - dp = dsa_slave_to_port(dev);
  38. + dp = dsa_slave_to_port(dev);
  39. - switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
  40. - if (!switchdev_work)
  41. - return NOTIFY_BAD;
  42. -
  43. - INIT_WORK(&switchdev_work->work,
  44. - dsa_slave_switchdev_event_work);
  45. - switchdev_work->ds = dp->ds;
  46. - switchdev_work->port = dp->index;
  47. - switchdev_work->event = event;
  48. + switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
  49. + if (!switchdev_work)
  50. + return NOTIFY_BAD;
  51. +
  52. + INIT_WORK(&switchdev_work->work,
  53. + dsa_slave_switchdev_event_work);
  54. + switchdev_work->ds = dp->ds;
  55. + switchdev_work->port = dp->index;
  56. + switchdev_work->event = event;
  57. - switch (event) {
  58. - case SWITCHDEV_FDB_ADD_TO_DEVICE:
  59. - case SWITCHDEV_FDB_DEL_TO_DEVICE:
  60. fdb_info = ptr;
  61. if (!fdb_info->added_by_user) {
  62. @@ -2196,13 +2194,12 @@ static int dsa_slave_switchdev_event(str
  63. switchdev_work->vid = fdb_info->vid;
  64. dev_hold(dev);
  65. + dsa_schedule_work(&switchdev_work->work);
  66. break;
  67. default:
  68. - kfree(switchdev_work);
  69. return NOTIFY_DONE;
  70. }
  71. - dsa_schedule_work(&switchdev_work->work);
  72. return NOTIFY_OK;
  73. }