diff mbox

xfs_bmap_util: use swap macro

Message ID 20180709140539.GA17517@embeddedor.com (mailing list archive)
State Superseded
Headers show

Commit Message

Gustavo A. R. Silva July 9, 2018, 2:05 p.m. UTC
Make use of the swap macro and remove some unnecessary variables.
This makes the code easier to read and maintain. Also, reduces the
stack usage.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 fs/xfs/xfs_bmap_util.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Darrick J. Wong July 9, 2018, 4:39 p.m. UTC | #1
On Mon, Jul 09, 2018 at 09:05:39AM -0500, Gustavo A. R. Silva wrote:
> Make use of the swap macro and remove some unnecessary variables.
> This makes the code easier to read and maintain. Also, reduces the
> stack usage.
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  fs/xfs/xfs_bmap_util.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index 83b1e8c..4b0b16f 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -1691,7 +1691,6 @@ xfs_swap_extent_forks(
>  	int			*src_log_flags,
>  	int			*target_log_flags)
>  {
> -	struct xfs_ifork	tempifp, *ifp, *tifp;
>  	xfs_filblks_t		aforkblks = 0;
>  	xfs_filblks_t		taforkblks = 0;
>  	xfs_extnum_t		junk;
> @@ -1733,11 +1732,7 @@ xfs_swap_extent_forks(
>  	/*
>  	 * Swap the data forks of the inodes
>  	 */
> -	ifp = &ip->i_df;
> -	tifp = &tip->i_df;
> -	tempifp = *ifp;		/* struct copy */
> -	*ifp = *tifp;		/* struct copy */
> -	*tifp = tempifp;	/* struct copy */
> +	swap(ip->i_df, tip->i_df);
>  
>  	/*
>  	 * Fix the on-disk inode values

Why not use swap() on the di_nextents and di_format exchange below here
too?

> @@ -1987,14 +1982,10 @@ xfs_swap_extents(
>  
>  	/* Swap the cow forks. */
>  	if (xfs_sb_version_hasreflink(&mp->m_sb)) {
> -		xfs_extnum_t	extnum;
> -
>  		ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS);
>  		ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS);
>  
> -		extnum = ip->i_cnextents;
> -		ip->i_cnextents = tip->i_cnextents;
> -		tip->i_cnextents = extnum;
> +		swap(ip->i_cnextents, tip->i_cnextents);
>  
>  		cowfp = ip->i_cowfp;
>  		ip->i_cowfp = tip->i_cowfp;

Same here -- why not use swap on {ip,tip}->i_cowfp?

--D

> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gustavo A. R. Silva July 9, 2018, 4:42 p.m. UTC | #2
Hi Darrick,

On 07/09/2018 11:39 AM, Darrick J. Wong wrote:
> On Mon, Jul 09, 2018 at 09:05:39AM -0500, Gustavo A. R. Silva wrote:
>> Make use of the swap macro and remove some unnecessary variables.
>> This makes the code easier to read and maintain. Also, reduces the
>> stack usage.
>>
>> This code was detected with the help of Coccinelle.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>  fs/xfs/xfs_bmap_util.c | 13 ++-----------
>>  1 file changed, 2 insertions(+), 11 deletions(-)
>>
>> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
>> index 83b1e8c..4b0b16f 100644
>> --- a/fs/xfs/xfs_bmap_util.c
>> +++ b/fs/xfs/xfs_bmap_util.c
>> @@ -1691,7 +1691,6 @@ xfs_swap_extent_forks(
>>  	int			*src_log_flags,
>>  	int			*target_log_flags)
>>  {
>> -	struct xfs_ifork	tempifp, *ifp, *tifp;
>>  	xfs_filblks_t		aforkblks = 0;
>>  	xfs_filblks_t		taforkblks = 0;
>>  	xfs_extnum_t		junk;
>> @@ -1733,11 +1732,7 @@ xfs_swap_extent_forks(
>>  	/*
>>  	 * Swap the data forks of the inodes
>>  	 */
>> -	ifp = &ip->i_df;
>> -	tifp = &tip->i_df;
>> -	tempifp = *ifp;		/* struct copy */
>> -	*ifp = *tifp;		/* struct copy */
>> -	*tifp = tempifp;	/* struct copy */
>> +	swap(ip->i_df, tip->i_df);
>>  
>>  	/*
>>  	 * Fix the on-disk inode values
> 
> Why not use swap() on the di_nextents and di_format exchange below here
> too?
> 
>> @@ -1987,14 +1982,10 @@ xfs_swap_extents(
>>  
>>  	/* Swap the cow forks. */
>>  	if (xfs_sb_version_hasreflink(&mp->m_sb)) {
>> -		xfs_extnum_t	extnum;
>> -
>>  		ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS);
>>  		ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS);
>>  
>> -		extnum = ip->i_cnextents;
>> -		ip->i_cnextents = tip->i_cnextents;
>> -		tip->i_cnextents = extnum;
>> +		swap(ip->i_cnextents, tip->i_cnextents);
>>  
>>  		cowfp = ip->i_cowfp;
>>  		ip->i_cowfp = tip->i_cowfp;
> 
> Same here -- why not use swap on {ip,tip}->i_cowfp?
> 

Yep. I'll send a new patch shortly.

Thanks for the feedback.
--
Gustavo
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 83b1e8c..4b0b16f 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1691,7 +1691,6 @@  xfs_swap_extent_forks(
 	int			*src_log_flags,
 	int			*target_log_flags)
 {
-	struct xfs_ifork	tempifp, *ifp, *tifp;
 	xfs_filblks_t		aforkblks = 0;
 	xfs_filblks_t		taforkblks = 0;
 	xfs_extnum_t		junk;
@@ -1733,11 +1732,7 @@  xfs_swap_extent_forks(
 	/*
 	 * Swap the data forks of the inodes
 	 */
-	ifp = &ip->i_df;
-	tifp = &tip->i_df;
-	tempifp = *ifp;		/* struct copy */
-	*ifp = *tifp;		/* struct copy */
-	*tifp = tempifp;	/* struct copy */
+	swap(ip->i_df, tip->i_df);
 
 	/*
 	 * Fix the on-disk inode values
@@ -1987,14 +1982,10 @@  xfs_swap_extents(
 
 	/* Swap the cow forks. */
 	if (xfs_sb_version_hasreflink(&mp->m_sb)) {
-		xfs_extnum_t	extnum;
-
 		ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS);
 		ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS);
 
-		extnum = ip->i_cnextents;
-		ip->i_cnextents = tip->i_cnextents;
-		tip->i_cnextents = extnum;
+		swap(ip->i_cnextents, tip->i_cnextents);
 
 		cowfp = ip->i_cowfp;
 		ip->i_cowfp = tip->i_cowfp;