]> git.ipfire.org Git - thirdparty/linux.git/commit - mm/mmap.c
mm/mmap/vma_merge: explicitly assign res, vma, extend invariants
authorLorenzo Stoakes <lstoakes@gmail.com>
Wed, 22 Mar 2023 20:18:59 +0000 (20:18 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 6 Apr 2023 02:42:58 +0000 (19:42 -0700)
commitb0729ae0ae67a1a001e8d577b8be9ba44c4bdb26
treed05ba6e79dbbd4571cfbf104b0ce5e51ecae9394
parent00cd00a6a2b1cc0b7d35e56444dab96879def809
mm/mmap/vma_merge: explicitly assign res, vma, extend invariants

Previously, vma was an uninitialised variable which was only definitely
assigned as a result of the logic covering all possible input cases - for
it to have remained uninitialised, prev would have to be NULL, and next
would _have_ to be mergeable.

The value of res defaults to NULL, so we can neatly eliminate the
assignment to res and vma in the if (prev) block and ensure that both res
and vma are both explicitly assigned, by just setting both to prev.

In addition we add an explanation as to under what circumstances both
might change, and since we absolutely do rely on addr == curr->vm_start
should curr exist, assert that this is the case.

Link: https://lkml.kernel.org/r/83938bed24422cbe5954bbf491341674becfe567.1679516210.git.lstoakes@gmail.com
Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Vernon Yang <vernon2gm@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c