mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
dma-mapping: fix missing clear bdr in check_ram_in_range_map()
[ Upstream commit8324993f60] As discussed in [1], if 'bdr' is set once, it would never get cleared, hence 0 is always returned. Refactor the range check hunk into a new helper dma_find_range(), which allows 'bdr' to be cleared in each iteration. Link: https://lore.kernel.org/all/64931fac-085b-4ff3-9314-84bac2fa9bdb@quicinc.com/ # [1] Fixes:a409d96009("dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM") Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com> Link: https://lore.kernel.org/r/20250307030350.69144-1-quic_bqiang@quicinc.com Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
db7dd032ee
commit
ca3c033a4f
@@ -584,6 +584,22 @@ int dma_direct_supported(struct device *dev, u64 mask)
|
|||||||
return mask >= phys_to_dma_unencrypted(dev, min_mask);
|
return mask >= phys_to_dma_unencrypted(dev, min_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct bus_dma_region *dma_find_range(struct device *dev,
|
||||||
|
unsigned long start_pfn)
|
||||||
|
{
|
||||||
|
const struct bus_dma_region *m;
|
||||||
|
|
||||||
|
for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) {
|
||||||
|
unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start);
|
||||||
|
|
||||||
|
if (start_pfn >= cpu_start_pfn &&
|
||||||
|
start_pfn - cpu_start_pfn < PFN_DOWN(m->size))
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To check whether all ram resource ranges are covered by dma range map
|
* To check whether all ram resource ranges are covered by dma range map
|
||||||
* Returns 0 when further check is needed
|
* Returns 0 when further check is needed
|
||||||
@@ -593,20 +609,12 @@ static int check_ram_in_range_map(unsigned long start_pfn,
|
|||||||
unsigned long nr_pages, void *data)
|
unsigned long nr_pages, void *data)
|
||||||
{
|
{
|
||||||
unsigned long end_pfn = start_pfn + nr_pages;
|
unsigned long end_pfn = start_pfn + nr_pages;
|
||||||
const struct bus_dma_region *bdr = NULL;
|
|
||||||
const struct bus_dma_region *m;
|
|
||||||
struct device *dev = data;
|
struct device *dev = data;
|
||||||
|
|
||||||
while (start_pfn < end_pfn) {
|
while (start_pfn < end_pfn) {
|
||||||
for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) {
|
const struct bus_dma_region *bdr;
|
||||||
unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start);
|
|
||||||
|
|
||||||
if (start_pfn >= cpu_start_pfn &&
|
bdr = dma_find_range(dev, start_pfn);
|
||||||
start_pfn - cpu_start_pfn < PFN_DOWN(m->size)) {
|
|
||||||
bdr = m;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!bdr)
|
if (!bdr)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user