From: Darrick J. Wong Date: Wed, 3 Jul 2024 21:21:42 +0000 (-0700) Subject: xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ed4adc13ca396ffbf103b6ce48da18f9ae3da91e;p=users%2Fhch%2Fxfsprogs.git xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one Only update rcur when we know the final *pcur value. Inspired-by: Christoph Hellwig [djwong: don't leave the caller with a dangling ref] Signed-off-by: Darrick J. Wong --- diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 4b9a8be36..d0a057f5c 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1340,7 +1340,7 @@ xfs_refcount_finish_one( struct xfs_btree_cur **pcur) { struct xfs_mount *mp = tp->t_mountp; - struct xfs_btree_cur *rcur; + struct xfs_btree_cur *rcur = *pcur; struct xfs_buf *agbp = NULL; int error = 0; xfs_agblock_t bno; @@ -1358,7 +1358,6 @@ xfs_refcount_finish_one( * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - rcur = *pcur; if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) { nr_ops = rcur->bc_refc.nr_ops; shape_changes = rcur->bc_refc.shape_changes; @@ -1372,11 +1371,11 @@ xfs_refcount_finish_one( if (error) return error; - rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, ri->ri_pag); + *pcur = rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, + ri->ri_pag); rcur->bc_refc.nr_ops = nr_ops; rcur->bc_refc.shape_changes = shape_changes; } - *pcur = rcur; switch (ri->ri_type) { case XFS_REFCOUNT_INCREASE: