irda: don't open-code memdup_user()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 13 May 2017 22:20:33 +0000 (18:20 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 30 Jun 2017 06:04:08 +0000 (02:04 -0400)
and no, GFP_ATOMIC does not make any sense there...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
net/irda/af_irda.c

index 8d77ad5cadaff3aa1feb18f168e779c5a6e7f917..2e6990f8b80b6b4cc1d59665b0154a81790e1788 100644 (file)
@@ -1901,16 +1901,10 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
                        goto out;
                }
 
-               ias_opt = kmalloc(sizeof(struct irda_ias_set), GFP_ATOMIC);
-               if (ias_opt == NULL) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-
                /* Copy query to the driver. */
-               if (copy_from_user(ias_opt, optval, optlen)) {
-                       kfree(ias_opt);
-                       err = -EFAULT;
+               ias_opt = memdup_user(optval, optlen);
+               if (IS_ERR(ias_opt)) {
+                       err = PTR_ERR(ias_opt);
                        goto out;
                }
 
@@ -2032,16 +2026,10 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
                        goto out;
                }
 
-               ias_opt = kmalloc(sizeof(struct irda_ias_set), GFP_ATOMIC);
-               if (ias_opt == NULL) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-
                /* Copy query to the driver. */
-               if (copy_from_user(ias_opt, optval, optlen)) {
-                       kfree(ias_opt);
-                       err = -EFAULT;
+               ias_opt = memdup_user(optval, optlen);
+               if (IS_ERR(ias_opt)) {
+                       err = PTR_ERR(ias_opt);
                        goto out;
                }
 
@@ -2317,16 +2305,10 @@ bed:
                        goto out;
                }
 
-               ias_opt = kmalloc(sizeof(struct irda_ias_set), GFP_ATOMIC);
-               if (ias_opt == NULL) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-
                /* Copy query to the driver. */
-               if (copy_from_user(ias_opt, optval, len)) {
-                       kfree(ias_opt);
-                       err = -EFAULT;
+               ias_opt = memdup_user(optval, len);
+               if (IS_ERR(ias_opt)) {
+                       err = PTR_ERR(ias_opt);
                        goto out;
                }
 
@@ -2381,16 +2363,10 @@ bed:
                        goto out;
                }
 
-               ias_opt = kmalloc(sizeof(struct irda_ias_set), GFP_ATOMIC);
-               if (ias_opt == NULL) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-
                /* Copy query to the driver. */
-               if (copy_from_user(ias_opt, optval, len)) {
-                       kfree(ias_opt);
-                       err = -EFAULT;
+               ias_opt = memdup_user(optval, len);
+               if (IS_ERR(ias_opt)) {
+                       err = PTR_ERR(ias_opt);
                        goto out;
                }