eventfs: Do not allow NULL parent to eventfs_start_creating()

The eventfs directory is dynamically created via the meta data supplied by
the existing trace events. All files and directories in eventfs has a
parent. Do not allow NULL to be passed into eventfs_start_creating() as
the parent because that should never happen. Warn if it does.

Link: https://lkml.kernel.org/r/20231121231112.693841807@goodmis.org

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Changed files
+4 -9
fs
tracefs
+4 -9
fs/tracefs/inode.c
··· 509 509 struct dentry *dentry; 510 510 int error; 511 511 512 + /* Must always have a parent. */ 513 + if (WARN_ON_ONCE(!parent)) 514 + return ERR_PTR(-EINVAL); 515 + 512 516 error = simple_pin_fs(&trace_fs_type, &tracefs_mount, 513 517 &tracefs_mount_count); 514 518 if (error) 515 519 return ERR_PTR(error); 516 - 517 - /* 518 - * If the parent is not specified, we create it in the root. 519 - * We need the root dentry to do this, which is in the super 520 - * block. A pointer to that is in the struct vfsmount that we 521 - * have around. 522 - */ 523 - if (!parent) 524 - parent = tracefs_mount->mnt_root; 525 520 526 521 if (unlikely(IS_DEADDIR(parent->d_inode))) 527 522 dentry = ERR_PTR(-ENOENT);