[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171030172034.GN23278@quack2.suse.cz>
Date: Mon, 30 Oct 2017 18:20:34 +0100
From: Jan Kara <jack@...e.cz>
To: Miklos Szeredi <mszeredi@...hat.com>
Cc: linux-fsdevel@...r.kernel.org, Jan Kara <jack@...e.cz>,
Amir Goldstein <amir73il@...il.com>,
Xiong Zhou <xzhou@...hat.com>, linux-kernel@...r.kernel.org
Subject: Re: [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@...hat.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@...e.com>
SUSE Labs, CR
Powered by blists - more mailing lists