Skip to contentSkip to conversation

devfreq: exynos-ppmu: Fix refcount leak in of_get_devfreq_events

PATCH Applied Miaoqian Lin 2 participants 3 messages May 26, 2022 – Jun 18, 2022

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

PATCH 1/1 devfreq: exynos-ppmu: Fix refcount leak in of_get_devfreq_events

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. This function only calls of_node_put() in normal path, missing it in error paths.
Add missing of_node_put() to avoid refcount leak.

Fixes f262f28c1470 ("PM / devfreq: event: Add devfreq_event class")
---
 drivers/devfreq/event/exynos-ppmu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/devfreq/event/exynos-ppmu.c +6 -2
index 9b849d781116..a443e7c42daf 100644
@@ -519,15 +519,19 @@ static int of_get_devfreq_events(struct device_node *np,
 
 	count = of_get_child_count(events_np);
 	desc = devm_kcalloc(dev, count, sizeof(*desc), GFP_KERNEL);
-	if (!desc)
+	if (!desc) {
+		of_node_put(events_np);
 		return -ENOMEM;
+	}
 	info->num_events = count;
 
 	of_id = of_match_device(exynos_ppmu_id_match, dev);
 	if (of_id)
 		info->ppmu_type = (enum exynos_ppmu_type)of_id->data;
-	else
+	else {
+		of_node_put(events_np);
 		return -EINVAL;
+	}
 
 	j = 0;
 	for_each_child_of_node(events_np, node) {
Signature · 1 line
2.25.1
Applied
#1 lore raw
Quoted 28 lines · Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. This function only calls of_node_put() in normal path, missing it in error paths.
Add missing of_node_put() to avoid refcount leak.

Fixes f262f28c1470 ("PM / devfreq: event: Add devfreq_event class")
---
 drivers/devfreq/event/exynos-ppmu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/devfreq/event/exynos-ppmu.c +3 -1
index 9b849d781116..a443e7c42daf 100644
@@ -519,15 +519,19 @@ static int of_get_devfreq_events(struct device_node *np,
 
 	count = of_get_child_count(events_np);
 	desc = devm_kcalloc(dev, count, sizeof(*desc), GFP_KERNEL);
-	if (!desc)
+	if (!desc) {
+		of_node_put(events_np);
 		return -ENOMEM;
+	}
 	info->num_events = count;
 
 	of_id = of_match_device(exynos_ppmu_id_match, dev);

drivers/devfreq/event/exynos-ppmu.c static int of_get_devfreq_events(struct device_node *np, · line 537

Quoted 10 lines
drivers/devfreq/event/exynos-ppmu.c +3 -1
 	if (of_id)
 		info->ppmu_type = (enum exynos_ppmu_type)of_id->data;
-	else
+	else {
+		of_node_put(events_np);
 		return -EINVAL;
+	}
 
 	j = 0;
 	for_each_child_of_node(events_np, node) {

Applied it. Thanks.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#2 lore raw
In reply to Miaoqian Lin
Quoted 28 lines · Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. This function only calls of_node_put() in normal path, missing it in error paths.
Add missing of_node_put() to avoid refcount leak.

Fixes f262f28c1470 ("PM / devfreq: event: Add devfreq_event class")
---
 drivers/devfreq/event/exynos-ppmu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/devfreq/event/exynos-ppmu.c +3 -1
index 9b849d781116..a443e7c42daf 100644
@@ -519,15 +519,19 @@ static int of_get_devfreq_events(struct device_node *np,
 
 	count = of_get_child_count(events_np);
 	desc = devm_kcalloc(dev, count, sizeof(*desc), GFP_KERNEL);
-	if (!desc)
+	if (!desc) {
+		of_node_put(events_np);
 		return -ENOMEM;
+	}
 	info->num_events = count;
 
 	of_id = of_match_device(exynos_ppmu_id_match, dev);

drivers/devfreq/event/exynos-ppmu.c static int of_get_devfreq_events(struct device_node *np, · line 537

Quoted 10 lines
drivers/devfreq/event/exynos-ppmu.c +3 -1
 	if (of_id)
 		info->ppmu_type = (enum exynos_ppmu_type)of_id->data;
-	else
+	else {
+		of_node_put(events_np);
 		return -EINVAL;
+	}
 
 	j = 0;
 	for_each_child_of_node(events_np, node) {

I edited the patch title with 'PM / ' prefix
in order to keep the consistent style of title as following:

PM / devfreq: exynos-ppmu: Fix refcount leak in of_get_devfreq_events

Signature · 8 lines
Best Regards,
Samsung Electronics
Chanwoo Choi

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel