8d391678ffb7c85989676c3c9fbf37c6ff9046c0
[openwrt/staging/blocktrron.git] /
1 From 12ce20e02e532f101b725d71c52a36c5cc8ad1e6 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sun, 4 Feb 2024 00:54:01 +0100
4 Subject: [PATCH] leds: trigger: netdev: Fix kernel panic on interface rename
5 trig notify
6
7 Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
8 speed mode") in the various changes, reworked the way to set the LINKUP
9 mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
10 NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.
11
12 This changed the logic where, in the previous implementation the dev
13 from the trigger event was used to check if the carrier was ok, but in
14 the new implementation with the generic function, the dev in
15 trigger_data is used instead.
16
17 This is problematic and cause a possible kernel panic due to the fact
18 that the dev in the trigger_data still reference the old one as the
19 new one (passed from the trigger event) still has to be hold and saved
20 in the trigger_data struct (done in the NETDEV_REGISTER case).
21
22 On calling of get_device_state(), an invalid net_dev is used and this
23 cause a kernel panic.
24
25 To handle this correctly, move the call to get_device_state() after the
26 new net_dev is correctly set in trigger_data (in the NETDEV_REGISTER
27 case) and correctly parse the new dev.
28
29 Fixes: d5e01266e7f5 ("leds: trigger: netdev: add additional specific link speed mode")
30 Cc: stable@vger.kernel.org
31 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
32 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
33 Link: https://lore.kernel.org/r/20240203235413.1146-1-ansuelsmth@gmail.com
34 Signed-off-by: Lee Jones <lee@kernel.org>
35 ---
36 drivers/leds/trigger/ledtrig-netdev.c | 4 ++--
37 1 file changed, 2 insertions(+), 2 deletions(-)
38
39 --- a/drivers/leds/trigger/ledtrig-netdev.c
40 +++ b/drivers/leds/trigger/ledtrig-netdev.c
41 @@ -489,12 +489,12 @@ static int netdev_trig_notify(struct not
42 trigger_data->duplex = DUPLEX_UNKNOWN;
43 switch (evt) {
44 case NETDEV_CHANGENAME:
45 - get_device_state(trigger_data);
46 - fallthrough;
47 case NETDEV_REGISTER:
48 dev_put(trigger_data->net_dev);
49 dev_hold(dev);
50 trigger_data->net_dev = dev;
51 + if (evt == NETDEV_CHANGENAME)
52 + get_device_state(trigger_data);
53 break;
54 case NETDEV_UNREGISTER:
55 dev_put(trigger_data->net_dev);