* [PATCH v2] mm: initialize return of vm_insert_pages
@ 2020-07-03 15:53 trix
2020-07-03 19:04 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: trix @ 2020-07-03 15:53 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, Tom Rix
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>
---
v1 change err intializer to -EINVAL
mm/memory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memory.c b/mm/memory.c
index 17a3df0f3994..76a00f414777 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 = -EINVAL;
for (; idx < pgcount; ++idx) {
err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]);
--
2.18.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm: initialize return of vm_insert_pages
2020-07-03 15:53 [PATCH v2] mm: initialize return of vm_insert_pages trix
@ 2020-07-03 19:04 ` Andrew Morton
2020-07-03 19:23 ` Tom Rix
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2020-07-03 19:04 UTC (permalink / raw)
To: trix; +Cc: linux-mm, linux-kernel
On Fri, 3 Jul 2020 08:53:54 -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.
>
> ...
>
> --- 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 = -EINVAL;
>
> for (; idx < pgcount; ++idx) {
> err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]);
If a caller were to ask vm_insert_pages() to insert zero pages, I
suspect we should just return zero and set *num to zero.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm: initialize return of vm_insert_pages
2020-07-03 19:04 ` Andrew Morton
@ 2020-07-03 19:23 ` Tom Rix
0 siblings, 0 replies; 3+ messages in thread
From: Tom Rix @ 2020-07-03 19:23 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel
On 7/3/20 12:04 PM, Andrew Morton wrote:
> On Fri, 3 Jul 2020 08:53:54 -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.
>>
>> ...
>>
>> --- 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 = -EINVAL;
>>
>> for (; idx < pgcount; ++idx) {
>> err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]);
> If a caller were to ask vm_insert_pages() to insert zero pages, I
> suspect we should just return zero and set *num to zero.
That would be v1 of the patch.
For the loop to not execute *num/pgcount is initially 0, and *num = pgcount - idx is 0 on exit.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-03 19:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 15:53 [PATCH v2] mm: initialize return of vm_insert_pages trix
2020-07-03 19:04 ` Andrew Morton
2020-07-03 19:23 ` Tom Rix
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).