xfs_bmap_util: use swap macro
PATCH 1/1 xfs_bmap_util: use swap macro
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.
--- fs/xfs/xfs_bmap_util.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
fs/xfs/xfs_bmap_util.c +2 -11
@@ -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;
Signature · 1 line
2.7.4
Quoted 26 lines · Gustavo A. R. Silva
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 <[email protected]>--- fs/xfs/xfs_bmap_util.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)fs/xfs/xfs_bmap_util.c +0
-1@@ -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
fs/xfs/xfs_bmap_util.c xfs_swap_extent_forks( · line 1738
Quoted 10 lines
fs/xfs/xfs_bmap_util.c +1
-5*/ - 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?
Quoted 6 lines
fs/xfs/xfs_bmap_util.c +0
-2@@ -1987,14 +1982,10 @@ xfs_swap_extents(/* Swap the cow forks. */ if (xfs_sb_version_hasreflink (&mp->m_sb)) { -xfs_extnum_t extnum; -
fs/xfs/xfs_bmap_util.c xfs_swap_extents( · line 1991
Quoted 10 lines
fs/xfs/xfs_bmap_util.c +1
-3ASSERT (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
Quoted 7 lines
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Darrick,
Quoted 55 lines · Darrick J. Wong
Quoted 26 lines · Gustavo A. R. Silva
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 <[email protected]>--- fs/xfs/xfs_bmap_util.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)fs/xfs/xfs_bmap_util.c +0
-1@@ -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 fs/xfs/xfs_bmap_util.c xfs_swap_extent_forks( · line 1738
Quoted 10 lines
fs/xfs/xfs_bmap_util.c +1
-5*/ - 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 thedi_nextentsanddi_formatexchange below here too?Quoted 14 lines
fs/xfs/xfs_bmap_util.c +1
-5@@ -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);
Quoted 5 lines
fs/xfs/xfs_bmap_util.c xfs_swap_extents( · line 1991
Quoted 2 lines
fs/xfs/xfs_bmap_util.c +0
-0cowfp = 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