From: Thorsten Blum <thorsten.blum@linux.dev>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
Alexey Gladkov <legion@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Myrrh Periwinkle <myrrhperiwinkle@qtmlabs.xyz>,
Thomas Gleixner <tglx@kernel.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH v2] tty: vt/keyboard: Hoist and reuse variable in vt_do_kdgkb_ioctl
Date: Mon, 2 Mar 2026 16:32:52 +0100 [thread overview]
Message-ID: <20260302153255.6278-2-thorsten.blum@linux.dev> (raw)
Hoist 'len' and use it in both cases.
Add a comment explaining why reassigning 'kbs' is intentional.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Keep 'kbs' reassignment and add a comment why it's required (Jiri)
- Link to v1: https://lore.kernel.org/lkml/20260226123419.737669-1-thorsten.blum@linux.dev/
---
drivers/tty/vt/keyboard.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 13bc048f45e8..88fd4ef2634a 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -2000,17 +2000,18 @@ static char *vt_kdskbsent(char *kbs, unsigned char cur)
int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
{
unsigned char kb_func;
+ ssize_t len;
if (get_user(kb_func, &user_kdgkb->kb_func))
return -EFAULT;
kb_func = array_index_nospec(kb_func, MAX_NR_FUNC);
+ /* size should have been a struct member */
+ len = sizeof(user_kdgkb->kb_string);
+
switch (cmd) {
case KDGKBSENT: {
- /* size should have been a struct member */
- ssize_t len = sizeof(user_kdgkb->kb_string);
-
char __free(kfree) *kbs = kmalloc(len, GFP_KERNEL);
if (!kbs)
return -ENOMEM;
@@ -2031,11 +2032,16 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
return -EPERM;
char __free(kfree) *kbs = strndup_user(user_kdgkb->kb_string,
- sizeof(user_kdgkb->kb_string));
+ len);
if (IS_ERR(kbs))
return PTR_ERR(kbs);
guard(spinlock_irqsave)(&func_buf_lock);
+
+ /*
+ * Ownership transfer: vt_kdskbsent() returns a pointer
+ * that must be freed (new buffer, old buffer, or NULL).
+ */
kbs = vt_kdskbsent(kbs, kb_func);
return 0;
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
next reply other threads:[~2026-03-02 15:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 15:32 Thorsten Blum [this message]
2026-03-12 14:18 ` [PATCH v2] tty: vt/keyboard: Hoist and reuse variable in vt_do_kdgkb_ioctl Greg Kroah-Hartman
2026-03-12 15:30 ` Thorsten Blum
2026-03-12 15:56 ` Greg Kroah-Hartman
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=20260302153255.6278-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=legion@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=myrrhperiwinkle@qtmlabs.xyz \
--cc=nathan@kernel.org \
--cc=tglx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.