net/hippi/rrunner: use memdup_user
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:42:16 +0000 (23:42 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 May 2017 19:02:09 +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/hippi/rrunner.c

index dd7fc6659ad40222f48d29bee637479ebc475322..365c4d987a014e6caf247e4bb77540d2d155eb1e 100644 (file)
@@ -1615,17 +1615,14 @@ static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        return -EPERM;
                }
 
-               image = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
-               oldimage = kmalloc(EEPROM_WORDS * sizeof(u32), GFP_KERNEL);
-               if (!image || !oldimage) {
-                       error = -ENOMEM;
-                       goto wf_out;
-               }
+               image = memdup_user(rq->ifr_data, EEPROM_BYTES);
+               if (IS_ERR(image))
+                       return PTR_ERR(image);
 
-               error = copy_from_user(image, rq->ifr_data, EEPROM_BYTES);
-               if (error) {
-                       error = -EFAULT;
-                       goto wf_out;
+               oldimage = kmalloc(EEPROM_BYTES, GFP_KERNEL);
+               if (!oldimage) {
+                       kfree(image);
+                       return -ENOMEM;
                }
 
                if (rrpriv->fw_running){