After the behavior of '%pD' is changed to print the full path of file, the printing of dentry and struct file name can be simplified. Given the space with proper length would be allocated in vprintk_store(), it is worthy of dropping kmalloc()/kfree() to avoid additional space allocation. Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: linux-fsdevel@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx Signed-off-by: Jia He <justin.he@xxxxxxx> --- fs/coredump.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index 07afb5ddb1c4..88063056a801 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -156,35 +156,17 @@ int cn_esc_printf(struct core_name *cn, const char *fmt, ...) static int cn_print_exe_file(struct core_name *cn, bool name_only) { struct file *exe_file; - char *pathbuf, *path, *ptr; int ret; exe_file = get_mm_exe_file(current->mm); if (!exe_file) return cn_esc_printf(cn, "%s (path unknown)", current->comm); - pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); - if (!pathbuf) { - ret = -ENOMEM; - goto put_exe_file; - } - - path = file_path(exe_file, pathbuf, PATH_MAX); - if (IS_ERR(path)) { - ret = PTR_ERR(path); - goto free_buf; - } - - if (name_only) { - ptr = strrchr(path, '/'); - if (ptr) - path = ptr + 1; - } - ret = cn_esc_printf(cn, "%s", path); + if (name_only) + ret = cn_esc_printf(cn, "%pd", exe_file->f_path.dentry); + else + ret = cn_esc_printf(cn, "%pD", exe_file); -free_buf: - kfree(pathbuf); -put_exe_file: fput(exe_file); return ret; } -- 2.17.1