From: Cristina Opriceana Date: Sat, 28 Mar 2015 00:57:34 +0000 (+0200) Subject: Staging: rtl8712: Use memdup_user() instead of copy_from_user() X-Git-Tag: v4.14-rc1~5616^2~138^2~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45de432775d6df1b349b02c4d783237937278906;p=platform%2Fkernel%2Flinux-rpi.git Staging: rtl8712: Use memdup_user() instead of copy_from_user() 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index 81f39c3..c39d031 100644 --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -1912,13 +1912,9 @@ static int r871x_mp_ioctl_hdl(struct net_device *dev, 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;