3b45951f5706add0d4d0262fe0bef4106c7b6243
[openwrt/staging/ansuel.git] /
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
5
6 Convert link tx and rx device attr to a common macro to reduce common
7 code and in preparation for additional attr.
8
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
13 ---
14 drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++-------------------
15 1 file changed, 16 insertions(+), 41 deletions(-)
16
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
20 return size;
21 }
22
23 -static ssize_t link_show(struct device *dev,
24 - struct device_attribute *attr, char *buf)
25 -{
26 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK);
27 -}
28 -
29 -static ssize_t link_store(struct device *dev,
30 - struct device_attribute *attr, const char *buf, size_t size)
31 -{
32 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK);
33 -}
34 -
35 -static DEVICE_ATTR_RW(link);
36 -
37 -static ssize_t tx_show(struct device *dev,
38 - struct device_attribute *attr, char *buf)
39 -{
40 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX);
41 -}
42 -
43 -static ssize_t tx_store(struct device *dev,
44 - struct device_attribute *attr, const char *buf, size_t size)
45 -{
46 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX);
47 -}
48 -
49 -static DEVICE_ATTR_RW(tx);
50 -
51 -static ssize_t rx_show(struct device *dev,
52 - struct device_attribute *attr, char *buf)
53 -{
54 - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX);
55 -}
56 -
57 -static ssize_t rx_store(struct device *dev,
58 - struct device_attribute *attr, const char *buf, size_t size)
59 -{
60 - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX);
61 -}
62 -
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) \
67 + { \
68 + return netdev_led_attr_show(dev, buf, trigger); \
69 + } \
70 + static ssize_t trigger_name##_store(struct device *dev, \
71 + struct device_attribute *attr, const char *buf, size_t size) \
72 + { \
73 + return netdev_led_attr_store(dev, buf, size, trigger); \
74 + } \
75 + static DEVICE_ATTR_RW(trigger_name)
76 +
77 +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK);
78 +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX);
79 +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX);
80
81 static ssize_t interval_show(struct device *dev,
82 struct device_attribute *attr, char *buf)