FS_FAN_ERROR must be able to merge events even in the short window after
they've been unqueued but prior to being read. Move the list_empty
check into the merge hooks, such that merge() is always invoked if
existing.
Signed-off-by: Gabriel Krisman Bertazi <redacted>
---
fs/notify/fanotify/fanotify.c | 3 ++-
fs/notify/inotify/inotify_fsnotify.c | 3 +++
fs/notify/notification.c | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index aba06b84da91..769703ef2b9a 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -168,7 +168,8 @@ static int fanotify_merge(struct fsnotify_group *group,
* the event structure we have created in fanotify_handle_event() is the
* one we should check for permission response.
*/
- if (fanotify_is_perm_event(new->mask))
+ if (list_empty(&group->notification_list) ||
+ fanotify_is_perm_event(new->mask))
return 0;
hlist_for_each_entry(old, hlist, merge_list) {diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index a003a64ff8ee..2f357b4933c2 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -52,6 +52,9 @@ static int inotify_merge(struct fsnotify_group *group,
struct list_head *list = &group->notification_list;
struct fsnotify_event *last_event;
+ if (list_empty(list))
+ return 0;
+
last_event = list_entry(list->prev, struct fsnotify_event, list);
return event_compare(last_event, event);
}
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index 0d9ba592d725..1d06e0728a24 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -111,7 +111,7 @@ int fsnotify_add_event(struct fsnotify_group *group,
goto queue;
}
- if (!list_empty(list) && merge) {
+ if (merge) {
ret = merge(group, event);
if (ret) {
spin_unlock(&group->notification_lock);--
2.32.0