]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ARM/dma-mapping: Remove CMA code when not built with CMA
authorKees Cook <keescook@chromium.org>
Wed, 9 Mar 2022 17:37:31 +0000 (09:37 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 31 Mar 2022 18:19:25 +0000 (11:19 -0700)
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 <linux@armlinux.org.uk>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: Martin Oliveira <martin.oliveira@eideticom.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/all/6243ee60.1c69fb81.16de6.7dbf@mx.google.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/lkml/20220310070041.GA24874@lst.de
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/lkml/9059fa71-330f-f04f-b155-2850abb72a71@redhat.com
arch/arm/mm/dma-mapping.c
arch/arm/mm/mm.h
include/linux/cma.h

index 4b61541853ea1c7ea6d996bf0332d7eb4f69ba2f..82ffac621854f863f8cb4b9b4f17621ffc83eb7a 100644 (file)
@@ -381,6 +381,7 @@ out:
  */
 postcore_initcall(atomic_pool_init);
 
+#ifdef CONFIG_CMA_AREAS
 struct dma_contig_early_reserve {
        phys_addr_t base;
        unsigned long size;
@@ -435,6 +436,7 @@ void __init dma_contiguous_remap(void)
                iotable_init(&map, 1);
        }
 }
+#endif
 
 static int __dma_update_pte(pte_t *pte, unsigned long addr, void *data)
 {
index 9ff683612f2a8cfc3e59f198e2b806415878bf63..d7ffccb7fea7d6f759104b62f9ab40a8d53cdeeb 100644 (file)
@@ -88,6 +88,10 @@ extern phys_addr_t arm_lowmem_limit;
 
 void __init bootmem_init(void);
 void arm_mm_memblock_reserve(void);
+#ifdef CONFIG_CMA_AREAS
 void dma_contiguous_remap(void);
+#else
+static inline void dma_contiguous_remap(void) { }
+#endif
 
 unsigned long __clear_cr(unsigned long mask);
index bd801023504b29197f103f49030a5fd87c1bf4d7..2c2ede7f0724e4fdfd21f7a885e17bd16239a00a 100644 (file)
  */
 #ifdef CONFIG_CMA_AREAS
 #define MAX_CMA_AREAS  (1 + CONFIG_CMA_AREAS)
-
-#else
-#define MAX_CMA_AREAS  (0)
-
 #endif
 
 #define CMA_MAX_NAME 64