diff mbox series

mm: initialize return of vm_insert_pages

Message ID 20200703145202.10629-1-trix@redhat.com (mailing list archive)
State New, archived
Headers show
Series mm: initialize return of vm_insert_pages | expand

Commit Message

Tom Rix July 3, 2020, 2:52 p.m. UTC
From: Tom Rix <trix@redhat.com>

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.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Matthew Wilcox (Oracle) July 3, 2020, 2:54 p.m. UTC | #1
On Fri, Jul 03, 2020 at 07:52:02AM -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> 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..
Tom Rix July 3, 2020, 3:46 p.m. UTC | #2
On 7/3/20 7:54 AM, Matthew Wilcox wrote:
> On Fri, Jul 03, 2020 at 07:52:02AM -0700, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> 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..
>
good point, i'll respin.
diff mbox series

Patch

diff --git a/mm/memory.c b/mm/memory.c
index 17a3df0f3994..41513275823b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -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]);