Re: [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation

From: Andrew Morton
Date: Wed Sep 29 2021 - 19:25:45 EST


On Wed, 29 Sep 2021 15:27:18 -0700 Mike Rapoport <rppt@xxxxxxxxxx> wrote:

> > mm/hugetlb.c:2957:33: error: variable 'm' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
> > for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > mm/hugetlb.c:1254:3: note: expanded from macro 'for_each_node_mask_to_alloc'
> > nr_nodes > 0 && \
> > ^~~~~~~~~~~~
> > mm/hugetlb.c:2974:18: note: uninitialized use occurs here
> > INIT_LIST_HEAD(&m->list);
> > ^
> > mm/hugetlb.c:2957:33: note: remove the '&&' if its condition is always true
> > for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> > ^
> > mm/hugetlb.c:2942:29: note: initialize the variable 'm' to silence this warning
> > struct huge_bootmem_page *m;
> > ^
> > = NULL
> > 1 error generated.
> >
> > I am not sure if it is possible for nr_nodes to be 0 right out of the
> > gate so might be a false positive?
>
> With nr_nodes == 0 there will be no memory in the system :)

Let's keep clang happy?

--- a/mm/hugetlb.c~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation-fix
+++ a/mm/hugetlb.c
@@ -2939,7 +2939,7 @@ int alloc_bootmem_huge_page(struct hstat
__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
int __alloc_bootmem_huge_page(struct hstate *h, int nid)
{
- struct huge_bootmem_page *m;
+ struct huge_bootmem_page *m = NULL; /* initialize for clang */
int nr_nodes, node;

if (nid >= nr_online_nodes)
_