Skip to contentSkip to conversation

mm/mremap: fix uninitialized return code

PATCH In review Arnd Bergmann 4 participants 5 messages Mar 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/mremap: fix uninitialized return code

From: Arnd Bergmann <[email protected]>

The 'err' variable is set in a conditinal branch and is not set otherwise:

mm/mremap.c:1017:7: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1017 | if (vma->vm_start != old_addr)

Set it to zero before the initial value is set.

Fixes 3129f7896afb ("mm/mremap: initial refactor of move_vma()")
---
 mm/mremap.c | 1 +
 1 file changed, 1 insertion(+)
mm/mremap.c +1 -0
index 456849b9e7bd..9c51a2360d84 100644
@@ -1014,6 +1014,7 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
 		return -ENOMEM;
 
 	if (vma->vm_ops && vma->vm_ops->may_split) {
+		err = 0;
 		if (vma->vm_start != old_addr)
 			err = vma->vm_ops->may_split(vma, old_addr);
 		if (!err && vma->vm_end != old_addr + old_len)
Signature · 1 line
2.39.5
#1 lore raw
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The 'err' variable is set in a conditinal branch and is not set otherwise:

Quoted 7 lines

mm/mremap.c:1017:7: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1017 | if (vma->vm_start != old_addr)

Set it to zero before the initial value is set.

Fixes 3129f7896afb ("mm/mremap: initial refactor of move_vma()")

Thanks for this, however this has already been fixed via Andrew doing a fix-patch which should land in mm-unstable,-next soon (possibly tmr?).

This is entirely my bad btw, for some reason my compiler locally didn't catch this even with CONFIG_WERROR on which _really_ surprises me...

Quoted 19 lines
---
 mm/mremap.c | 1 +
 1 file changed, 1 insertion(+)
mm/mremap.c +1 -1
index 456849b9e7bd..9c51a2360d84 100644
@@ -1014,6 +1014,7 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
 		return -ENOMEM;
 
 	if (vma->vm_ops && vma->vm_ops->may_split) {
+		err = 0;
 		if (vma->vm_start != old_addr)
 			err = vma->vm_ops->may_split(vma, old_addr);
 		if (!err && vma->vm_end != old_addr + old_len)
--

2.39.5

#2 lore raw
Quoted 11 lines · Lorenzo Stoakes
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The 'err' variable is set in a conditinal branch and is not set otherwise:

mm/mremap.c:1017:7: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1017 | if (vma->vm_start != old_addr)

Set it to zero before the initial value is set.

Quoted 8 lines
Quoted 2 lines
Fixes 3129f7896afb ("mm/mremap: initial refactor of move_vma()")

Thanks for this, however this has already been fixed via Andrew doing a fix-patch which should land in mm-unstable,-next soon (possibly tmr?).

This is entirely my bad btw, for some reason my compiler locally didn't catch this even with CONFIG_WERROR on which _really_ surprises me...

Unfortunately gcc never shows warnings about conditionally uninitialized variables. There is a -Wmaybe-uninitialized, but that has so many false positives that it is completely useless and it is turned off globally.

Arnd

#3 lore raw
Quoted 18 lines · Arnd Bergmann
Quoted 17 lines · Lorenzo Stoakes
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The 'err' variable is set in a conditinal branch and is not set otherwise:

Quoted 7 lines

mm/mremap.c:1017:7: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1017 | if (vma->vm_start != old_addr)

Set it to zero before the initial value is set.

Fixes 3129f7896afb ("mm/mremap: initial refactor of move_vma()")

Thanks for this, however this has already been fixed via Andrew doing a fix-patch which should land in mm-unstable,-next soon (possibly tmr?).

Quoted 7 lines
Quoted 2 lines

This is entirely my bad btw, for some reason my compiler locally didn't catch this even with CONFIG_WERROR on which _really_ surprises me...

Unfortunately gcc never shows warnings about conditionally uninitialized variables. There is a -Wmaybe-uninitialized, but that has so many false positives that it is completely useless and it is turned off globally.

OK I notice by building with LLVM=1 this is immediately reported locally, so from now on I'll make sure to do a clang build too.

At least there is some means by which I can sensibly determine this!

Cheers!

Quoted 2 lines

Arnd

#4 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The 'err' variable is set in a conditinal branch and is not set otherwise:

mm/mremap.c:1017:7: error: variable 'err' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1017 | if (vma->vm_start != old_addr)

Set it to zero before the initial value is set.

Fixes 3129f7896afb ("mm/mremap: initial refactor of move_vma()")

I think Andrew already fixed this:
https://lore.kernel.org/lkml/[email protected]/

Quoted 21 lines
---
 mm/mremap.c | 1 +
 1 file changed, 1 insertion(+)
mm/mremap.c +1 -0
index 456849b9e7bd..9c51a2360d84 100644
@@ -1014,6 +1014,7 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
 		return -ENOMEM;
 
 	if (vma->vm_ops && vma->vm_ops->may_split) {
+		err = 0;
 		if (vma->vm_start != old_addr)
 			err = vma->vm_ops->may_split(vma, old_addr);
 		if (!err && vma->vm_end != old_addr + old_len)
Signature · 1 line
2.39.5