803-v6.5-04-leds-trigger-netdev-Convert-device-attr-to-macro.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 164b67d53476a9d114be85c885bd31f783835be4 Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Wed, 19 Apr 2023 23:07:42 +0200
  4. Subject: [PATCH 4/5] leds: trigger: netdev: Convert device attr to macro
  5. Convert link tx and rx device attr to a common macro to reduce common
  6. code and in preparation for additional attr.
  7. Signed-off-by: Christian Marangi <[email protected]>
  8. Reviewed-by: Andrew Lunn <[email protected]>
  9. Signed-off-by: Lee Jones <[email protected]>
  10. Link: https://lore.kernel.org/r/[email protected]
  11. ---
  12. drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++-------------------
  13. 1 file changed, 16 insertions(+), 41 deletions(-)
  14. --- a/drivers/leds/trigger/ledtrig-netdev.c
  15. +++ b/drivers/leds/trigger/ledtrig-netdev.c
  16. @@ -198,47 +198,22 @@ static ssize_t netdev_led_attr_store(str
  17. return size;
  18. }
  19. -static ssize_t link_show(struct device *dev,
  20. - struct device_attribute *attr, char *buf)
  21. -{
  22. - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK);
  23. -}
  24. -
  25. -static ssize_t link_store(struct device *dev,
  26. - struct device_attribute *attr, const char *buf, size_t size)
  27. -{
  28. - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK);
  29. -}
  30. -
  31. -static DEVICE_ATTR_RW(link);
  32. -
  33. -static ssize_t tx_show(struct device *dev,
  34. - struct device_attribute *attr, char *buf)
  35. -{
  36. - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX);
  37. -}
  38. -
  39. -static ssize_t tx_store(struct device *dev,
  40. - struct device_attribute *attr, const char *buf, size_t size)
  41. -{
  42. - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX);
  43. -}
  44. -
  45. -static DEVICE_ATTR_RW(tx);
  46. -
  47. -static ssize_t rx_show(struct device *dev,
  48. - struct device_attribute *attr, char *buf)
  49. -{
  50. - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX);
  51. -}
  52. -
  53. -static ssize_t rx_store(struct device *dev,
  54. - struct device_attribute *attr, const char *buf, size_t size)
  55. -{
  56. - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX);
  57. -}
  58. -
  59. -static DEVICE_ATTR_RW(rx);
  60. +#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \
  61. + static ssize_t trigger_name##_show(struct device *dev, \
  62. + struct device_attribute *attr, char *buf) \
  63. + { \
  64. + return netdev_led_attr_show(dev, buf, trigger); \
  65. + } \
  66. + static ssize_t trigger_name##_store(struct device *dev, \
  67. + struct device_attribute *attr, const char *buf, size_t size) \
  68. + { \
  69. + return netdev_led_attr_store(dev, buf, size, trigger); \
  70. + } \
  71. + static DEVICE_ATTR_RW(trigger_name)
  72. +
  73. +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK);
  74. +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX);
  75. +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX);
  76. static ssize_t interval_show(struct device *dev,
  77. struct device_attribute *attr, char *buf)