818-v6.5-09-leds-trigger-netdev-validate-configured-netdev.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 33ec0b53befff2c0a7f3aa19ff08556d60585d6b Mon Sep 17 00:00:00 2001
  2. From: Andrew Lunn <[email protected]>
  3. Date: Mon, 29 May 2023 18:32:39 +0200
  4. Subject: [PATCH 09/13] leds: trigger: netdev: validate configured netdev
  5. The netdev which the LED should blink for is configurable in
  6. /sys/class/led/foo/device_name. Ensure when offloading that the
  7. configured netdev is the same as the netdev the LED is associated
  8. with. If it is not, only perform software blinking.
  9. Signed-off-by: Andrew Lunn <[email protected]>
  10. Signed-off-by: Christian Marangi <[email protected]>
  11. Signed-off-by: David S. Miller <[email protected]>
  12. ---
  13. drivers/leds/trigger/ledtrig-netdev.c | 24 ++++++++++++++++++++++--
  14. 1 file changed, 22 insertions(+), 2 deletions(-)
  15. --- a/drivers/leds/trigger/ledtrig-netdev.c
  16. +++ b/drivers/leds/trigger/ledtrig-netdev.c
  17. @@ -110,6 +110,24 @@ static bool supports_hw_control(struct l
  18. return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name);
  19. }
  20. +/*
  21. + * Validate the configured netdev is the same as the one associated with
  22. + * the LED driver in hw control.
  23. + */
  24. +static bool validate_net_dev(struct led_classdev *led_cdev,
  25. + struct net_device *net_dev)
  26. +{
  27. + struct device *dev = led_cdev->hw_control_get_device(led_cdev);
  28. + struct net_device *ndev;
  29. +
  30. + if (!dev)
  31. + return false;
  32. +
  33. + ndev = to_net_dev(dev);
  34. +
  35. + return ndev == net_dev;
  36. +}
  37. +
  38. static bool can_hw_control(struct led_netdev_data *trigger_data)
  39. {
  40. unsigned long default_interval = msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL);
  41. @@ -131,9 +149,11 @@ static bool can_hw_control(struct led_ne
  42. /*
  43. * net_dev must be set with hw control, otherwise no
  44. * blinking can be happening and there is nothing to
  45. - * offloaded.
  46. + * offloaded. Additionally, for hw control to be
  47. + * valid, the configured netdev must be the same as
  48. + * netdev associated to the LED.
  49. */
  50. - if (!trigger_data->net_dev)
  51. + if (!validate_net_dev(led_cdev, trigger_data->net_dev))
  52. return false;
  53. /* Check if the requested mode is supported */