Re: [PATCH 1/2] drivers/base/node: merge register_one_node() and register_node() to a single function.
From: Donet Tom <hidden>
Date: 2025-09-25 13:21:21
Also in:
linux-mm, lkml
On 9/25/25 2:24 PM, David Hildenbrand wrote:
On 24.09.25 20:40, Donet Tom wrote:quoted
register_one_node() and register_node() are small functions. This patch merges them into a single function named register_node() to improve code readability. No functional changes are introduced. Signed-off-by: Donet Tom <redacted> ---[...]quoted
/** * unregister_node - unregister a node device * @node: node going away@@ -869,7 +842,13 @@ voidregister_memory_blocks_under_node_hotplug(int nid, unsigned long start_pfn, } #endif /* CONFIG_MEMORY_HOTPLUG */ -int register_one_node(int nid) +/*We can directly convert this to proper kernel doc by using /**
Sure I will add it.
quoted
+ * register_node - Setup a sysfs device for a node. + * @nid - Node number to use when creating the device. + * + * Initialize and register the node device.and briefly describing what the return value means "Returns 0 on success, ..."
Sure
quoted
+ */ +int register_node(int nid) { int error; int cpu;@@ -880,14 +859,23 @@ int register_one_node(int nid)return -ENOMEM; INIT_LIST_HEAD(&node->access_list); - node_devices[nid] = node; - error = register_node(node_devices[nid], nid); + node->dev.id = nid; + node->dev.bus = &node_subsys; + node->dev.release = node_device_release; + node->dev.groups = node_dev_groups; + + error = device_register(&node->dev); if (error) { - node_devices[nid] = NULL;Wondering why we did have this temporary setting of the node_devices[] in there. But I cannot immediately spot why it was required.
node_devices[] is used in many places to access node data. In the previous code, immediately after allocating the node structure, it was stored in node_devices[]. On error paths, we were clearing the node structure entry from node_devices[]. With the new code, the node structure is now stored in node_devices[] only after the device has been registered, and just before calling register_cpu_under_node(), since node_devices[] is accessed inside that function. It is also used outside of node.c, in hugetlb_register_all_nodes() . Do you think we could use a different mechanism instead of this?