Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1295431 > unrolled thread

[PATCH] tty: vt: use memdup_user to reuse the code

Started byRahul Pathak <rahulpathaklinux@gmail.com>
First post2015-12-19 19:50 +0100
Last post2015-12-21 21:10 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] tty: vt: use memdup_user to reuse the code Rahul Pathak <rahulpathaklinux@gmail.com> - 2015-12-19 19:50 +0100
    Re: [PATCH] tty: vt: use memdup_user to reuse the code Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2015-12-21 21:10 +0100

#1295431 — [PATCH] tty: vt: use memdup_user to reuse the code

FromRahul Pathak <rahulpathaklinux@gmail.com>
Date2015-12-19 19:50 +0100
Subject[PATCH] tty: vt: use memdup_user to reuse the code
Message-ID<qHuJP-6Om-1@gated-at.bofh.it>
Fixing coccicheck warning which recommends to use memdup_user instead
to reimplement its code, using memdup_user simplifies the code

./drivers/tty/vt/keyboard.c:1709:9-16: WARNING opportunity for memdup_user
./drivers/tty/vt/keyboard.c:1752:9-16: WARNING opportunity for memdup_user

Signed-off-by: Rahul Pathak <rahulpathaklinux@gmail.com>
---
 drivers/tty/vt/keyboard.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 6f0336f..ec05360 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1706,16 +1706,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
 			return -EINVAL;
 
 		if (ct) {
-			dia = kmalloc(sizeof(struct kbdiacr) * ct,
-								GFP_KERNEL);
-			if (!dia)
-				return -ENOMEM;
-
-			if (copy_from_user(dia, a->kbdiacr,
-					sizeof(struct kbdiacr) * ct)) {
-				kfree(dia);
-				return -EFAULT;
-			}
+			dia = memdup_user(a->kbdiacr,
+					sizeof(struct kbdiacr) * ct);
+			if (IS_ERR(dia))
+				return PTR_ERR(dia);
 		}
 
 		spin_lock_irqsave(&kbd_event_lock, flags);
@@ -1749,16 +1743,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
 			return -EINVAL;
 
 		if (ct) {
-			buf = kmalloc(ct * sizeof(struct kbdiacruc),
-								GFP_KERNEL);
-			if (buf == NULL)
-				return -ENOMEM;
-
-			if (copy_from_user(buf, a->kbdiacruc,
-					ct * sizeof(struct kbdiacruc))) {
-				kfree(buf);
-				return -EFAULT;
-			}
+			buf = memdup_user(a->kbdiacruc,
+					sizeof(struct kbdiacruc) * ct);
+			if (IS_ERR(buf))
+				return PTR_ERR(buf);
 		} 
 		spin_lock_irqsave(&kbd_event_lock, flags);
 		if (ct)
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1296182

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2015-12-21 21:10 +0100
Message-ID<qIeWm-2Dm-13@gated-at.bofh.it>
In reply to#1295431
On Sun, Dec 20, 2015 at 12:15:33AM +0530, Rahul Pathak wrote:
> Fixing coccicheck warning which recommends to use memdup_user instead
> to reimplement its code, using memdup_user simplifies the code
> 
> ./drivers/tty/vt/keyboard.c:1709:9-16: WARNING opportunity for memdup_user
> ./drivers/tty/vt/keyboard.c:1752:9-16: WARNING opportunity for memdup_user
> 
> Signed-off-by: Rahul Pathak <rahulpathaklinux@gmail.com>

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

(assuming Greg will pick it up, otherwise I can take it through my
tree).

Thanks.

> ---
>  drivers/tty/vt/keyboard.c | 28 ++++++++--------------------
>  1 file changed, 8 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index 6f0336f..ec05360 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -1706,16 +1706,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
>  			return -EINVAL;
>  
>  		if (ct) {
> -			dia = kmalloc(sizeof(struct kbdiacr) * ct,
> -								GFP_KERNEL);
> -			if (!dia)
> -				return -ENOMEM;
> -
> -			if (copy_from_user(dia, a->kbdiacr,
> -					sizeof(struct kbdiacr) * ct)) {
> -				kfree(dia);
> -				return -EFAULT;
> -			}
> +			dia = memdup_user(a->kbdiacr,
> +					sizeof(struct kbdiacr) * ct);
> +			if (IS_ERR(dia))
> +				return PTR_ERR(dia);
>  		}
>  
>  		spin_lock_irqsave(&kbd_event_lock, flags);
> @@ -1749,16 +1743,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
>  			return -EINVAL;
>  
>  		if (ct) {
> -			buf = kmalloc(ct * sizeof(struct kbdiacruc),
> -								GFP_KERNEL);
> -			if (buf == NULL)
> -				return -ENOMEM;
> -
> -			if (copy_from_user(buf, a->kbdiacruc,
> -					ct * sizeof(struct kbdiacruc))) {
> -				kfree(buf);
> -				return -EFAULT;
> -			}
> +			buf = memdup_user(a->kbdiacruc,
> +					sizeof(struct kbdiacruc) * ct);
> +			if (IS_ERR(buf))
> +				return PTR_ERR(buf);
>  		} 
>  		spin_lock_irqsave(&kbd_event_lock, flags);
>  		if (ct)
> -- 
> 2.1.4
> 

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web