linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drivers/base/node: Handle error properly in register_one_node()
@ 2025-08-22  8:48 Donet Tom
  2025-08-22  9:48 ` David Hildenbrand
  2025-09-17 13:45 ` Chris Mason
  0 siblings, 2 replies; 6+ messages in thread
From: Donet Tom @ 2025-08-22  8:48 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton, Oscar Salvador, Zi Yan,
	Greg Kroah-Hartman
  Cc: Ritesh Harjani, linux-mm, linux-kernel, Rafael J . Wysocki,
	Danilo Krummrich, Jonathan Cameron, Alison Schofield, Yury Norov,
	Dave Jiang, KAMEZAWA Hiroyuki, Donet Tom

If register_node() returns an error, it is not handled correctly.
The function will proceed further and try to register CPUs under the
node, which is not correct.

So, in this patch, if register_node() returns an error, we return
immediately from the function.

Fixes: 76b67ed9dce6 ("[PATCH] node hotplug: register cpu: remove node struct")
Signed-off-by: Donet Tom <donettom@linux.ibm.com>
---
v1 -> v2
Made the changes based on Oscar’s review comments.

v1 - https://lore.kernel.org/all/20250702112856.295176-1-donettom@linux.ibm.com/
---
 drivers/base/node.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index c65b4917794e..1608816de67f 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -883,6 +883,11 @@ int register_one_node(int nid)
 	node_devices[nid] = node;
 
 	error = register_node(node_devices[nid], nid);
+	if (error) {
+		node_devices[nid] = NULL;
+		kfree(node);
+		return error;
+	}
 
 	/* link cpu under this node */
 	for_each_present_cpu(cpu) {
-- 
2.50.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-18  4:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-22  8:48 [PATCH v2] drivers/base/node: Handle error properly in register_one_node() Donet Tom
2025-08-22  9:48 ` David Hildenbrand
2025-09-17 13:45 ` Chris Mason
2025-09-17 14:55   ` Donet Tom
2025-09-17 21:48     ` Andrew Morton
2025-09-18  4:49       ` Donet Tom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox