mbox series

[0/7] vsprintf: Add %pTN to print Task Name

Message ID 20241213054610.55843-1-laoar.shao@gmail.com (mailing list archive)
Headers show
Series vsprintf: Add %pTN to print Task Name | expand

Message

Yafang Shao Dec. 13, 2024, 5:46 a.m. UTC
Since task->comm is guaranteed to be NUL-terminated, it can be printed
directly. This patch introduces a new vsnprintf format specifier, %pTN, to
print a task's name. In this specifier, p represents the task pointer, T
stands for "Task," and N denotes "Name." With this abstraction, users no
longer need to manually retrieve the task name for printing purposes.

In this patchset, all instances of get_task_comm() used for printing the
task name have been replaced with the new %pTN specifier. The raw uses of
'xyz->comm' for printouts will be addressed in a subsequent patch.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/bpf/CAHk-=wgqrwFXK-CO8-V4fwUh5ymnUZ=wJnFyufV1dM9rC1t3Lg@mail.gmail.com 

Yafang Shao (7):
  vsprintf: Add %pTN to print task name
  kernel: Replace get_task_comm() with %pTN
  arch: Replace get_task_comm() with %pTN
  net: Replace get_task_comm() with %pTN
  security: Replace get_task_comm() with %pTN
  drivers: Repace get_task_comm() with %pTN
  fs: Use %pTN to print task name

 arch/arc/kernel/unaligned.c                    |  9 ++++-----
 arch/x86/kernel/vm86_32.c                      |  5 ++---
 drivers/accel/habanalabs/common/context.c      |  5 ++---
 .../accel/habanalabs/common/habanalabs_ioctl.c | 15 +++++----------
 .../drm/i915/display/intel_display_driver.c    | 10 ++++------
 drivers/gpu/drm/nouveau/nouveau_chan.c         |  4 +---
 drivers/gpu/drm/nouveau/nouveau_drm.c          |  7 +++----
 drivers/tty/tty_io.c                           |  5 ++---
 fs/ocfs2/cluster/netdebug.c                    |  5 ++---
 kernel/capability.c                            | 12 ++++--------
 kernel/futex/waitwake.c                        |  5 ++---
 lib/vsprintf.c                                 | 18 ++++++++++++++++++
 net/wireless/wext-core.c                       |  6 ++----
 scripts/checkpatch.pl                          |  6 ++++--
 security/yama/yama_lsm.c                       |  6 ++----
 15 files changed, 57 insertions(+), 61 deletions(-)

Comments

Yafang Shao Dec. 13, 2024, 8:36 a.m. UTC | #1
On Fri, Dec 13, 2024 at 4:05 PM Petr Mladek <pmladek@suse.com> wrote:
>
> On Fri 2024-12-13 13:46:04, Yafang Shao wrote:
> > 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.
>
> What is the advantage, please?

The advantage is that it provides the flexibility to modify the comm
representation to meet future requirements. For instance, we could
rename it to "task_name" and increase its size.

>
> Honestly, I believe that the meaning of
>
>         printk("%s\n", task->comm);
>
> is much more clear than using a cryptic %pXYZ modifier:
>
>         printk("%pTN\n", task);
>
>
> The %pXYZ modifiers makes sense only when the formatting of the printed
> information needs some processing. But this is a plain string.

That makes sense to me.

> IMHO, it is not worth it. In fact, I believe that it is a
> counter productive.

Linus, what are your thoughts?


--
Regards
Yafang