x86/fpu: Replace vmalloc + copy_from_user with vmemdup_user in xstateregs_set
PATCH 1/1 x86/fpu: Replace vmalloc + copy_from_user with vmemdup_user in xstateregs_set
Replace vmalloc() followed by copy_from_user() with vmemdup_user() to improve and simplify xstateregs_set(). Use kvfree() to free.
Return early if an error occurs and remove the obsolete 'out' label.
No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>
--- arch/x86/kernel/fpu/regset.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
arch/x86/kernel/fpu/regset.c +5 -10
@@ -3,6 +3,7 @@* FPU register's regset abstraction, for ptrace, core dumps, etc. */ #include <linux/sched/task_stack.h> +#include <linux/string.h> #include <linux/vmalloc.h> #include <asm/fpu/api.h>
@@ -157,21 +158,15 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,return -EFAULT ;if (!kbuf) { - tmpbuf =vmalloc (count); -if (!tmpbuf) -return -ENOMEM ; - -if (copy_from_user (tmpbuf, ubuf, count)) { - ret = -EFAULT ; - goto out; - } + tmpbuf =vmemdup_user (ubuf, count); +if (IS_ERR (tmpbuf)) +return PTR_ERR (tmpbuf); }fpu_force_restore (fpu); ret =copy_uabi_from_kernel_to_xstate (fpu->fpstate, kbuf ?: tmpbuf, &target->thread.pkru); -out: -vfree (tmpbuf); +kvfree (tmpbuf);return ret; }
Signature · 1 line
2.51.0