Re: [RFC PATCH] fs: introduce check for drop/inc_nlink

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

 



On Fri, Oct 13, 2023 at 03:27:30PM +0800, cheng.lin130@xxxxxxxxxx wrote:
> From: Cheng Lin <cheng.lin130@xxxxxxxxxx>
> 
> Avoid inode nlink overflow or underflow.
> 
> Signed-off-by: Cheng Lin <cheng.lin130@xxxxxxxxxx>
> ---

I'm very confused. There's no explanation why that's needed. As it
stands it's not possible to provide a useful review.

I'm not saying it's wrong. I just don't understand why and even if this
should please show up in the commit message.

>  fs/inode.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 67611a360..8e6d62dc4 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -328,6 +328,9 @@ static void destroy_inode(struct inode *inode)
>  void drop_nlink(struct inode *inode)
>  {
>  	WARN_ON(inode->i_nlink == 0);
> +	if (unlikely(inode->i_nlink == 0))
> +		return;
> +
>  	inode->__i_nlink--;
>  	if (!inode->i_nlink)
>  		atomic_long_inc(&inode->i_sb->s_remove_count);
> @@ -388,6 +391,9 @@ void inc_nlink(struct inode *inode)
>  		atomic_long_dec(&inode->i_sb->s_remove_count);
>  	}
>  
> +	if (unlikely(inode->i_nlink == ~0U))
> +		return;
> +
>  	inode->__i_nlink++;
>  }
>  EXPORT_SYMBOL(inc_nlink);
> -- 
> 2.18.1






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

  Powered by Linux