Skip to content

Commit d8aaab4

Browse files
jankaratorvalds
authored andcommitted
fanotify: reorganize loop in fanotify_read()
Swap the error / "read ok" branches in the main loop of fanotify_read(). We will grow the "read ok" part in the next patch and this makes the indentation easier. Also it is more common to have error conditions inside an 'if' instead of the fast path. Signed-off-by: Jan Kara <[email protected]> Cc: Eric Paris <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9573f79 commit d8aaab4

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -275,35 +275,37 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
275275
kevent = get_one_event(group, count);
276276
mutex_unlock(&group->notification_mutex);
277277

278-
if (kevent) {
278+
if (IS_ERR(kevent)) {
279279
ret = PTR_ERR(kevent);
280-
if (IS_ERR(kevent))
280+
break;
281+
}
282+
283+
if (!kevent) {
284+
ret = -EAGAIN;
285+
if (file->f_flags & O_NONBLOCK)
281286
break;
282-
ret = copy_event_to_user(group, kevent, buf);
283-
/*
284-
* Permission events get queued to wait for response.
285-
* Other events can be destroyed now.
286-
*/
287-
if (!(kevent->mask & FAN_ALL_PERM_EVENTS))
288-
fsnotify_destroy_event(group, kevent);
289-
if (ret < 0)
287+
288+
ret = -ERESTARTSYS;
289+
if (signal_pending(current))
290+
break;
291+
292+
if (start != buf)
290293
break;
291-
buf += ret;
292-
count -= ret;
294+
schedule();
293295
continue;
294296
}
295297

296-
ret = -EAGAIN;
297-
if (file->f_flags & O_NONBLOCK)
298-
break;
299-
ret = -ERESTARTSYS;
300-
if (signal_pending(current))
301-
break;
302-
303-
if (start != buf)
298+
ret = copy_event_to_user(group, kevent, buf);
299+
/*
300+
* Permission events get queued to wait for response. Other
301+
* events can be destroyed now.
302+
*/
303+
if (!(kevent->mask & FAN_ALL_PERM_EVENTS))
304+
fsnotify_destroy_event(group, kevent);
305+
if (ret < 0)
304306
break;
305-
306-
schedule();
307+
buf += ret;
308+
count -= ret;
307309
}
308310

309311
finish_wait(&group->notification_waitq, &wait);

0 commit comments

Comments
 (0)