Re: [PATCH] mm/memblock: add missing include <linux/bootmem.h> and #ifdef
From: Mathieu Malaterre
Date: Mon Jun 25 2018 - 10:26:43 EST
On Mon, Jun 25, 2018 at 4:03 PM Michal Hocko <mhocko@xxxxxxxxxx> wrote:
>
> On Fri 22-06-18 23:05:41, Mathieu Malaterre wrote:
> > Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis")
> > introduced two new function definitions:
> >
> > memblock_virt_alloc_try_nid_nopanic()
> > memblock_virt_alloc_try_nid()
> >
> > Commit ea1f5f3712af ("mm: define memblock_virt_alloc_try_nid_raw")
> > introduced the following function definition:
> >
> > memblock_virt_alloc_try_nid_raw()
> >
> > This commit adds an include of header file <linux/bootmem.h> to provide
> > the missing function prototypes. Silence the following gcc warning
> > (W=1):
> >
> > mm/memblock.c:1334:15: warning: no previous prototype for `memblock_virt_alloc_try_nid_raw' [-Wmissing-prototypes]
> > mm/memblock.c:1371:15: warning: no previous prototype for `memblock_virt_alloc_try_nid_nopanic' [-Wmissing-prototypes]
> > mm/memblock.c:1407:15: warning: no previous prototype for `memblock_virt_alloc_try_nid' [-Wmissing-prototypes]
> >
> > As seen in commit 6cc22dc08a24 ("revert "mm/memblock: add missing include
> > <linux/bootmem.h>"") #ifdef blockers were missing which lead to compilation
> > failure on mips/ia64 where CONFIG_NO_BOOTMEM=n.
> >
> > Suggested-by: Tony Luck <tony.luck@xxxxxxxxx>
> > Signed-off-by: Mathieu Malaterre <malat@xxxxxxxxxx>
>
> I was not aware of -Wmissing-prototypes
(not tested) sparse would report something like:
symbol 'memblock_virt_alloc_try_nid_raw' was not declared. Should it be static?
> > ---
> > mm/memblock.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/memblock.c b/mm/memblock.c
> > index 4c98672bc3e2..f4b6766d7907 100644
> > --- a/mm/memblock.c
> > +++ b/mm/memblock.c
> > @@ -20,6 +20,7 @@
> > #include <linux/kmemleak.h>
> > #include <linux/seq_file.h>
> > #include <linux/memblock.h>
> > +#include <linux/bootmem.h>
> >
> > #include <asm/sections.h>
> > #include <linux/io.h>
> > @@ -1226,6 +1227,7 @@ phys_addr_t __init memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, i
> > return memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
> > }
> >
> > +#if defined(CONFIG_HAVE_MEMBLOCK) && defined(CONFIG_NO_BOOTMEM)
>
> Why do you need CONFIG_HAVE_MEMBLOCK dependency?
> mm/Makefile says
> obj-$(CONFIG_HAVE_MEMBLOCK) += memblock.o
>
> so we even do not compile this code for !HAVE_MEMBLOCK AFAICS.
Right, that can be simplified. I took it directly from Tony. I
originally found it more readable since it matched sentinels used for
the prototypes in <linux/bootmem.h>
$ grep -B 7 memblock_virt_alloc_try_nid_raw include/linux/bootmem.h | head -1
#if defined(CONFIG_HAVE_MEMBLOCK) && defined(CONFIG_NO_BOOTMEM)
I'll send a v2 shortly.
> > /**
> > * memblock_virt_alloc_internal - allocate boot memory block
> > * @size: size of memory block to be allocated in bytes
> > @@ -1433,6 +1435,7 @@ void * __init memblock_virt_alloc_try_nid(
> > (u64)max_addr);
> > return NULL;
> > }
> > +#endif
> >
> > /**
> > * __memblock_free_early - free boot memory block
> > --
> > 2.11.0
>
> --
> Michal Hocko
> SUSE Labs