From: Darrick J. Wong <djwong@xxxxxxxxxx> Source kernel commit: 4c175af2ccd3e0d618b2af941e656fabc453c4af Warn if we ever bump nlevels higher than the allowed maximum cursor height. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> Reviewed-by: Chandan Babu R <chandan.babu@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- libxfs/xfs_btree.c | 2 ++ libxfs/xfs_btree_staging.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 7097abde..426ab7f8 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -2934,6 +2934,7 @@ xfs_btree_new_iroot( be16_add_cpu(&block->bb_level, 1); xfs_btree_set_numrecs(block, 1); cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); cur->bc_ptrs[level + 1] = 1; kp = xfs_btree_key_addr(cur, 1, block); @@ -3097,6 +3098,7 @@ xfs_btree_new_root( xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); cur->bc_ptrs[cur->bc_nlevels] = nptr; cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); *stat = 1; return 0; error0: diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index daf99797..aa3d49cf 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -703,6 +703,7 @@ xfs_btree_bload_compute_geometry( * block-based btree level. */ cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); xfs_btree_bload_level_geometry(cur, bbl, level, nr_this_level, &avg_per_block, &level_blocks, &dontcare64); @@ -718,6 +719,7 @@ xfs_btree_bload_compute_geometry( /* Otherwise, we need another level of btree. */ cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); } nr_blocks += level_blocks;