Skip to content

Commit

Permalink
leds: call of_node_put() when breaking out of for_each_available_chil…
Browse files Browse the repository at this point in the history
…d_of_node()

Since for_each_available_child_of_node() will increase the refcount of
node, we need to call of_node_put() manually when breaking out of the
iteration.

Fixes: 24e2d05 ("leds: Add driver for Qualcomm LPG")
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
  • Loading branch information
ZhangPeng authored and intel-lab-lkp committed Nov 22, 2022
1 parent eb70814 commit 013aed0
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions drivers/leds/rgb/leds-qcom-lpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
ret = of_property_read_u32(np, "color", &color);
if (ret < 0 && ret != -EINVAL) {
dev_err(lpg->dev, "failed to parse \"color\" of %pOF\n", np);
return ret;
goto err_put_np_node;
}

if (color == LED_COLOR_ID_RGB)
Expand All @@ -1093,21 +1093,25 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
num_channels = 1;

led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL);
if (!led)
return -ENOMEM;
if (!led) {
ret = -ENOMEM
goto err_put_np_node;
}

led->lpg = lpg;
led->num_channels = num_channels;

if (color == LED_COLOR_ID_RGB) {
info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL);
if (!info)
return -ENOMEM;
if (!info) {
ret = -ENOMEM
goto err_put_np_node;
}
i = 0;
for_each_available_child_of_node(np, child) {
ret = lpg_parse_channel(lpg, child, &led->channels[i]);
if (ret < 0)
return ret;
goto err_put_child_node;

info[i].color_index = led->channels[i]->color;
info[i].intensity = 0;
Expand All @@ -1129,7 +1133,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
} else {
ret = lpg_parse_channel(lpg, np, &led->channels[0]);
if (ret < 0)
return ret;
goto err_put_np_node;

cdev = &led->cdev;
cdev->brightness_set = lpg_brightness_single_set;
Expand Down Expand Up @@ -1161,7 +1165,15 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
ret = devm_led_classdev_register_ext(lpg->dev, &led->cdev, &init_data);
if (ret)
dev_err(lpg->dev, "unable to register %s\n", cdev->name);
else
return ret;

err_put_np_node:
of_node_put(np);
return ret;

err_put_child_node:
of_node_put(child);
return ret;
}

Expand Down

0 comments on commit 013aed0

Please sign in to comment.