diff mbox series

mm, mempolicy: Check parameters first in kernel_get_mempolicy

Message ID 20200801090825.5597-1-haowenchao22@gmail.com (mailing list archive)
State New, archived
Headers show
Series mm, mempolicy: Check parameters first in kernel_get_mempolicy | expand

Commit Message

Wenchao Hao Aug. 1, 2020, 9:08 a.m. UTC
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(-)

Comments

Andrew Morton Aug. 4, 2020, 3:25 a.m. UTC | #1
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.
diff mbox series

Patch

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)