Use memdup_user() to avoid its duplicated implementation and simplify
code. memdup_user() uses GFP_KERNEL instead of GFP_ATOMIC,
which is valid because copy_from_user() might sleep and it's useless
to make the allocation atomic. Found with coccinelle.
Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
bset = (u8)(p->flags & 0xFFFF);
len = p->length;
pparmbuf = NULL;
- pparmbuf = kmalloc(len, GFP_ATOMIC);
- if (pparmbuf == NULL) {
- ret = -ENOMEM;
- goto _r871x_mp_ioctl_hdl_exit;
- }
- if (copy_from_user(pparmbuf, p->pointer, len)) {
- ret = -EFAULT;
+ pparmbuf = memdup_user(p->pointer, len);
+ if (IS_ERR(pparmbuf)) {
+ ret = PTR_ERR(pparmbuf);
goto _r871x_mp_ioctl_hdl_exit;
}
poidparam = (struct mp_ioctl_param *)pparmbuf;