mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 804-v6.5-09-leds-trigger-netdev-validate-configured-netdev.patch
1 From 33ec0b53befff2c0a7f3aa19ff08556d60585d6b Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Mon, 29 May 2023 18:32:39 +0200
4 Subject: [PATCH 09/13] leds: trigger: netdev: validate configured netdev
5
6 The netdev which the LED should blink for is configurable in
7 /sys/class/led/foo/device_name. Ensure when offloading that the
8 configured netdev is the same as the netdev the LED is associated
9 with. If it is not, only perform software blinking.
10
11 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
12 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/leds/trigger/ledtrig-netdev.c | 24 ++++++++++++++++++++++--
16 1 file changed, 22 insertions(+), 2 deletions(-)
17
18 --- a/drivers/leds/trigger/ledtrig-netdev.c
19 +++ b/drivers/leds/trigger/ledtrig-netdev.c
20 @@ -110,6 +110,24 @@ static bool supports_hw_control(struct l
21 return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name);
22 }
23
24 +/*
25 + * Validate the configured netdev is the same as the one associated with
26 + * the LED driver in hw control.
27 + */
28 +static bool validate_net_dev(struct led_classdev *led_cdev,
29 + struct net_device *net_dev)
30 +{
31 + struct device *dev = led_cdev->hw_control_get_device(led_cdev);
32 + struct net_device *ndev;
33 +
34 + if (!dev)
35 + return false;
36 +
37 + ndev = to_net_dev(dev);
38 +
39 + return ndev == net_dev;
40 +}
41 +
42 static bool can_hw_control(struct led_netdev_data *trigger_data)
43 {
44 unsigned long default_interval = msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL);
45 @@ -131,9 +149,11 @@ static bool can_hw_control(struct led_ne
46 /*
47 * net_dev must be set with hw control, otherwise no
48 * blinking can be happening and there is nothing to
49 - * offloaded.
50 + * offloaded. Additionally, for hw control to be
51 + * valid, the configured netdev must be the same as
52 + * netdev associated to the LED.
53 */
54 - if (!trigger_data->net_dev)
55 + if (!validate_net_dev(led_cdev, trigger_data->net_dev))
56 return false;
57
58 /* Check if the requested mode is supported */