]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: actually check xfs_btree_check_block return in xfs_btree_islastblock
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)
Source kernel commit: 27d9ee577dccec94fb0fc1a14728de64db342f86

Coverity points out that xfs_btree_islastblock doesn't check the return
value of xfs_btree_check_block.  Since the question "Does the cursor
point to the last block in this level?" only makes sense if the caller
previously performed a lookup or seek operation, the block should
already have been checked.

Therefore, check the return value in an ASSERT and turn the whole thing
into a static inline predicate.

Coverity-id: 114069
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_btree.c
libxfs/xfs_btree.h

index 5a04d3bd3a7979f4dca8c4db23320291061813d3..6e051e3c2dce46828c0bc2b1512f6e8214256001 100644 (file)
@@ -711,25 +711,6 @@ xfs_btree_get_bufs(
        return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
 }
 
-/*
- * Check for the cursor referring to the last block at the given level.
- */
-int                                    /* 1=is last block, 0=not last block */
-xfs_btree_islastblock(
-       xfs_btree_cur_t         *cur,   /* btree cursor */
-       int                     level)  /* level to check */
-{
-       struct xfs_btree_block  *block; /* generic btree block pointer */
-       xfs_buf_t               *bp;    /* buffer containing block */
-
-       block = xfs_btree_get_block(cur, level, &bp);
-       xfs_btree_check_block(cur, block, level, bp);
-       if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
-               return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK);
-       else
-               return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
-}
-
 /*
  * Change the cursor to point to the first record at the given level.
  * Other levels are unaffected.
index 301b6ff181f2f2dd32e34c2577c58dce78792227..2e727f23cdc475f6404124c593ee75d8c5caa445 100644 (file)
@@ -317,14 +317,6 @@ xfs_btree_get_bufs(
        xfs_agnumber_t          agno,   /* allocation group number */
        xfs_agblock_t           agbno); /* allocation group block number */
 
-/*
- * Check for the cursor referring to the last block at the given level.
- */
-int                                    /* 1=is last block, 0=not last block */
-xfs_btree_islastblock(
-       xfs_btree_cur_t         *cur,   /* btree cursor */
-       int                     level); /* level to check */
-
 /*
  * Compute first and last byte offsets for the fields given.
  * Interprets the offsets table, which contains struct field offsets.
@@ -524,4 +516,21 @@ int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
                union xfs_btree_irec *high, bool *exists);
 bool xfs_btree_has_more_records(struct xfs_btree_cur *cur);
 
+/* Does this cursor point to the last block in the given level? */
+static inline bool
+xfs_btree_islastblock(
+       xfs_btree_cur_t         *cur,
+       int                     level)
+{
+       struct xfs_btree_block  *block;
+       struct xfs_buf          *bp;
+
+       block = xfs_btree_get_block(cur, level, &bp);
+       ASSERT(block && xfs_btree_check_block(cur, block, level, bp) == 0);
+
+       if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
+               return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK);
+       return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
+}
+
 #endif /* __XFS_BTREE_H__ */