Re: [PATCH 2/2] drivers/base/node: merge unregister_one_node() and unregister_node() to a single function.

Christophe Leroy
2025-09-24T19:50:35Z

Le 24/09/2025 à 20:40, Donet Tom a écrit :
> unregister_one_node() and unregister_node() are small functions.
> This patch merges them into a single function named unregister_node()
> to improve code readability.

Same comment than patch 1. It is not only because they are small that
you merge them, it is primarily because unregister_node() only has one
caller.

>
> No functional changes are introduced.
>
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
> drivers/base/node.c | 37 +++++++++++++++++--------------------
> include/linux/node.h | 6 ++----
> mm/memory_hotplug.c | 4 ++--
> 3 files changed, 21 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index eab620e29c78..d460c1675c77 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -638,23 +638,6 @@ static void node_device_release(struct device *dev)
> kfree(to_node(dev));
> }
>
> -/**
> - * unregister_node - unregister a node device
> - * @node: node going away
> - *
> - * Unregisters a node device @node. All the devices on the node must be
> - * unregistered before calling this function.
> - */
> -void unregister_node(struct node *node)
> -{
> - hugetlb_unregister_node(node);
> - compaction_unregister_node(node);
> - reclaim_unregister_node(node);
> - node_remove_accesses(node);
> - node_remove_caches(node);
> - device_unregister(&node->dev);
> -}
> -
> struct node *node_devices[MAX_NUMNODES];
>
> /*
> @@ -887,12 +870,26 @@ int register_node(int nid)
> return error;
> }
>
> -void unregister_one_node(int nid)
> +/**
> + * unregister_node - unregister a node device
> + * @nid: nid of the node going away
> + *
> + * Unregisters the node device at node id @nid. All the devices on the
> + * node must be unregistered before calling this function.
> + */
> +void unregister_node(int nid)
> {
> - if (!node_devices[nid])
> + struct node *node = node_devices[nid];
> +
> + if (!node)
> return;
>
> - unregister_node(node_devices[nid]);
> + hugetlb_unregister_node(node);
> + compaction_unregister_node(node);
> + reclaim_unregister_node(node);
> + node_remove_accesses(node);
> + node_remove_caches(node);
> + device_unregister(&node->dev);
> node_devices[nid] = NULL;
> }
>
> diff --git a/include/linux/node.h b/include/linux/node.h
> index 4dcf876cd0b4..d721127964b3 100644
> --- a/include/linux/node.h
> +++ b/include/linux/node.h
> @@ -124,8 +124,6 @@ static inline void register_memory_blocks_under_nodes(void)
> }
> #endif
>
> -extern void unregister_node(struct node *node);
> -
> struct node_notify {
> int nid;
> };
> @@ -169,7 +167,7 @@ static inline int hotplug_node_notifier(notifier_fn_t fn, int pri)
> extern void node_dev_init(void);
> /* Core of the node registration - only memory hotplug should use this */
> extern int register_node(int nid);
> -extern void unregister_one_node(int nid);
> +extern void unregister_node(int nid);

No 'extern' on function prototypes.

> extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
> extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
> extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
> @@ -185,7 +183,7 @@ static inline int register_node(int nid)
> {
> return 0;
> }
> -static inline int unregister_one_node(int nid)
> +static inline int unregister_node(int nid)
> {
> return 0;
> }
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 6c050d867031..94a8f6e8811a 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1596,7 +1596,7 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
> error:
> if (new_node) {
> node_set_offline(nid);
> - unregister_one_node(nid);
> + unregister_node(nid);
> }
> error_memblock_remove:
> if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
> @@ -2201,7 +2201,7 @@ void try_offline_node(int nid)
> * node now.
> */
> node_set_offline(nid);
> - unregister_one_node(nid);
> + unregister_node(nid);
> }
> EXPORT_SYMBOL(try_offline_node);
>