public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rahul Pathak <rahulpathaklinux@gmail.com>
To: gregkh@linuxfoundation.org, jslaby@suse.com,
	samuel.thibault@ens-lyon.org, pavel@ucw.cz,
	dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH] tty: vt: use memdup_user to reuse the code
Date: Sun, 20 Dec 2015 00:15:33 +0530	[thread overview]
Message-ID: <20151219184533.GA7305@platform-Vostro-3546> (raw)

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


             reply	other threads:[~2015-12-19 18:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-19 18:45 Rahul Pathak [this message]
2015-12-21 20:04 ` [PATCH] tty: vt: use memdup_user to reuse the code Dmitry Torokhov
2016-02-07  7:31 ` Greg KH
2016-02-07 10:08   ` rahul pathak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151219184533.GA7305@platform-Vostro-3546 \
    --to=rahulpathaklinux@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=samuel.thibault@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox