public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Ajay Garg <ajaygargnsit@gmail.com>
To: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ajay Garg <ajaygargnsit@gmail.com>
Subject: [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed.
Date: Sat,  6 Nov 2021 15:02:02 +0530	[thread overview]
Message-ID: <20211106093202.44518-1-ajaygargnsit@gmail.com> (raw)

In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of
KDGKBSENT or KDGSKBSENT.

If cmd is none of the above, no kbs is kmalloced, and thus,
kbs must only be kfreed if it is really kmalloced.

Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
---
 drivers/tty/vt/keyboard.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index dfef7de8a057..95839987c79c 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 {
 	unsigned char kb_func;
 	unsigned long flags;
-	char *kbs;
+	char *kbs = NULL;
 	int ret;
 
 	if (get_user(kb_func, &user_kdgkb->kb_func))
@@ -2092,7 +2092,8 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 		break;
 	}
 
-	kfree(kbs);
+        if(kbs)
+            kfree(kbs);
 
 	return ret;
 }
-- 
2.30.2


             reply	other threads:[~2021-11-06  9:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06  9:32 Ajay Garg [this message]
2021-11-06  9:41 ` [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed Greg KH
2021-11-06 10:43   ` Ajay Garg

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=20211106093202.44518-1-ajaygargnsit@gmail.com \
    --to=ajaygargnsit@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.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