kernel: fix LED netdev trigger on interface rename
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 402-leds-trigger-netdev-fix-handling-on-interface-rename.patch
1 From 0ff035231edca3713c3d0839c44e64a4ac41ef38 Mon Sep 17 00:00:00 2001
2 From: Martin Schiller <ms@dev.tdt.de>
3 Date: Thu, 24 Oct 2019 15:09:23 +0200
4 Subject: [PATCH] leds: trigger: netdev: fix handling on interface rename
5
6 The NETDEV_CHANGENAME code is not "unneeded" like it is stated in commit
7 4cb6560514fa ("leds: trigger: netdev: fix refcnt leak on interface
8 rename").
9
10 The event was accidentally misinterpreted equivalent to
11 NETDEV_UNREGISTER, but should be equivalent to NETDEV_REGISTER.
12
13 This was the case in the original code from the openwrt project.
14
15 Otherwise, you are unable to set netdev led triggers for (non-existent)
16 netdevices, which has to be renamed. This is the case, for example, for
17 ppp interfaces in openwrt.
18
19 Fixes: 06f502f57d0d ("leds: trigger: Introduce a NETDEV trigger")
20 Fixes: 4cb6560514fa ("leds: trigger: netdev: fix refcnt leak on interface rename")
21 Signed-off-by: Martin Schiller <ms@dev.tdt.de>
22 ---
23 drivers/leds/trigger/ledtrig-netdev.c | 5 ++++-
24 1 file changed, 4 insertions(+), 1 deletion(-)
25
26 diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
27 index 136f86a1627d..d5e774d83021 100644
28 --- a/drivers/leds/trigger/ledtrig-netdev.c
29 +++ b/drivers/leds/trigger/ledtrig-netdev.c
30 @@ -302,10 +302,12 @@ static int netdev_trig_notify(struct notifier_block *nb,
31 container_of(nb, struct led_netdev_data, notifier);
32
33 if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE
34 - && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER)
35 + && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER
36 + && evt != NETDEV_CHANGENAME)
37 return NOTIFY_DONE;
38
39 if (!(dev == trigger_data->net_dev ||
40 + (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) ||
41 (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name))))
42 return NOTIFY_DONE;
43
44 @@ -315,6 +317,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
45
46 clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
47 switch (evt) {
48 + case NETDEV_CHANGENAME:
49 case NETDEV_REGISTER:
50 if (trigger_data->net_dev)
51 dev_put(trigger_data->net_dev);
52 --
53 2.20.1
54