mm, mempolicy: Check parameters first in kernel_get_mempolicy
Subsystems (2)
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.
Signed-off-by Wenchao Hao <[email protected]>
--- mm/mempolicy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mempolicy.c +2 -2
@@ -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
Andrew Morton
maintainerQuoted 12 lines · On Sat, 1 Aug 2020 17:08:26 +0800 Wenchao Hao <[email protected]> wrote:
Previous implement called
untagged_addrbefore error check, while if the error check failed and return EINVAL, theuntagged_addris 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.