Commit 8f38f8fa authored by Lu Hongfei's avatar Lu Hongfei Committed by Lee Jones
Browse files

led: qcom-lpg: Fix resource leaks in for_each_available_child_of_node() loops



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

Signed-off-by: default avatarLu Hongfei <luhongfei@vivo.com>
Link: https://lore.kernel.org/r/20230525111705.3055-1-luhongfei@vivo.com


Signed-off-by: default avatarLee Jones <lee@kernel.org>
parent 28598e21
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1173,8 +1173,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;
@@ -1352,9 +1354,11 @@ 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++)
		lpg_apply_dtest(&lpg->channels[i]);