On 6/3/25 3:19 PM, Smita Koralahalli wrote:
> From: Nathan Fontenot <[email protected]>
>
> To enable registration of HMEM devices for SOFT RESERVED regions after
> the DAX HMEM device is initialized, this patch saves a reference to the
> DAX HMEM platform device.
>
> This saved pointer will be used in a follow-up patch to allow late
> registration of SOFT RESERVED memory ranges. It also enables
> simplification of the walk_hmem_resources() by removing the need to
> pass a struct device argument.
>
> There are no functional changes.
>
> Co-developed-by: Nathan Fontenot <[email protected]>
> Signed-off-by: Nathan Fontenot <[email protected]>
> Co-developed-by: Terry Bowman <[email protected]>
> Signed-off-by: Terry Bowman <[email protected]>
> Signed-off-by: Smita Koralahalli <[email protected]>
> ---
> drivers/dax/hmem/device.c | 4 ++--
> drivers/dax/hmem/hmem.c | 9 ++++++---
> include/linux/dax.h | 5 ++---
> 3 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c
> index f9e1a76a04a9..59ad44761191 100644
> --- a/drivers/dax/hmem/device.c
> +++ b/drivers/dax/hmem/device.c
> @@ -17,14 +17,14 @@ static struct resource hmem_active = {
> .flags = IORESOURCE_MEM,
> };
>
> -int walk_hmem_resources(struct device *host, walk_hmem_fn fn)
> +int walk_hmem_resources(walk_hmem_fn fn)
> {
> struct resource *res;
> int rc = 0;
>
> mutex_lock(&hmem_resource_lock);
> for (res = hmem_active.child; res; res = res->sibling) {
> - rc = fn(host, (int) res->desc, res);
> + rc = fn((int) res->desc, res);
> if (rc)
> break;
> }
> diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c
> index 5e7c53f18491..3aedef5f1be1 100644
> --- a/drivers/dax/hmem/hmem.c
> +++ b/drivers/dax/hmem/hmem.c
> @@ -9,6 +9,8 @@
> static bool region_idle;
> module_param_named(region_idle, region_idle, bool, 0644);
>
> +static struct platform_device *dax_hmem_pdev;
> +
> static int dax_hmem_probe(struct platform_device *pdev)
> {
> unsigned long flags = IORESOURCE_DAX_KMEM;
> @@ -59,9 +61,9 @@ static void release_hmem(void *pdev)
> platform_device_unregister(pdev);
> }
>
> -static int hmem_register_device(struct device *host, int target_nid,
> - const struct resource *res)
> +static int hmem_register_device(int target_nid, const struct resource *res)
> {
> + struct device *host = &dax_hmem_pdev->dev;
> struct platform_device *pdev;
> struct memregion_info info;
> long id;
> @@ -125,7 +127,8 @@ static int hmem_register_device(struct device *host, int
> target_nid,
>
> static int dax_hmem_platform_probe(struct platform_device *pdev)
> {
> - return walk_hmem_resources(&pdev->dev, hmem_register_device);
> + dax_hmem_pdev = pdev;
Is there never more than 1 DAX HMEM platform device that can show up? The
global pointer makes me nervous.
DJ
> + return walk_hmem_resources(hmem_register_device);
> }
>
> static struct platform_driver dax_hmem_platform_driver = {
> diff --git a/include/linux/dax.h b/include/linux/dax.h
> index dcc9fcdf14e4..a4ad3708ea35 100644
> --- a/include/linux/dax.h
> +++ b/include/linux/dax.h
> @@ -305,7 +305,6 @@ static inline void hmem_register_resource(int target_nid,
> struct resource *r)
> }
> #endif
>
> -typedef int (*walk_hmem_fn)(struct device *dev, int target_nid,
> - const struct resource *res);
> -int walk_hmem_resources(struct device *dev, walk_hmem_fn fn);
> +typedef int (*walk_hmem_fn)(int target_nid, const struct resource *res);
> +int walk_hmem_resources(walk_hmem_fn fn);
> #endif