Skip to content

Commit

Permalink
led: qcom-lpg: Fix resource leaks in for_each_available_child_of_node…
Browse files Browse the repository at this point in the history
…() loops

[ Upstream commit 8f38f8f ]

Ensure child node references are decremented properly in the error path.

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
Link: https://lore.kernel.org/r/20230525111705.3055-1-luhongfei@vivo.com
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Lu Hongfei authored and gregkh committed Aug 23, 2023
1 parent bda3f46 commit 6c9317f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/leds/rgb/leds-qcom-lpg.c
Expand Up @@ -1112,8 +1112,10 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
i = 0;
for_each_available_child_of_node(np, child) {
ret = lpg_parse_channel(lpg, child, &led->channels[i]);
if (ret < 0)
if (ret < 0) {
of_node_put(child);
return ret;
}

info[i].color_index = led->channels[i]->color;
info[i].intensity = 0;
Expand Down Expand Up @@ -1291,8 +1293,10 @@ static int lpg_probe(struct platform_device *pdev)

for_each_available_child_of_node(pdev->dev.of_node, np) {
ret = lpg_add_led(lpg, np);
if (ret)
if (ret) {
of_node_put(np);
return ret;
}
}

for (i = 0; i < lpg->num_channels; i++)
Expand Down

0 comments on commit 6c9317f

Please sign in to comment.