staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
authorWan Jiabing <wanjiabing@vivo.com>
Thu, 21 Oct 2021 12:20:02 +0000 (08:20 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Oct 2021 09:06:36 +0000 (11:06 +0200)
Fix following coccicheck warning:
./drivers/staging/r8188eu/os_dep/ioctl_linux.c:1986:8-15: WARNING
opportunity for memdup_user.

Use memdup_user rather than duplicating its implementation, which
makes code simple and easy to understand.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
Link: https://lore.kernel.org/r/20211021122015.6974-1-wanjiabing@vivo.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/r8188eu/os_dep/ioctl_linux.c

index 4e51d5a559855e5000af7f8889aa228b6d5015f9..52d42e57644332c303caa12e8c06e22cb4e6cb3e 100644 (file)
@@ -1984,14 +1984,9 @@ static int rtw_wx_read32(struct net_device *dev,
        padapter = (struct adapter *)rtw_netdev_priv(dev);
        p = &wrqu->data;
        len = p->length;
-       ptmp = kmalloc(len, GFP_KERNEL);
-       if (!ptmp)
-               return -ENOMEM;
-
-       if (copy_from_user(ptmp, p->pointer, len)) {
-               kfree(ptmp);
-               return -EFAULT;
-       }
+       ptmp = memdup_user(p->pointer, len);
+       if (IS_ERR(ptmp))
+               return PTR_ERR(ptmp);
 
        bytes = 0;
        addr = 0;