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
7 Move the code into a helper, ready for it to be called at
8 other times. No intended behaviour change.
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>
14 drivers/leds/trigger/ledtrig-netdev.c | 29 ++++++++++++++++++---------
15 1 file changed, 20 insertions(+), 9 deletions(-)
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
23 -static ssize_t device_name_store(struct device *dev,
24 - struct device_attribute *attr, const char *buf,
26 +static int set_device_name(struct led_netdev_data *trigger_data,
27 + const char *name, size_t size)
29 - struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
31 - if (size >= IFNAMSIZ)
34 cancel_delayed_work_sync(&trigger_data->work);
36 mutex_lock(&trigger_data->lock);
37 @@ -122,7 +116,7 @@ static ssize_t device_name_store(struct
38 trigger_data->net_dev = NULL;
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);
53 +static ssize_t device_name_store(struct device *dev,
54 + struct device_attribute *attr, const char *buf,
57 + struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
60 + if (size >= IFNAMSIZ)
63 + ret = set_device_name(trigger_data, buf, size);