Re: [PATCH v2 7/7] fanotify: clean up CONFIG_FANOTIFY_ACCESS_PERMISSIONS ifdefs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>

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@xxxxxxxx>
SUSE Labs, CR



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux