Re: [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA

From: David Hildenbrand
Date: Thu Mar 10 2022 - 03:23:54 EST


On 09.03.22 18:51, Kees Cook wrote:
> 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 with
> -Warray-bounds:
>
> arch/arm/mm/dma-mapping.c:396:22: warning: array subscript <unknown> is outside array bounds of 'str
> uct 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 <linux@xxxxxxxxxxxxxxx>
> Cc: Logan Gunthorpe <logang@xxxxxxxxxxxx>
> Cc: Martin Oliveira <martin.oliveira@xxxxxxxxxxxxx>
> Cc: David Hildenbrand <david@xxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
> Cc: Zi Yan <ziy@xxxxxxxxxx>
> Cc: Hari Bathini <hbathini@xxxxxxxxxxxxx>
> Cc: Minchan Kim <minchan@xxxxxxxxxx>
> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx>
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>

Reviewed-by: David Hildenbrand <david@xxxxxxxxxx>


--
Thanks,

David / dhildenb