From: Yafang Shao <laoar.shao@gmail.com>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, x86@kernel.org,
linux-snps-arc@lists.infradead.org,
linux-wireless@vger.kernel.org, intel-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org, nouveau@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, ocfs2-devel@lists.linux.dev,
Yafang Shao <laoar.shao@gmail.com>,
Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: [PATCH 1/7] vsprintf: Add %pTN to print task name
Date: Fri, 13 Dec 2024 13:46:04 +0800 [thread overview]
Message-ID: <20241213054610.55843-2-laoar.shao@gmail.com> (raw)
In-Reply-To: <20241213054610.55843-1-laoar.shao@gmail.com>
Since the task->comm is guaranteed to be NUL-ternimated, we can print it
directly. Add a new vsnprintf format specifier "%pTN" to print task comm,
where 'p' represents the task Pointer, 'T' stands for Task, and 'N' denots
Name. With this abstraction, the user no longer needs to care about
retrieving task name.
checkpatch.pl is updated accordingly.
Link: https://lore.kernel.org/bpf/CAHk-=wgqrwFXK-CO8-V4fwUh5ymnUZ=wJnFyufV1dM9rC1t3Lg@mail.gmail.com
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
---
lib/vsprintf.c | 18 ++++++++++++++++++
scripts/checkpatch.pl | 6 ++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6ac02bbb7df1..bb1018d79655 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2273,6 +2273,17 @@ char *resource_or_range(const char *fmt, char *buf, char *end, void *ptr,
return resource_string(buf, end, ptr, spec, fmt);
}
+static noinline_for_stack
+char *task_name_string(char *buf, char *end, struct task_struct *p,
+ struct printf_spec spec)
+{
+ if (check_pointer(&buf, end, p, spec))
+ return buf;
+
+ buf = string(buf, end, p->comm, spec);
+ return buf;
+}
+
int __init no_hash_pointers_enable(char *str)
{
if (no_hash_pointers)
@@ -2525,6 +2536,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
default:
return error_string(buf, end, "(einval)", spec);
}
+ case 'T':
+ switch (fmt[1]) {
+ case 'N':
+ return task_name_string(buf, end, ptr, spec);
+ default:
+ return error_string(buf, end, "(einval)", spec);
+ }
default:
return default_pointer(buf, end, ptr, spec);
}
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9eed3683ad76..fe0d80f55ce8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6908,11 +6908,13 @@ sub process {
$specifier = $1;
$extension = $2;
$qualifier = $3;
- if ($extension !~ /[4SsBKRraEehMmIiUDdgVCbGNOxtf]/ ||
+ if ($extension !~ /[4SsBKRraEehMmIiUDdgVCbGNOxtfT]/ ||
($extension eq "f" &&
defined $qualifier && $qualifier !~ /^w/) ||
($extension eq "4" &&
- defined $qualifier && $qualifier !~ /^cc/)) {
+ defined $qualifier && $qualifier !~ /^cc/) ||
+ ($extension eq "T" &&
+ defined $qualifier && $qualifier ne "N")) {
$bad_specifier = $specifier;
last;
}
--
2.43.5
next prev parent reply other threads:[~2024-12-13 5:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 5:46 [PATCH 0/7] vsprintf: Add %pTN to print Task Name Yafang Shao
2024-12-13 5:46 ` Yafang Shao [this message]
2024-12-13 8:05 ` [PATCH 1/7] vsprintf: Add %pTN to print task name Petr Mladek
2024-12-13 8:35 ` Kalle Valo
2024-12-13 13:27 ` Borislav Petkov
2024-12-13 17:11 ` Andy Shevchenko
2024-12-13 8:36 ` Yafang Shao
2024-12-13 5:46 ` [PATCH 2/7] kernel: Replace get_task_comm() with %pTN Yafang Shao
2024-12-13 5:46 ` [PATCH 3/7] arch: " Yafang Shao
2024-12-13 5:46 ` [PATCH 4/7] net: " Yafang Shao
2024-12-13 5:46 ` [PATCH 5/7] security: " Yafang Shao
2024-12-16 23:02 ` Paul Moore
2024-12-17 0:41 ` Kees Cook
2024-12-17 1:08 ` Linus Torvalds
2024-12-13 5:46 ` [PATCH 6/7] drivers: Repace " Yafang Shao
2024-12-13 7:48 ` Jiri Slaby
2024-12-16 20:33 ` Lyude Paul
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=20241213054610.55843-2-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=apw@canonical.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=dwaipayanray1@gmail.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=lukas.bulwahn@gmail.com \
--cc=nouveau@lists.freedesktop.org \
--cc=ocfs2-devel@lists.linux.dev \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).