Re: [PATCH] drivers/base/node: Handle error properly in register_one_node()

Oscar Salvador
2025-07-02T12:47:10Z

On Wed, Jul 02, 2025 at 06:28:56AM -0500, Donet Tom wrote:
> 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.
>
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
>
...
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index bef84f01712f..aec991b4c0b2 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -885,6 +885,8 @@ int register_one_node(int nid)
> node_devices[nid] = node;
>
> error = register_node(node_devices[nid], nid);
> + if (error)
> + return error;

Ok, all current callers (based on mm-unstable) panic or BUG() if this fails,
but powerpc, in init_phb_dynamic(), which keeps on going.
Unless it panics somewhere down the road as well.

So I think we need to:

node_devices[nid] = NULL
kfree(node)

?

Also, once Hannes fix lands, we might need that as well.

Anyway, I'd suggest you hold on until Hannes fix lands, so we can later
rebase all your mem-hotplug on top of that [1].

[1] https://lore.kernel.org/linux-mm/86f89a65-f0f6-4462-9eea-ac691de2f3b6@suse.de/T/#mbf392eb390b8053f96be50da3b40dfd9b62dd389

--
Oscar Salvador
SUSE Labs