2021-09-14 15:11:00

by Amit Kachhap

[permalink] [raw]
Subject: [PATCH] mm/memory: Avoid unnecessary kernel/user pointer conversion

Annotating a pointer from __user to kernel and then back again might
confuse sparse. In copy_huge_page_from_user() it can be avoided by
removing the intermediate variable since it is never used.

Cc: Andrew Morton <[email protected]>
Signed-off-by: Amit Daniel Kachhap <[email protected]>
---
mm/memory.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 25fc46e87214..90970d19b7dd 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5411,7 +5411,6 @@ long copy_huge_page_from_user(struct page *dst_page,
unsigned int pages_per_huge_page,
bool allow_pagefault)
{
- void *src = (void *)usr_src;
void *page_kaddr;
unsigned long i, rc = 0;
unsigned long ret_val = pages_per_huge_page * PAGE_SIZE;
@@ -5424,8 +5423,7 @@ long copy_huge_page_from_user(struct page *dst_page,
else
page_kaddr = kmap_atomic(subpage);
rc = copy_from_user(page_kaddr,
- (const void __user *)(src + i * PAGE_SIZE),
- PAGE_SIZE);
+ usr_src + i * PAGE_SIZE, PAGE_SIZE);
if (allow_pagefault)
kunmap(subpage);
else
--
2.17.1


2021-09-15 10:44:54

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [PATCH] mm/memory: Avoid unnecessary kernel/user pointer conversion

On Tue, Sep 14, 2021 at 08:38:20PM +0530, Amit Daniel Kachhap wrote:
> Annotating a pointer from __user to kernel and then back again might
> confuse sparse. In copy_huge_page_from_user() it can be avoided by
> removing the intermediate variable since it is never used.
>
> Cc: Andrew Morton <[email protected]>
> Signed-off-by: Amit Daniel Kachhap <[email protected]>

Acked-by: Kirill A. Shutemov <[email protected]>

--
Kirill A. Shutemov