Skip to contentSkip to conversation

mm: initialize return of vm_insert_pages

PATCH Superseded [email protected] 2 participants 3 messages Jul 3, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: initialize return of vm_insert_pages

From: Tom Rix <[email protected]>

clang static analysis reports a garbage return

In file included from mm/memory.c:84:
mm/memory.c:1612:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]

        return err;
        ^~~~~~~~~~

The setting of err depends on a loop executing.
So initialize err.

---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
index 17a3df0f3994..41513275823b 100644
@@ -1601,7 +1601,7 @@ int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr,
 	return insert_pages(vma, addr, pages, num, vma->vm_page_prot);
 #else
 	unsigned long idx = 0, pgcount = *num;
-	int err;
+	int err = 0;
 
 	for (; idx < pgcount; ++idx) {
 		err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]);
Signature · 1 line
2.18.1
#1 lore raw
Quoted 11 lines · On Fri, Jul 03, 2020 at 07:52:02AM -0700, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis reports a garbage return

In file included from mm/memory.c:84:
mm/memory.c:1612:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]

        return err;
        ^~~~~~~~~~

The setting of err depends on a loop executing.
So initialize err.

I'd argue that returning zero is wrong. If someone's asked to insert zero pages, that's a nonsense thing to do so it should return -EINVAL..

author
#2 lore raw
Quoted 10 lines · Matthew Wilcox
Quoted 9 lines · On Fri, Jul 03, 2020 at 07:52:02AM -0700, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis reports a garbage return

In file included from mm/memory.c:84:
mm/memory.c:1612:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]

        return err;
        ^~~~~~~~~~
Quoted 5 lines
Quoted 2 lines

The setting of err depends on a loop executing.
So initialize err.

I'd argue that returning zero is wrong. If someone's asked to insert zero pages, that's a nonsense thing to do so it should return -EINVAL..

good point, i'll respin.