kernel: backport phylink changes from mainline Linux
[openwrt/staging/jow.git] / target / linux / generic / backport-6.1 / 821-v6.4-net-phy-Fix-reading-LED-reg-property.patch
1 From aed8fdad2152d946add50bec00a6b07c457bdcdf Mon Sep 17 00:00:00 2001
2 From: Alexander Stein <alexander.stein@ew.tq-group.com>
3 Date: Mon, 24 Apr 2023 16:16:48 +0200
4 Subject: [PATCH] net: phy: Fix reading LED reg property
5
6 'reg' is always encoded in 32 bits, thus it has to be read using the
7 function with the corresponding bit width.
8
9 Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
10 Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
13 Link: https://lore.kernel.org/r/20230424141648.317944-1-alexander.stein@ew.tq-group.com
14 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
15 ---
16 drivers/net/phy/phy_device.c | 6 +++++-
17 1 file changed, 5 insertions(+), 1 deletion(-)
18
19 --- a/drivers/net/phy/phy_device.c
20 +++ b/drivers/net/phy/phy_device.c
21 @@ -3075,6 +3075,7 @@ static int of_phy_led(struct phy_device
22 struct led_init_data init_data = {};
23 struct led_classdev *cdev;
24 struct phy_led *phyled;
25 + u32 index;
26 int err;
27
28 phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL);
29 @@ -3084,10 +3085,13 @@ static int of_phy_led(struct phy_device
30 cdev = &phyled->led_cdev;
31 phyled->phydev = phydev;
32
33 - err = of_property_read_u8(led, "reg", &phyled->index);
34 + err = of_property_read_u32(led, "reg", &index);
35 if (err)
36 return err;
37 + if (index > U8_MAX)
38 + return -EINVAL;
39
40 + phyled->index = index;
41 if (phydev->drv->led_brightness_set)
42 cdev->brightness_set_blocking = phy_led_set_brightness;
43 if (phydev->drv->led_blink_set)