Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs-progs: improve error handling in btrfs_split_item() #921

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions kernel-shared/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
u32 nritems;
u32 orig_offset;
struct btrfs_disk_key disk_key;
char *buf;
char *buf = NULL;

leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &orig_key, path->slots[0]);
Expand All @@ -2469,11 +2469,13 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
/* if our item isn't there or got smaller, return now */
if (ret != 0 || item_size != btrfs_item_size(path->nodes[0],
path->slots[0])) {
return -EAGAIN;
ret = -EAGAIN;
goto error;
}

ret = split_leaf(trans, root, &orig_key, path, 0, 0);
BUG_ON(ret);
if (ret < 0)
goto error;

BUG_ON(btrfs_leaf_free_space(leaf) < sizeof(struct btrfs_item));
leaf = path->nodes[0];
Expand All @@ -2484,7 +2486,10 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,


buf = kmalloc(item_size, GFP_NOFS);
BUG_ON(!buf);
if (!buf) {
ret = -ENOMEM;
goto error;
}
read_extent_buffer(leaf, buf, btrfs_item_ptr_offset(leaf,
path->slots[0]), item_size);
slot = path->slots[0] + 1;
Expand Down Expand Up @@ -2530,6 +2535,10 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,
}
kfree(buf);
return ret;
error:
kfree(buf);
btrfs_release_path(path);
return ret;
}

void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)
Expand Down
Loading