Re: [PATCH 4/7] ecryptfs: combine the two ATTR_SIZE blocks in ecryptfs_setattr

Tyler Hicks <[email protected]> Mon, 6 Apr 2026 00:53:05 -0500
Newsgroups org.kernel.vger.ecryptfs,org.kernel.vger.linux-fsdevel
Message-ID <adNKQTyMdsR8wErw@yaupon>
On 2026-03-31 17:37:25, Christoph Hellwig wrote:
> Simplify the logic in ecryptfs_setattr by combining the two ATTR_SIZE
> blocks.  This initializes lower_ia before the size check, which is
> obviously correct as the size check doesn't look at it.
> 
> Signed-off-by: Christoph Hellwig <[email protected]>

This one looks good to me, as well.

Tyler

> ---
>  fs/ecryptfs/inode.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
> index 57df35a22e9c..7a3da72eb3c6 100644
> --- a/fs/ecryptfs/inode.c
> +++ b/fs/ecryptfs/inode.c
> @@ -934,16 +934,15 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
>  	rc = setattr_prepare(&nop_mnt_idmap, dentry, ia);
>  	if (rc)
>  		goto out;
> -	if (ia->ia_valid & ATTR_SIZE) {
> -		rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size);
> -		if (rc)
> -			goto out;
> -	}
>  
>  	memcpy(&lower_ia, ia, sizeof(lower_ia));
>  	if (ia->ia_valid & ATTR_FILE)
>  		lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
>  	if (ia->ia_valid & ATTR_SIZE) {
> +		rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size);
> +		if (rc)
> +			goto out;
> +
>  		rc = truncate_upper(dentry, ia, &lower_ia);
>  		if (rc < 0)
>  			goto out;
> -- 
> 2.47.3
>