1 From 164b67d53476a9d114be85c885bd31f783835be4 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 19 Apr 2023 23:07:42 +0200
4 Subject: [PATCH 4/5] leds: trigger: netdev: Convert device attr to macro
6 Convert link tx and rx device attr to a common macro to reduce common
7 code and in preparation for additional attr.
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
10 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
11 Signed-off-by: Lee Jones <lee@kernel.org>
12 Link: https://lore.kernel.org/r/20230419210743.3594-5-ansuelsmth@gmail.com
14 drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++-------------------
15 1 file changed, 16 insertions(+), 41 deletions(-)
17 --- a/drivers/leds/trigger/ledtrig-netdev.c
18 +++ b/drivers/leds/trigger/ledtrig-netdev.c
19 @@ -198,47 +198,22 @@ static ssize_t netdev_led_attr_store(str
23 -static ssize_t link_show(struct device *dev,
24 - struct device_attribute *attr, char *buf)
26 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK);
29 -static ssize_t link_store(struct device *dev,
30 - struct device_attribute *attr, const char *buf, size_t size)
32 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK);
35 -static DEVICE_ATTR_RW(link);
37 -static ssize_t tx_show(struct device *dev,
38 - struct device_attribute *attr, char *buf)
40 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX);
43 -static ssize_t tx_store(struct device *dev,
44 - struct device_attribute *attr, const char *buf, size_t size)
46 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX);
49 -static DEVICE_ATTR_RW(tx);
51 -static ssize_t rx_show(struct device *dev,
52 - struct device_attribute *attr, char *buf)
54 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX);
57 -static ssize_t rx_store(struct device *dev,
58 - struct device_attribute *attr, const char *buf, size_t size)
60 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX);
63 -static DEVICE_ATTR_RW(rx);
64 +#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \
65 + static ssize_t trigger_name##_show(struct device *dev, \
66 + struct device_attribute *attr, char *buf) \
68 + return netdev_led_attr_show(dev, buf, trigger); \
70 + static ssize_t trigger_name##_store(struct device *dev, \
71 + struct device_attribute *attr, const char *buf, size_t size) \
73 + return netdev_led_attr_store(dev, buf, size, trigger); \
75 + static DEVICE_ATTR_RW(trigger_name)
77 +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK);
78 +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX);
79 +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX);
81 static ssize_t interval_show(struct device *dev,
82 struct device_attribute *attr, char *buf)