leds: lp50xx: Put fwnode in error case during ->probe()
authorAndy Shevchenko <andy.shevchenko@gmail.com>
Mon, 10 May 2021 09:50:40 +0000 (12:50 +0300)
committerPavel Machek <pavel@ucw.cz>
Fri, 28 May 2021 10:00:15 +0000 (12:00 +0200)
fwnode_for_each_child_node() bumps a reference counting of a returned variable.
We have to balance it whenever we return to the caller.

OTOH, the successful iteration will drop reference count under the hood, no need
to do it twice.

Fixes: 242b81170fb8 ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")
Cc: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
drivers/leds/leds-lp50xx.c

index 06230614fdc56591c03f8df371682e38f223b193..401df1e2e05d08abccc05bf274dd7b54cf9ea140 100644 (file)
@@ -490,6 +490,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
                        ret = fwnode_property_read_u32(led_node, "color",
                                                       &color_id);
                        if (ret) {
+                               fwnode_handle_put(led_node);
                                dev_err(priv->dev, "Cannot read color\n");
                                goto child_out;
                        }
@@ -512,7 +513,6 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
                        goto child_out;
                }
                i++;
-               fwnode_handle_put(child);
        }
 
        return 0;