[PATCH 212/212] dma: make dma_mapping_error NULL-device safe
Johannes Schneider <[email protected]> Fri, 19 Jun 2026 16:09:18 +0000
| Newsgroups | org.infradead.lists.barebox |
|---|---|
| Message-ID | <[email protected]> |
PBL callers often pass NULL as dev; NULL deref of dev->dma_mask reads i.MX8M boot ROM and returns junk byte causing false 'mapping error'. Treat NULL dev as 'no constraint'. Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Johannes Schneider <[email protected]> --- include/dma.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/dma.h b/include/dma.h index b8016c2e89..60937a69aa 100644 --- a/include/dma.h +++ b/include/dma.h @@ -69,8 +69,11 @@ static inline void dma_set_mask(struct device *dev, u64 dma_mask) static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) { - return dma_addr == DMA_ERROR_CODE || - (dev->dma_mask && dma_addr > dev->dma_mask); + if (dma_addr == DMA_ERROR_CODE) + return 1; + if (!dev) + return 0; + return dev->dma_mask && dma_addr > dev->dma_mask; } static inline dma_addr_t cpu_to_dma(struct device *dev, void *cpu_addr) -- 2.43.0