3c804c0b412e3cb33b390c298024e106e585f55b
[openwrt/staging/neocturne.git] /
1 From 28a6a2ef18ad840a390d519840c303b03040961c Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Mon, 29 May 2023 18:32:34 +0200
4 Subject: [PATCH 04/13] leds: trigger: netdev: refactor code setting device
5 name
6
7 Move the code into a helper, ready for it to be called at
8 other times. No intended behaviour change.
9
10 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
11 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14 drivers/leds/trigger/ledtrig-netdev.c | 29 ++++++++++++++++++---------
15 1 file changed, 20 insertions(+), 9 deletions(-)
16
17 --- a/drivers/leds/trigger/ledtrig-netdev.c
18 +++ b/drivers/leds/trigger/ledtrig-netdev.c
19 @@ -104,15 +104,9 @@ static ssize_t device_name_show(struct d
20 return len;
21 }
22
23 -static ssize_t device_name_store(struct device *dev,
24 - struct device_attribute *attr, const char *buf,
25 - size_t size)
26 +static int set_device_name(struct led_netdev_data *trigger_data,
27 + const char *name, size_t size)
28 {
29 - struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
30 -
31 - if (size >= IFNAMSIZ)
32 - return -EINVAL;
33 -
34 cancel_delayed_work_sync(&trigger_data->work);
35
36 mutex_lock(&trigger_data->lock);
37 @@ -122,7 +116,7 @@ static ssize_t device_name_store(struct
38 trigger_data->net_dev = NULL;
39 }
40
41 - memcpy(trigger_data->device_name, buf, size);
42 + memcpy(trigger_data->device_name, name, size);
43 trigger_data->device_name[size] = 0;
44 if (size > 0 && trigger_data->device_name[size - 1] == '\n')
45 trigger_data->device_name[size - 1] = 0;
46 @@ -140,6 +134,23 @@ static ssize_t device_name_store(struct
47 set_baseline_state(trigger_data);
48 mutex_unlock(&trigger_data->lock);
49
50 + return 0;
51 +}
52 +
53 +static ssize_t device_name_store(struct device *dev,
54 + struct device_attribute *attr, const char *buf,
55 + size_t size)
56 +{
57 + struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
58 + int ret;
59 +
60 + if (size >= IFNAMSIZ)
61 + return -EINVAL;
62 +
63 + ret = set_device_name(trigger_data, buf, size);
64 +
65 + if (ret < 0)
66 + return ret;
67 return size;
68 }
69