drivers: remove get_task_comm() and print task comm directly

Since task->comm is guaranteed to be NUL-terminated, we can print it
directly without the need to copy it into a separate buffer.  This
simplifies the code and avoids unnecessary operations.

Link: https://lkml.kernel.org/r/20241219023452.69907-6-laoar.shao@gmail.com
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org> (For tty)
Reviewed-by: Lyude Paul <lyude@redhat.com> (For nouveau)
Cc: Oded Gabbay <ogabbay@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: "André Almeida" <andrealmeid@igalia.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vineet Gupta <vgupta@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Yafang Shao 2024-12-19 10:34:52 +08:00 committed by Andrew Morton
parent ba4510352b
commit cf08bd297e
6 changed files with 10 additions and 22 deletions

View File

@ -199,7 +199,6 @@ out_err:
int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx) int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
{ {
char task_comm[TASK_COMM_LEN];
int rc = 0, i; int rc = 0, i;
ctx->hdev = hdev; ctx->hdev = hdev;
@ -272,7 +271,7 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
mutex_init(&ctx->ts_reg_lock); mutex_init(&ctx->ts_reg_lock);
dev_dbg(hdev->dev, "create user context, comm=\"%s\", asid=%u\n", dev_dbg(hdev->dev, "create user context, comm=\"%s\", asid=%u\n",
get_task_comm(task_comm, current), ctx->asid); current->comm, ctx->asid);
} }
return 0; return 0;

View File

@ -1279,13 +1279,10 @@ static long _hl_ioctl(struct hl_fpriv *hpriv, unsigned int cmd, unsigned long ar
retcode = -EFAULT; retcode = -EFAULT;
out_err: out_err:
if (retcode) { if (retcode)
char task_comm[TASK_COMM_LEN];
dev_dbg_ratelimited(dev, dev_dbg_ratelimited(dev,
"error in ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n", "error in ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n",
task_pid_nr(current), get_task_comm(task_comm, current), cmd, nr); task_pid_nr(current), current->comm, cmd, nr);
}
if (kdata != stack_kdata) if (kdata != stack_kdata)
kfree(kdata); kfree(kdata);
@ -1308,11 +1305,9 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)
if (nr == _IOC_NR(DRM_IOCTL_HL_INFO)) { if (nr == _IOC_NR(DRM_IOCTL_HL_INFO)) {
ioctl = &hl_ioctls_control[nr - HL_COMMAND_START]; ioctl = &hl_ioctls_control[nr - HL_COMMAND_START];
} else { } else {
char task_comm[TASK_COMM_LEN];
dev_dbg_ratelimited(hdev->dev_ctrl, dev_dbg_ratelimited(hdev->dev_ctrl,
"invalid ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n", "invalid ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n",
task_pid_nr(current), get_task_comm(task_comm, current), cmd, nr); task_pid_nr(current), current->comm, cmd, nr);
return -ENOTTY; return -ENOTTY;
} }

View File

@ -391,7 +391,6 @@ void intel_display_driver_resume_access(struct drm_i915_private *i915)
*/ */
bool intel_display_driver_check_access(struct drm_i915_private *i915) bool intel_display_driver_check_access(struct drm_i915_private *i915)
{ {
char comm[TASK_COMM_LEN];
char current_task[TASK_COMM_LEN + 16]; char current_task[TASK_COMM_LEN + 16];
char allowed_task[TASK_COMM_LEN + 16] = "none"; char allowed_task[TASK_COMM_LEN + 16] = "none";
@ -400,12 +399,11 @@ bool intel_display_driver_check_access(struct drm_i915_private *i915)
return true; return true;
snprintf(current_task, sizeof(current_task), "%s[%d]", snprintf(current_task, sizeof(current_task), "%s[%d]",
get_task_comm(comm, current), current->comm, task_pid_vnr(current));
task_pid_vnr(current));
if (i915->display.access.allowed_task) if (i915->display.access.allowed_task)
snprintf(allowed_task, sizeof(allowed_task), "%s[%d]", snprintf(allowed_task, sizeof(allowed_task), "%s[%d]",
get_task_comm(comm, i915->display.access.allowed_task), i915->display.access.allowed_task->comm,
task_pid_vnr(i915->display.access.allowed_task)); task_pid_vnr(i915->display.access.allowed_task));
drm_dbg_kms(&i915->drm, drm_dbg_kms(&i915->drm,

View File

@ -279,7 +279,6 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
const u64 plength = 0x10000; const u64 plength = 0x10000;
const u64 ioffset = plength; const u64 ioffset = plength;
const u64 ilength = 0x02000; const u64 ilength = 0x02000;
char name[TASK_COMM_LEN];
int cid, ret; int cid, ret;
u64 size; u64 size;
@ -338,8 +337,7 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
chan->userd = &chan->user; chan->userd = &chan->user;
} }
get_task_comm(name, current); snprintf(args.name, sizeof(args.name), "%s[%d]", current->comm, task_pid_nr(current));
snprintf(args.name, sizeof(args.name), "%s[%d]", name, task_pid_nr(current));
ret = nvif_object_ctor(&device->object, "abi16ChanUser", 0, hosts[cid].oclass, ret = nvif_object_ctor(&device->object, "abi16ChanUser", 0, hosts[cid].oclass,
&args, sizeof(args), &chan->user); &args, sizeof(args), &chan->user);

View File

@ -1159,7 +1159,7 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
{ {
struct nouveau_drm *drm = nouveau_drm(dev); struct nouveau_drm *drm = nouveau_drm(dev);
struct nouveau_cli *cli; struct nouveau_cli *cli;
char name[32], tmpname[TASK_COMM_LEN]; char name[32];
int ret; int ret;
/* need to bring up power immediately if opening device */ /* need to bring up power immediately if opening device */
@ -1169,10 +1169,9 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
return ret; return ret;
} }
get_task_comm(tmpname, current);
rcu_read_lock(); rcu_read_lock();
snprintf(name, sizeof(name), "%s[%d]", snprintf(name, sizeof(name), "%s[%d]",
tmpname, pid_nr(rcu_dereference(fpriv->pid))); current->comm, pid_nr(rcu_dereference(fpriv->pid)));
rcu_read_unlock(); rcu_read_unlock();
if (!(cli = kzalloc(sizeof(*cli), GFP_KERNEL))) { if (!(cli = kzalloc(sizeof(*cli), GFP_KERNEL))) {

View File

@ -2622,14 +2622,13 @@ static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
static int tty_set_serial(struct tty_struct *tty, struct serial_struct *ss) static int tty_set_serial(struct tty_struct *tty, struct serial_struct *ss)
{ {
char comm[TASK_COMM_LEN];
int flags; int flags;
flags = ss->flags & ASYNC_DEPRECATED; flags = ss->flags & ASYNC_DEPRECATED;
if (flags) if (flags)
pr_warn_ratelimited("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n", pr_warn_ratelimited("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
__func__, get_task_comm(comm, current), flags); __func__, current->comm, flags);
if (!tty->ops->set_serial) if (!tty->ops->set_serial)
return -ENOTTY; return -ENOTTY;