From: Gustavo A. R. Silva Date: Fri, 5 Oct 2018 02:36:09 +0000 (-0500) Subject: xfs_attr_leaf: use swap macro in xfs_attr3_leaf_rebalance X-Git-Tag: v4.19.0-rc0~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50c8d19173b2bd4df68f692854beb62db4052dcf;p=thirdparty%2Fxfsprogs-dev.git xfs_attr_leaf: use swap macro in xfs_attr3_leaf_rebalance Source kernel commit: 1d5bebbafc73d82e5af003cdd2bf8ee5741cd1df 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 Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 2f2ca06f1..da050abad 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -252,6 +252,13 @@ div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) #define max_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) +/** + * swap - swap values of @a and @b + * @a: first value + * @b: second value + */ +#define swap(a, b) \ + do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) #define __round_mask(x, y) ((__typeof__(x))((y)-1)) #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index abb158b26..30b6990b8 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -1561,17 +1561,10 @@ xfs_attr3_leaf_rebalance( */ swap = 0; if (xfs_attr3_leaf_order(blk1->bp, &ichdr1, blk2->bp, &ichdr2)) { - struct xfs_da_state_blk *tmp_blk; - struct xfs_attr3_icleaf_hdr tmp_ichdr; + swap(blk1, blk2); - tmp_blk = blk1; - blk1 = blk2; - blk2 = tmp_blk; - - /* struct copies to swap them rather than reconverting */ - tmp_ichdr = ichdr1; - ichdr1 = ichdr2; - ichdr2 = tmp_ichdr; + /* swap structures rather than reconverting them */ + swap(ichdr1, ichdr2); leaf1 = blk1->bp->b_addr; leaf2 = blk2->bp->b_addr;