Re: [PATCH V9 1/8] dax: move dax_pgoff_to_phys from [drivers/dax/] device.c to bus.c
From: Ira Weiny
Date: Tue Mar 24 2026 - 19:41:12 EST
Jonathan Cameron wrote:
> 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>
Added this to the series. LMK if I missed something.
Ira
---
commit ccc1878ab00178e82108bdd1ece497388a24290b (HEAD -> nvdimm-famfs-dax)
Author: Ira Weiny <ira.weiny@xxxxxxxxx>
Date: Tue Mar 24 12:36:19 2026 -0500
dax: Modernize dax_pgoff_to_phys()
The patch to move dax_pgoff_to_phys() to bus.c revealed that the
function could be improved with more modern style and the newer
in_range() utility function.
Update it while we are moving it around.
Link: https://lore.kernel.org/all/20260324141806.000003f7@xxxxxxxxxx/
Suggested-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxx>
Signed-off-by: Ira Weiny <ira.weiny@xxxxxxxxx>
diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index e4bd5c9f006c..1b412264bb36 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -1421,16 +1421,12 @@ static const struct device_type dev_dax_type = {
__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++) {
+ for (int i = 0; i < dev_dax->nr_range; i++) {
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)
+ 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)