diff options
author | Filipe Manana <fdmanana@suse.com> | 2015-02-23 14:48:52 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-03-02 17:04:45 -0500 |
commit | 5dfe2be7ead15863fd7b3fcc8bd69e470fae2bec (patch) | |
tree | a0f3398927bcd6e15a7347f741b186eb85cf3fc1 /fs/btrfs | |
parent | e8c1c76e804b18120e6977fc092769c043876212 (diff) |
Btrfs: fix off-by-one logic error in btrfs_realloc_node
The end_slot variable actually matches the number of pointers in the
node and not the last slot (which is 'nritems - 1'). Therefore in order
to check that the current slot in the for loop doesn't match the last
one, the correct logic is to check if 'i' is less than 'end_slot - 1'
and not 'end_slot - 2'.
Fix this and set end_slot to be 'nritems - 1', as it's less confusing
since the variable name implies it's inclusive rather then exclusive.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ctree.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 993642199326..6d67f32e648d 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1645,14 +1645,14 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1645 | 1645 | ||
1646 | parent_nritems = btrfs_header_nritems(parent); | 1646 | parent_nritems = btrfs_header_nritems(parent); |
1647 | blocksize = root->nodesize; | 1647 | blocksize = root->nodesize; |
1648 | end_slot = parent_nritems; | 1648 | end_slot = parent_nritems - 1; |
1649 | 1649 | ||
1650 | if (parent_nritems == 1) | 1650 | if (parent_nritems <= 1) |
1651 | return 0; | 1651 | return 0; |
1652 | 1652 | ||
1653 | btrfs_set_lock_blocking(parent); | 1653 | btrfs_set_lock_blocking(parent); |
1654 | 1654 | ||
1655 | for (i = start_slot; i < end_slot; i++) { | 1655 | for (i = start_slot; i <= end_slot; i++) { |
1656 | int close = 1; | 1656 | int close = 1; |
1657 | 1657 | ||
1658 | btrfs_node_key(parent, &disk_key, i); | 1658 | btrfs_node_key(parent, &disk_key, i); |
@@ -1669,7 +1669,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1669 | other = btrfs_node_blockptr(parent, i - 1); | 1669 | other = btrfs_node_blockptr(parent, i - 1); |
1670 | close = close_blocks(blocknr, other, blocksize); | 1670 | close = close_blocks(blocknr, other, blocksize); |
1671 | } | 1671 | } |
1672 | if (!close && i < end_slot - 2) { | 1672 | if (!close && i < end_slot) { |
1673 | other = btrfs_node_blockptr(parent, i + 1); | 1673 | other = btrfs_node_blockptr(parent, i + 1); |
1674 | close = close_blocks(blocknr, other, blocksize); | 1674 | close = close_blocks(blocknr, other, blocksize); |
1675 | } | 1675 | } |