Skip to content
Snippets Groups Projects
  • Levi Yun's avatar
    mm/cma: fix potential memory loss on cma_declare_contiguous_nid · 148aa87e
    Levi Yun authored
    Suppose memblock_alloc_range_nid() with highmem_start succeeds when
    cma_declare_contiguous_nid is called with !fixed on a 32-bit system with
    PHYS_ADDR_T_64BIT enabled with memblock.bottom_up == false.
    
    But the next trial to memblock_alloc_range_nid() to allocate in [SIZE_4G,
    limits) nullifies former successfully allocated addr and it retries
    memblock_alloc_ragne_nid().
    
    In this situation, the first successfully allocated address area is lost.
    
    Change the order of allocation (SIZE_4G, high_memory and base) and check
    whether the allocated succeeded to prevent potential memory loss.
    
    Link: https://lkml.kernel.org/r/20230118080523.44522-1-ppbuk5246@gmail.com
    
    
    Signed-off-by: default avatarLevi Yun <ppbuk5246@gmail.com>
    Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Cc: Marek Szyprowski <m.szyprowski@samsung.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    148aa87e