The patch titled Subject: mm/nommu: fix compile warning in do_mmap() has been added to the -mm mm-unstable branch. Its filename is nommu-remove-uses-of-vma-linked-list-fix-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/nommu-remove-uses-of-vma-linked-list-fix-fix.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx> Subject: mm/nommu: fix compile warning in do_mmap() Date: Thu, 2 Jun 2022 09:44:38 -0400 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. Link: https://lkml.kernel.org/r/20220602141145.i44sjd3mxvqaofvt@revolver Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> Reported-by: kernel test robot <lkp@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/nommu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/mm/nommu.c~nommu-remove-uses-of-vma-linked-list-fix-fix +++ a/mm/nommu.c @@ -590,8 +590,8 @@ static void mas_add_vma_to_mm(struct ma_ 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 @@ sharing_violation: 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 @@ error_getting_vma: 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; _ Patches currently in -mm which might be from Liam.Howlett@xxxxxxxxxx are nommu-remove-uses-of-vma-linked-list-fix.patch nommu-remove-uses-of-vma-linked-list-fix-fix.patch