Re: [PATCH V9 1/8] dax: move dax_pgoff_to_phys from [drivers/dax/] device.c to bus.c
From: Jonathan Cameron
Date: Tue Mar 24 2026 - 10:20:16 EST
On Tue, 24 Mar 2026 00:37:53 +0000
John Groves <john@xxxxxxxxxxxxxx> wrote:
> From: John Groves <john@xxxxxxxxxx>
>
> This function will be used by both device.c and fsdev.c, but both are
> loadable modules. Moving to bus.c puts it in core and makes it available
> to both.
>
> No code changes - just relocated.
>
> Reviewed-by: Ira Weiny <ira.weiny@xxxxxxxxx>
> Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Signed-off-by: John Groves <john@xxxxxxxxxx>
Obviously this is a straight forward code move... But I can't resist
commenting on what is moving (feel free to ignore! or maybe a follow
up patch if you agree.
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxx>
> ---
> drivers/dax/bus.c | 24 ++++++++++++++++++++++++
> drivers/dax/device.c | 23 -----------------------
> 2 files changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
> index c94c09622516..e4bd5c9f006c 100644
> --- a/drivers/dax/bus.c
> +++ b/drivers/dax/bus.c
> @@ -1417,6 +1417,30 @@ static const struct device_type dev_dax_type = {
> .groups = dax_attribute_groups,
> };
>
> +/* see "strong" declaration in tools/testing/nvdimm/dax-dev.c */
> +__weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff,
> + unsigned long size)
> +{
> + int i;
> +
> + for (i = 0; i < dev_dax->nr_range; i++) {
Modernize as:
for (int i = 0; ...
> + struct dev_dax_range *dax_range = &dev_dax->ranges[i];
> + struct range *range = &dax_range->range;
> + unsigned long long pgoff_end;
> + phys_addr_t phys;
> +
> + pgoff_end = dax_range->pgoff + PHYS_PFN(range_len(range)) - 1;
> + if (pgoff < dax_range->pgoff || pgoff > pgoff_end)
We have in_range() (linux/minmax.h) available for these case of a start to start + length - 1
check. I think this is same:
if (!in_range(pgoff, dax_range->pgoff, PHYS_PFN(range_len(range)))
> + continue;
> + phys = PFN_PHYS(pgoff - dax_range->pgoff) + range->start;
> + if (phys + size - 1 <= range->end)
> + return phys;
> + break;
> + }
> + return -1;
> +}
> +EXPORT_SYMBOL_GPL(dax_pgoff_to_phys);
> +