Skip to contentSkip to conversation

unitialized return value in mm/mlock.c: __mlock_vma_pages_range()

PATCH In review Helge Deller 2 participants 2 messages Nov 16, 2008

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

PATCH 1/1 unitialized return value in mm/mlock.c: __mlock_vma_pages_range()

Fix an unitialized return value when compiling on parisc (with CONFIG_UNEVICTABLE_LRU=y):
mm/mlock.c: In function `__mlock_vma_pages_range':
mm/mlock.c:165: warning: `ret' might be used uninitialized in this function

mm/mlock.c +1 -1
@@ -162,7 +162,7 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
 	unsigned long addr = start;
 	struct page *pages[16]; /* 16 gives a reasonable batch */
 	int nr_pages = (end - start) / PAGE_SIZE;
-	int ret;
+	int ret = 0;
 	int gup_flags = 0;
 
 	VM_BUG_ON(start & ~PAGE_MASK);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 4 lines · Helge Deller

Fix an unitialized return value when compiling on parisc (with CONFIG_UNEVICTABLE_LRU=y):
mm/mlock.c: In function `__mlock_vma_pages_range':
mm/mlock.c:165: warning: `ret' might be used uninitialized in this function

Looks valid.

Of course, nobody should ever call this with a range that could possibly be empty, so an equally valid approach would be to change the "while" loop to a "do while()", and that would generate better code. But I guess the simple unnecessary initialization is more defensive programming, in that if some other buggy caller does set things up with an empty range, it gets the right result.

Btw, exactly _because_ gcc warnings about uninitialized functions are sometimes bogus (ie due to gcc simply not being able to follow things like conditional initializations where the values are only used if they were initialized), I would ask that people comment on these kinds of issues when they send in patches.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>