Skip to contentSkip to conversation

leds: rgb: leds-ktd202x: Fix error code in ktd202x_setup_led_rgb()

PATCH In review Dan Carpenter 2 participants 4 messages Dec 9, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: rgb: leds-ktd202x: Fix error code in ktd202x_setup_led_rgb()

Return -EINVAL if the "reg" value is invalid. This is unlikely to happen in real life because it comes from the firmware, whether from device tree or ACPI.

Fixes f14aa5ea415b ("leds: rgb: leds-ktd202x: Get device properties through fwnode to support ACPI")
---
 drivers/leds/rgb/leds-ktd202x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/rgb/leds-ktd202x.c +1 -1
index e4f0f25a5e45..3b7f2272036c 100644
@@ -410,7 +410,7 @@ static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *fwn
 		if (ret != 0 || reg >= chip->num_leds) {
 			dev_err(chip->dev, "invalid 'reg' of %pfw\n", child);
 			fwnode_handle_put(child);
-			return ret;
+			return ret ?: -EINVAL;
 		}
 
 		ret = fwnode_property_read_u32(child, "color", &mono_color);
Signature · 1 line
2.51.0
#1 lore raw
Quoted 4 lines · Dan Carpenter

Return -EINVAL if the "reg" value is invalid. This is unlikely to happen in real life because it comes from the firmware, whether from device tree or ACPI.

...

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *fwn · line 414

Quoted 6 lines
                if (ret != 0 || reg >= chip->num_leds) {
                        dev_err(chip->dev, "invalid 'reg' of %pfw\n", child);
                        fwnode_handle_put(child);
drivers/leds/rgb/leds-ktd202x.c +1 -1
-                       return ret;
+                       return ret ?: -EINVAL;
                }

I think the better fix is to split the original conditional to two.

And make the message something like
"can't retrieve 'reg' property of %pfw\n'
for the case if (ret).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Dan Carpenter

Return -EINVAL if the "reg" value is invalid. This is unlikely to happen in real life because it comes from the firmware, whether from device tree or ACPI.

...

drivers/leds/rgb/leds-ktd202x.c static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct fwnode_handle *fwn · line 414

Quoted 6 lines
                if (ret != 0 || reg >= chip->num_leds) {
                        dev_err(chip->dev, "invalid 'reg' of %pfw\n", child);
                        fwnode_handle_put(child);
drivers/leds/rgb/leds-ktd202x.c +1 -1
-                       return ret;
+                       return ret ?: -EINVAL;
                }
Quoted 6 lines

I think the better fix is to split the original conditional to two.

And make the message something like
"can't retrieve 'reg' property of %pfw\n'
for the case if (ret).

These are never going to show up for users, the messages are only for developers bringing up a board...

regards,
dan carpenter

#3 lore raw
Quoted 2 lines · Dan Carpenter
Quoted 1 line · Andy Shevchenko

On Tue, Dec 9, 2025 at 8:56 AM Dan Carpenter <[email protected]> wrote:

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
                if (ret != 0 || reg >= chip->num_leds) {
                        dev_err(chip->dev, "invalid 'reg' of %pfw\n", child);
                        fwnode_handle_put(child);
drivers/leds/rgb/leds-ktd202x.c +1 -1
-                       return ret;
+                       return ret ?: -EINVAL;
                }
Quoted 8 lines
Quoted 5 lines

I think the better fix is to split the original conditional to two.

And make the message something like
"can't retrieve 'reg' property of %pfw\n'
for the case if (ret).

These are never going to show up for users, the messages are only for developers bringing up a board...

Even better,

  if (ret) {
    fwnode_handle_put(...);
    return ret;
  }

  if (reg >= ...) {
    ...
  }

Since it's a fix likely for a backporting, the separate change can move to the _scoped() for_each loop and drop those fwnode_handle_put() calls.

Signature · 2 lines
With Best Regards,
Andy Shevchenko