lkml.org 
[lkml]   [2017]   [Oct]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 7/7] fanotify: clean up CONFIG_FANOTIFY_ACCESS_PERMISSIONS ifdefs
On Wed 25-10-17 10:41:39, Miklos Szeredi wrote:
> The only negative from this patch should be an addition of 32bytes to
> 'struct fsnotify_group' if CONFIG_FANOTIFY_ACCESS_PERMISSIONS is not
> defined.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

I like this but some comments below.

> @@ -338,11 +332,14 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
>
> static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
> {
> -#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
> struct fanotify_response response = { .fd = -1, .response = -1 };
> struct fsnotify_group *group;
> int ret;
>
> + if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
> + return -EINVAL;
> +
> +

Two empty lines here look superfluous.

> @@ -358,59 +355,57 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
> count = ret;
>
> return count;
> -#else
> - return -EINVAL;
> -#endif
> }
>
> static int fanotify_release(struct inode *ignored, struct file *file)
> {
> struct fsnotify_group *group = file->private_data;
>
> -#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
> - struct fanotify_perm_event_info *event, *next;
> - struct fsnotify_event *fsn_event;
> + if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
> + struct fanotify_perm_event_info *event, *next;
> + struct fsnotify_event *fsn_event;

Rather than doing this, I'd just let fanotify_release() go through the same
path for both CONFIG_FANOTIFY_ACCESS_PERMISSIONS enabled and disabled.
Enabled path won't be much more expensive since access_list will be empty
and we have to walk & destroy events anyway. That way you also don't have
to reindent everything.

> @@ -768,10 +763,10 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
> if (force_o_largefile())
> event_f_flags |= O_LARGEFILE;
> group->fanotify_data.f_flags = event_f_flags;
> -#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
> - init_waitqueue_head(&group->fanotify_data.access_waitq);
> - INIT_LIST_HEAD(&group->fanotify_data.access_list);
> -#endif
> + if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
> + init_waitqueue_head(&group->fanotify_data.access_waitq);
> + INIT_LIST_HEAD(&group->fanotify_data.access_list);
> + }

When having space for these allocated, just initialize them properly.
Otherwise it's asking for trouble.

Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR

\
 
 \ /
  Last update: 2017-10-30 18:21    [W:0.611 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site