821-v6.4-net-phy-Fix-reading-LED-reg-property.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From aed8fdad2152d946add50bec00a6b07c457bdcdf Mon Sep 17 00:00:00 2001
  2. From: Alexander Stein <[email protected]>
  3. Date: Mon, 24 Apr 2023 16:16:48 +0200
  4. Subject: [PATCH] net: phy: Fix reading LED reg property
  5. 'reg' is always encoded in 32 bits, thus it has to be read using the
  6. function with the corresponding bit width.
  7. Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
  8. Signed-off-by: Alexander Stein <[email protected]>
  9. Reviewed-by: Andrew Lunn <[email protected]>
  10. Reviewed-by: Florian Fainelli <[email protected]>
  11. Link: https://lore.kernel.org/r/[email protected]
  12. Signed-off-by: Jakub Kicinski <[email protected]>
  13. ---
  14. drivers/net/phy/phy_device.c | 6 +++++-
  15. 1 file changed, 5 insertions(+), 1 deletion(-)
  16. --- a/drivers/net/phy/phy_device.c
  17. +++ b/drivers/net/phy/phy_device.c
  18. @@ -2974,6 +2974,7 @@ static int of_phy_led(struct phy_device
  19. struct led_init_data init_data = {};
  20. struct led_classdev *cdev;
  21. struct phy_led *phyled;
  22. + u32 index;
  23. int err;
  24. phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL);
  25. @@ -2983,10 +2984,13 @@ static int of_phy_led(struct phy_device
  26. cdev = &phyled->led_cdev;
  27. phyled->phydev = phydev;
  28. - err = of_property_read_u8(led, "reg", &phyled->index);
  29. + err = of_property_read_u32(led, "reg", &index);
  30. if (err)
  31. return err;
  32. + if (index > U8_MAX)
  33. + return -EINVAL;
  34. + phyled->index = index;
  35. if (phydev->drv->led_brightness_set)
  36. cdev->brightness_set_blocking = phy_led_set_brightness;
  37. if (phydev->drv->led_blink_set)