Skip to content

Commit e109dea

Browse files
committed
eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set
If ei->is_freed is set in eventfs_iterate(), it means that the directory that is being iterated on is in the process of being freed. Just exit the loop immediately when that is ever detected, and separate out the return of the entry->callback() from ei->is_freed. Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.016261289@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 8186fff commit e109dea

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
788788
name = entry->name;
789789

790790
mutex_lock(&eventfs_mutex);
791-
/* If ei->is_freed, then the event itself may be too */
792-
if (!ei->is_freed)
793-
r = entry->callback(name, &mode, &cdata, &fops);
794-
else
795-
r = -1;
791+
/* If ei->is_freed then just bail here, nothing more to do */
792+
if (ei->is_freed) {
793+
mutex_unlock(&eventfs_mutex);
794+
goto out;
795+
}
796+
r = entry->callback(name, &mode, &cdata, &fops);
796797
mutex_unlock(&eventfs_mutex);
797798
if (r <= 0)
798799
continue;

0 commit comments

Comments
 (0)