Skip to content

Commit 229a08a

Browse files
committed
ARM/dma-mapping: Remove CMA code when not built with CMA
The MAX_CMA_AREAS could be set to 0, which would result in code that would attempt to operate beyond the end of a zero-sized array. If CONFIG_CMA is disabled, just remove this code entirely. Found when building arm on GCC 10.x for several defconfigs (e.g. axm55xx_defconfig) under -Warray-bounds: arch/arm/mm/dma-mapping.c:396:22: warning: array subscript <unknown> is outside array bounds of 'struct dma_contig_early_reserve[0]' [-Warray-bounds] 396 | dma_mmu_remap[dma_mmu_remap_num].size = size; | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ arch/arm/mm/dma-mapping.c:389:40: note: while referencing 'dma_mmu_remap' 389 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata; | ^~~~~~~~~~~~~ Cc: Russell King <[email protected]> Cc: Logan Gunthorpe <[email protected]> Cc: Martin Oliveira <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Zi Yan <[email protected]> Cc: Hari Bathini <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/lkml/[email protected] Reviewed-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]
1 parent ef3e787 commit 229a08a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

arch/arm/mm/dma-mapping.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ static int __init atomic_pool_init(void)
381381
*/
382382
postcore_initcall(atomic_pool_init);
383383

384+
#ifdef CONFIG_CMA_AREAS
384385
struct dma_contig_early_reserve {
385386
phys_addr_t base;
386387
unsigned long size;
@@ -435,6 +436,7 @@ void __init dma_contiguous_remap(void)
435436
iotable_init(&map, 1);
436437
}
437438
}
439+
#endif
438440

439441
static int __dma_update_pte(pte_t *pte, unsigned long addr, void *data)
440442
{

arch/arm/mm/mm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ extern phys_addr_t arm_lowmem_limit;
8888

8989
void __init bootmem_init(void);
9090
void arm_mm_memblock_reserve(void);
91+
#ifdef CONFIG_CMA_AREAS
9192
void dma_contiguous_remap(void);
93+
#else
94+
static inline void dma_contiguous_remap(void) { }
95+
#endif
9296

9397
unsigned long __clear_cr(unsigned long mask);

include/linux/cma.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
*/
1313
#ifdef CONFIG_CMA_AREAS
1414
#define MAX_CMA_AREAS (1 + CONFIG_CMA_AREAS)
15-
16-
#else
17-
#define MAX_CMA_AREAS (0)
18-
1915
#endif
2016

2117
#define CMA_MAX_NAME 64

0 commit comments

Comments
 (0)