Skip to content

Commit a1cffe8

Browse files
committed
Merge tag 'dma-mapping-6.14-2025-03-21' of git://git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux
Pull dma-mapping fix from Marek Szyprowski: - fix missing clear bdr in check_ram_in_range_map() (Baochen Qiang) * tag 'dma-mapping-6.14-2025-03-21' of git://git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux: dma-mapping: fix missing clear bdr in check_ram_in_range_map()
2 parents b5329d5 + 8324993 commit a1cffe8

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

kernel/dma/direct.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,22 @@ int dma_direct_supported(struct device *dev, u64 mask)
584584
return mask >= phys_to_dma_unencrypted(dev, min_mask);
585585
}
586586

587+
static const struct bus_dma_region *dma_find_range(struct device *dev,
588+
unsigned long start_pfn)
589+
{
590+
const struct bus_dma_region *m;
591+
592+
for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) {
593+
unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start);
594+
595+
if (start_pfn >= cpu_start_pfn &&
596+
start_pfn - cpu_start_pfn < PFN_DOWN(m->size))
597+
return m;
598+
}
599+
600+
return NULL;
601+
}
602+
587603
/*
588604
* To check whether all ram resource ranges are covered by dma range map
589605
* Returns 0 when further check is needed
@@ -593,20 +609,12 @@ static int check_ram_in_range_map(unsigned long start_pfn,
593609
unsigned long nr_pages, void *data)
594610
{
595611
unsigned long end_pfn = start_pfn + nr_pages;
596-
const struct bus_dma_region *bdr = NULL;
597-
const struct bus_dma_region *m;
598612
struct device *dev = data;
599613

600614
while (start_pfn < end_pfn) {
601-
for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) {
602-
unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start);
615+
const struct bus_dma_region *bdr;
603616

604-
if (start_pfn >= cpu_start_pfn &&
605-
start_pfn - cpu_start_pfn < PFN_DOWN(m->size)) {
606-
bdr = m;
607-
break;
608-
}
609-
}
617+
bdr = dma_find_range(dev, start_pfn);
610618
if (!bdr)
611619
return 1;
612620

0 commit comments

Comments
 (0)