Skip to content

Commit

Permalink
Btrfs: make sure roots are assigned before freeing their nodes
Browse files Browse the repository at this point in the history
If we fail to load the chunk tree we'll call free_root_pointers, except we may
not have assigned the roots for the dev_root/extent_root/csum_root yet, so we
could NULL pointer deref at this point.  Just add checks to make sure these
roots are set to keep us from panicing.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
  • Loading branch information
Josef Bacik committed May 18, 2013
1 parent 3a6cad9 commit 655b09f
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,30 +1987,33 @@ static void free_root_pointers(struct btrfs_fs_info *info, int chunk_root)
{
free_extent_buffer(info->tree_root->node);
free_extent_buffer(info->tree_root->commit_root);
free_extent_buffer(info->dev_root->node);
free_extent_buffer(info->dev_root->commit_root);
free_extent_buffer(info->extent_root->node);
free_extent_buffer(info->extent_root->commit_root);
free_extent_buffer(info->csum_root->node);
free_extent_buffer(info->csum_root->commit_root);
if (info->quota_root) {
free_extent_buffer(info->quota_root->node);
free_extent_buffer(info->quota_root->commit_root);
}

info->tree_root->node = NULL;
info->tree_root->commit_root = NULL;
info->dev_root->node = NULL;
info->dev_root->commit_root = NULL;
info->extent_root->node = NULL;
info->extent_root->commit_root = NULL;
info->csum_root->node = NULL;
info->csum_root->commit_root = NULL;

if (info->dev_root) {
free_extent_buffer(info->dev_root->node);
free_extent_buffer(info->dev_root->commit_root);
info->dev_root->node = NULL;
info->dev_root->commit_root = NULL;
}
if (info->extent_root) {
free_extent_buffer(info->extent_root->node);
free_extent_buffer(info->extent_root->commit_root);
info->extent_root->node = NULL;
info->extent_root->commit_root = NULL;
}
if (info->csum_root) {
free_extent_buffer(info->csum_root->node);
free_extent_buffer(info->csum_root->commit_root);
info->csum_root->node = NULL;
info->csum_root->commit_root = NULL;
}
if (info->quota_root) {
free_extent_buffer(info->quota_root->node);
free_extent_buffer(info->quota_root->commit_root);
info->quota_root->node = NULL;
info->quota_root->commit_root = NULL;
}

if (chunk_root) {
free_extent_buffer(info->chunk_root->node);
free_extent_buffer(info->chunk_root->commit_root);
Expand Down

0 comments on commit 655b09f

Please sign in to comment.