[PATCH 5/6] driver core: cpu: Fix OF node reference leak in register_cpu() error path

From: Wentao Liang

Date: Tue Sep 15 2026 - 00:36:20 EST


register_cpu() assigns the device node returned by of_get_cpu_node(),
which comes with a reference, to cpu->dev.of_node. If device_register()
fails, the error path calls put_device() and returns, but nothing ever
drops the OF node reference: cpu_device_release() is empty and the
driver core does not put dev->of_node on the failure path, so each
failed registration leaks a reference on the device node.

Release the OF node with of_node_put() on the error path. It is safe
to access cpu->dev.of_node after put_device(), since the statically
allocated struct cpu is never freed by cpu_device_release().

Fixes: f86e4718f24b ("driver/core: cpu: initialize of_node in cpu's device struture")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/base/cpu.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 875abdc9942e..bc96725c8d4c 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -431,6 +431,7 @@ int register_cpu(struct cpu *cpu, int num)
error = device_register(&cpu->dev);
if (error) {
put_device(&cpu->dev);
+ of_node_put(cpu->dev.of_node);
return error;
}

--
2.34.1