@@ -1490,7 +1490,8 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root
1490
1490
BUG ();
1491
1491
if (nritems == BTRFS_NODEPTRS_PER_BLOCK (root ))
1492
1492
BUG ();
1493
- if (slot != nritems ) {
1493
+ if (slot < nritems ) {
1494
+ /* shift the items */
1494
1495
memmove_extent_buffer (lower ,
1495
1496
btrfs_node_key_ptr_offset (slot + 1 ),
1496
1497
btrfs_node_key_ptr_offset (slot ),
@@ -2254,7 +2255,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
2254
2255
2255
2256
nritems = btrfs_header_nritems (leaf );
2256
2257
2257
- if (slot != nritems ) {
2258
+ if (slot < nritems ) {
2258
2259
/* shift the items */
2259
2260
memmove_extent_buffer (leaf , btrfs_item_nr_offset (slot + 1 ),
2260
2261
btrfs_item_nr_offset (slot ),
@@ -2505,7 +2506,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
2505
2506
slot = path -> slots [0 ];
2506
2507
BUG_ON (slot < 0 );
2507
2508
2508
- if (slot != nritems ) {
2509
+ if (slot < nritems ) {
2509
2510
unsigned int old_data = btrfs_item_end_nr (leaf , slot );
2510
2511
2511
2512
if (old_data < data_end ) {
@@ -2608,7 +2609,8 @@ int btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path,
2608
2609
int ret = 0 ;
2609
2610
2610
2611
nritems = btrfs_header_nritems (parent );
2611
- if (slot != nritems - 1 ) {
2612
+ if (slot < nritems - 1 ) {
2613
+ /* shift the items */
2612
2614
memmove_extent_buffer (parent ,
2613
2615
btrfs_node_key_ptr_offset (slot ),
2614
2616
btrfs_node_key_ptr_offset (slot + 1 ),
0 commit comments