Skip to contentSkip to conversation

mm, mempolicy: Check parameters first in kernel_get_mempolicy

PATCH Applied Wenchao Hao 2 participants 2 messages Aug 1, 2020 – Aug 4, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, mempolicy: Check parameters first in kernel_get_mempolicy

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

---
 mm/mempolicy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mempolicy.c +2 -2
index 381320671677..dac0cd0df3e1 100644
@@ -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)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 12 lines · On Sat, 1 Aug 2020 17:08:26 +0800 Wenchao Hao <[email protected]> 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.

...

mm/mempolicy.c +0 -0
@@ -1632,11 +1632,11 @@ static int kernel_get_mempolicy(int __user *policy,
 	int uninitialized_var(pval);
 	nodemask_t nodes;
 

mm/mempolicy.c static int kernel_get_mempolicy(int __user *policy, · line 1642

Quoted 10 lines
mm/mempolicy.c +2 -2
-	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.