Skip to contentSkip to conversation

btrfs: push btrfs_grab_fs_root into btrfs_get_fs_root

bug report Dan Carpenter 1 participant 1 message May 23, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hello Josef Bacik,

The patch bc44d7c4b2b1: "btrfs: push btrfs_grab_fs_root into btrfs_get_fs_root" from Jan 24, 2020, leads to the following static checker warning:

fs/btrfs/backref.c:565 resolve_indirect_ref()
warn: 'root' can also be NULL

fs/btrfs/backref.c
1537 struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info,
1538 u64 objectid, bool check_ref)
1539 {

  1540          struct btrfs_root *root;
  1541          struct btrfs_path *path;
  1542          struct btrfs_key key;
  1543          int ret;
  1544  
  1545          if (objectid == BTRFS_ROOT_TREE_OBJECTID)
  1546                  return btrfs_grab_root(fs_info->tree_root);
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1547          if (objectid == BTRFS_EXTENT_TREE_OBJECTID)
  1548                  return btrfs_grab_root(fs_info->extent_root);
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

These return NULL on error and it leads to an OOps in the caller.

  1549          if (objectid == BTRFS_CHUNK_TREE_OBJECTID)
  1550                  return btrfs_grab_root(fs_info->chunk_root);
  1551          if (objectid == BTRFS_DEV_TREE_OBJECTID)
  1552                  return btrfs_grab_root(fs_info->dev_root);
  1553          if (objectid == BTRFS_CSUM_TREE_OBJECTID)
  1554                  return btrfs_grab_root(fs_info->csum_root);
  1555          if (objectid == BTRFS_QUOTA_TREE_OBJECTID)
  1556                  return btrfs_grab_root(fs_info->quota_root) ?
  1557                          fs_info->quota_root : ERR_PTR(-ENOENT);

It should probably return ERR_PTR(-ENOENT).

1558 if (objectid == BTRFS_UUID_TREE_OBJECTID)
1559 return btrfs_grab_root(fs_info->uuid_root) ?
1560 fs_info->uuid_root : ERR_PTR(-ENOENT);
1561 if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID)
1562 return btrfs_grab_root(fs_info->free_space_root) ?
1563 fs_info->free_space_root : ERR_PTR(-ENOENT);
1564 again:

regards,
dan carpenter