Skip to content

Commit a741c2f

Browse files
committed
fanotify: Simplify create_fd()
create_fd() is never used with invalid path. Also the only thing it needs to know from fanotify_event is the path. Simplify the function to take path directly and assume it is correct. Signed-off-by: Jan Kara <[email protected]>
1 parent 55bf882 commit a741c2f

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,12 @@ static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
9696
return fsn_event;
9797
}
9898

99-
static int create_fd(struct fsnotify_group *group,
100-
struct fanotify_event *event,
99+
static int create_fd(struct fsnotify_group *group, struct path *path,
101100
struct file **file)
102101
{
103102
int client_fd;
104103
struct file *new_file;
105104

106-
pr_debug("%s: group=%p event=%p\n", __func__, group, event);
107-
108105
client_fd = get_unused_fd_flags(group->fanotify_data.f_flags);
109106
if (client_fd < 0)
110107
return client_fd;
@@ -113,14 +110,9 @@ static int create_fd(struct fsnotify_group *group,
113110
* we need a new file handle for the userspace program so it can read even if it was
114111
* originally opened O_WRONLY.
115112
*/
116-
/* it's possible this event was an overflow event. in that case dentry and mnt
117-
* are NULL; That's fine, just don't call dentry open */
118-
if (event->path.dentry && event->path.mnt)
119-
new_file = dentry_open(&event->path,
120-
group->fanotify_data.f_flags | FMODE_NONOTIFY,
121-
current_cred());
122-
else
123-
new_file = ERR_PTR(-EOVERFLOW);
113+
new_file = dentry_open(path,
114+
group->fanotify_data.f_flags | FMODE_NONOTIFY,
115+
current_cred());
124116
if (IS_ERR(new_file)) {
125117
/*
126118
* we still send an event even if we can't open the file. this
@@ -276,9 +268,13 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
276268
metadata.pid = pid_vnr(event->pid);
277269

278270
if (fanotify_event_has_path(event)) {
279-
fd = create_fd(group, event, &f);
280-
if (fd < 0)
281-
return fd;
271+
struct path *path = &event->path;
272+
273+
if (path->mnt && path->dentry) {
274+
fd = create_fd(group, path, &f);
275+
if (fd < 0)
276+
return fd;
277+
}
282278
} else if (fanotify_event_has_fid(event)) {
283279
metadata.event_len += fanotify_event_info_len(event);
284280
}

0 commit comments

Comments
 (0)