yam: use memdup_user
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:42:22 +0000 (23:42 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 May 2017 19:02:10 +0000 (15:02 -0400)
Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hamradio/yam.c

index b6891ada1d7b7b67311fc8f1e6b04115ba341d11..7a7c5224a3368785fa046640edfbf0888c0d4128 100644 (file)
@@ -976,12 +976,10 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        case SIOCYAMSMCS:
                if (netif_running(dev))
                        return -EINVAL;         /* Cannot change this parameter when up */
-               if ((ym = kmalloc(sizeof(struct yamdrv_ioctl_mcs), GFP_KERNEL)) == NULL)
-                       return -ENOBUFS;
-               if (copy_from_user(ym, ifr->ifr_data, sizeof(struct yamdrv_ioctl_mcs))) {
-                       kfree(ym);
-                       return -EFAULT;
-               }
+               ym = memdup_user(ifr->ifr_data,
+                                sizeof(struct yamdrv_ioctl_mcs));
+               if (IS_ERR(ym))
+                       return PTR_ERR(ym);
                if (ym->bitrate > YAM_MAXBITRATE) {
                        kfree(ym);
                        return -EINVAL;