Message ID | 20210810200632.3812797-1-nathan@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm/hugetlb: Initialize page to NULL in alloc_buddy_huge_page_with_mpol() | expand |
On Tue, Aug 10, 2021 at 01:06:32PM -0700, Nathan Chancellor wrote: > Clang warns: > > mm/hugetlb.c:2162:6: warning: variable 'page' is used uninitialized > whenever 'if' condition is false [-Wsometimes-uninitialized] > if (mpol_is_preferred_many(mpol)) { > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > mm/hugetlb.c:2172:7: note: uninitialized use occurs here > if (!page) > ^~~~ > mm/hugetlb.c:2162:2: note: remove the 'if' if its condition is always > true > if (mpol_is_preferred_many(mpol)) { > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > mm/hugetlb.c:2155:19: note: initialize the variable 'page' to silence > this warning > struct page *page; > ^ > = NULL > 1 warning generated. > > Initialize page to NULL like in dequeue_huge_page_vma() so that page is > not used uninitialized. > > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Thanks for the catch! In my original patch, I initialized it in one function, but overlooked this one. Thanks, Feng
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3d9cd2722ea5..604e2d6bd506 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2152,7 +2152,7 @@ static struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h, struct vm_area_struct *vma, unsigned long addr) { - struct page *page; + struct page *page = NULL; struct mempolicy *mpol; gfp_t gfp_mask = htlb_alloc_mask(h); int nid;
Clang warns: mm/hugetlb.c:2162:6: warning: variable 'page' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (mpol_is_preferred_many(mpol)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/hugetlb.c:2172:7: note: uninitialized use occurs here if (!page) ^~~~ mm/hugetlb.c:2162:2: note: remove the 'if' if its condition is always true if (mpol_is_preferred_many(mpol)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/hugetlb.c:2155:19: note: initialize the variable 'page' to silence this warning struct page *page; ^ = NULL 1 warning generated. Initialize page to NULL like in dequeue_huge_page_vma() so that page is not used uninitialized. Signed-off-by: Nathan Chancellor <nathan@kernel.org> --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 18f73b217b4633e27a61832e1485ce927a8ee5c1