--- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -718,6 +718,7 @@ static int fanotify_handle_event(struct struct fanotify_event *event; struct fsnotify_event *fsn_event; __kernel_fsid_t fsid = {}; + bool prepared = false; BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS); BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY); @@ -753,7 +754,8 @@ static int fanotify_handle_event(struct * fsnotify_prepare_user_wait() fails if we race with mark * deletion. Just let the operation pass in that case. */ - if (!fsnotify_prepare_user_wait(iter_info)) + prepared = fsnotify_prepare_user_wait(iter_info); + if (!prepared) return 0; } @@ -761,7 +763,7 @@ static int fanotify_handle_event(struct fsid = fanotify_get_fsid(iter_info); /* Racing with mark destruction or creation? */ if (!fsid.val[0] && !fsid.val[1]) - return 0; + goto finish; } event = fanotify_alloc_event(group, mask, data, data_type, dir, @@ -793,7 +795,7 @@ static int fanotify_handle_event(struct iter_info); } finish: - if (fanotify_is_perm_event(mask)) + if (prepared) fsnotify_finish_user_wait(iter_info); return ret;