Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mm, mempolicy: Check parameters first in kernel_get_mempolicy
@ 2020-08-01  9:08 Wenchao Hao
  2020-08-04  3:25 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Wenchao Hao @ 2020-08-01  9:08 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Wenchao Hao

Previous implement called untagged_addr before error check, while
if the error check failed and return EINVAL, the untagged_addr is
just useless work.

Signed-off-by: Wenchao Hao <haowenchao22@gmail.com>
---
 mm/mempolicy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 381320671677..dac0cd0df3e1 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1632,11 +1632,11 @@ static int kernel_get_mempolicy(int __user *policy,
 	int uninitialized_var(pval);
 	nodemask_t nodes;
 
-	addr = untagged_addr(addr);
-
 	if (nmask != NULL && maxnode < nr_node_ids)
 		return -EINVAL;
 
+	addr = untagged_addr(addr);
+
 	err = do_get_mempolicy(&pval, &nodes, addr, flags);
 
 	if (err)
-- 
2.25.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm, mempolicy: Check parameters first in kernel_get_mempolicy
  2020-08-01  9:08 [PATCH] mm, mempolicy: Check parameters first in kernel_get_mempolicy Wenchao Hao
@ 2020-08-04  3:25 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2020-08-04  3:25 UTC (permalink / raw)
  To: Wenchao Hao; +Cc: linux-mm, linux-kernel

On Sat,  1 Aug 2020 17:08:26 +0800 Wenchao Hao <haowenchao22@gmail.com> wrote:

> Previous implement called untagged_addr before error check, while
> if the error check failed and return EINVAL, the untagged_addr is
> just useless work.
>
> ...
>
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1632,11 +1632,11 @@ static int kernel_get_mempolicy(int __user *policy,
>  	int uninitialized_var(pval);
>  	nodemask_t nodes;
>  
> -	addr = untagged_addr(addr);
> -
>  	if (nmask != NULL && maxnode < nr_node_ids)
>  		return -EINVAL;
>  
> +	addr = untagged_addr(addr);
> +
>  	err = do_get_mempolicy(&pval, &nodes, addr, flags);
>  
>  	if (err)

Well, the compiler will surely avoid that useless work.  But the code
is better this way.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01  9:08 [PATCH] mm, mempolicy: Check parameters first in kernel_get_mempolicy Wenchao Hao
2020-08-04  3:25 ` Andrew Morton

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git