Re: [linux-next:master 14545/14705] mm/nommu.c:1081:28: warning: variable 'vma' is uninitialized when used here

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> [220602 09:40]:
> * kernel test robot <lkp@xxxxxxxxx> [220602 09:24]:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
> > head:   2e776ccffa840ce53ee1c21bde54cbe4bc102c3b
> > commit: 32355b99dd92f9751a482463d7e239fa06302bc9 [14545/14705] mm/nommu: move preallocations and limit other allocations
> > config: arm-buildonly-randconfig-r004-20220531 (https://download.01.org/0day-ci/archive/20220602/202206022121.RYk2Zgc9-lkp@xxxxxxxxx/config)
> > compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project b364c76683f8ef241025a9556300778c07b590c2)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install arm cross compiling tool for clang build
> >         # apt-get install binutils-arm-linux-gnueabi
> >         # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=32355b99dd92f9751a482463d7e239fa06302bc9
> >         git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> >         git fetch --no-tags linux-next master
> >         git checkout 32355b99dd92f9751a482463d7e239fa06302bc9
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash
> > 
> > If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > 
> > All warnings (new ones prefixed by >>):
> > 
> >    mm/nommu.c:593:18: error: incompatible pointer types passing 'struct ma_state **' to parameter of type 'struct ma_state *'; remove & [-Werror,-Wincompatible-pointer-types]
> >            prev = mas_prev(&mas, 0);
> >                            ^~~~
> >    include/linux/maple_tree.h:468:33: note: passing argument to parameter 'mas' here
> >    void *mas_prev(struct ma_state *mas, unsigned long min);
> >                                    ^
> >    mm/nommu.c:594:12: error: incompatible pointer types passing 'struct ma_state **' to parameter of type 'struct ma_state *'; remove & [-Werror,-Wincompatible-pointer-types]
> >            mas_reset(&mas);
> >                      ^~~~
> >    include/linux/maple_tree.h:505:47: note: passing argument to parameter 'mas' here
> >    static inline void mas_reset(struct ma_state *mas)
> >                                                  ^
> > >> mm/nommu.c:1081:28: warning: variable 'vma' is uninitialized when used here [-Wuninitialized]
> >            if (mas_preallocate(&mas, vma, GFP_KERNEL))
> 
> mas_preallocate does not currently use this variable, but in the future
> it may be that you are storing a NULL which could affect the
> preallocations as an optimization.  I will fix this by relocating it
> below the vma allocation.

Andrew,

Please find the attached patch to fix up the commit mentioned above
"32355b99dd92f: mm/nommu: move preallocations and limit other
allocations"

Thanks,
Liam


From 0ff3d1d6f0c1d0464cca008acb1a750d78af441e Mon Sep 17 00:00:00 2001
From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>
Date: Thu, 2 Jun 2022 09:44:38 -0400
Subject: [PATCH] mm/nommu: Fix compile warning in do_mmap()

vma is passed in to preallocate nodes since storing NULL could result in
less nodes needed than an actual value being stored.  Fix this by moving
the preallocation call to below the vma allocation & be sure to undo
other allocations in the failure path.

Also fix the type error in the short-lived linked list modification.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
---
 mm/nommu.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/nommu.c b/mm/nommu.c
index dbd73e3a9adf..f6b187090d95 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -590,8 +590,8 @@ static void mas_add_vma_to_mm(struct ma_state *mas, struct mm_struct *mm,
 
 	setup_vma_to_mm(vma, mm);
 
-	prev = mas_prev(&mas, 0);
-	mas_reset(&mas);
+	prev = mas_prev(mas, 0);
+	mas_reset(mas);
 	/* add the VMA to the tree */
 	vma_mas_store(vma, mas);
 	__vma_link_list(mm, vma, prev);
@@ -1078,9 +1078,6 @@ unsigned long do_mmap(struct file *file,
 	vm_flags = determine_vm_flags(file, prot, flags, capabilities);
 
 
-	if (mas_preallocate(&mas, vma, GFP_KERNEL))
-		goto error_maple_preallocate;
-
 	/* we're going to need to record the mapping */
 	region = kmem_cache_zalloc(vm_region_jar, GFP_KERNEL);
 	if (!region)
@@ -1090,6 +1087,9 @@ unsigned long do_mmap(struct file *file,
 	if (!vma)
 		goto error_getting_vma;
 
+	if (mas_preallocate(&mas, vma, GFP_KERNEL))
+		goto error_maple_preallocate;
+
 	region->vm_usage = 1;
 	region->vm_flags = vm_flags;
 	region->vm_pgoff = pgoff;
@@ -1262,7 +1262,6 @@ unsigned long do_mmap(struct file *file,
 	goto error;
 
 error_getting_vma:
-	mas_destroy(&mas);
 	kmem_cache_free(vm_region_jar, region);
 	pr_warn("Allocation of vma for %lu byte allocation from process %d failed\n",
 			len, current->pid);
@@ -1270,13 +1269,14 @@ unsigned long do_mmap(struct file *file,
 	return -ENOMEM;
 
 error_getting_region:
-	mas_destroy(&mas);
 	pr_warn("Allocation of vm region for %lu byte allocation from process %d failed\n",
 			len, current->pid);
 	show_free_areas(0, NULL);
 	return -ENOMEM;
 
 error_maple_preallocate:
+	kmem_cache_free(vm_region_jar, region);
+	vm_area_free(vma);
 	pr_warn("Allocation of vma tree for process %d failed\n", current->pid);
 	show_free_areas(0, NULL);
 	return -ENOMEM;
-- 
2.35.1


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux