Skip to content

Commit 81122fb

Browse files
Weigang Herobherring
authored andcommitted
of: fix reference count leak in of_alias_scan()
of_find_node_by_path() returns a device_node with its refcount incremented. When kstrtoint() fails or dt_alloc() fails, the function continues to the next iteration without calling of_node_put(), causing a reference count leak. Add of_node_put(np) before continue on both error paths to properly release the device_node reference. Fixes: 611cad7 ("dt: add of_alias_scan and of_alias_get_id") Cc: stable@vger.kernel.org Signed-off-by: Weigang He <geoffreyhe2@gmail.com> Link: https://patch.msgid.link/20260117091238.481243-1-geoffreyhe2@gmail.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 48e6a9c commit 81122fb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/of/base.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,17 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
19421942
end--;
19431943
len = end - start;
19441944

1945-
if (kstrtoint(end, 10, &id) < 0)
1945+
if (kstrtoint(end, 10, &id) < 0) {
1946+
of_node_put(np);
19461947
continue;
1948+
}
19471949

19481950
/* Allocate an alias_prop with enough space for the stem */
19491951
ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));
1950-
if (!ap)
1952+
if (!ap) {
1953+
of_node_put(np);
19511954
continue;
1955+
}
19521956
memset(ap, 0, sizeof(*ap) + len + 1);
19531957
ap->alias = start;
19541958
of_alias_add(ap, np, id, start, len);

0 commit comments

Comments
 (0)