Commit 98d5dc13e7e74b77ca3b4c3cbded9f48d2dbbbb7

Authored by Tsutomu Itoh
Committed by Chris Mason
1 parent 5df6708348

btrfs: fix return value check of btrfs_start_transaction()

The error check of btrfs_start_transaction() is added, and the mistake
of the error check on several places is corrected.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>

Showing 7 changed files with 37 additions and 6 deletions Side-by-side Diff

fs/btrfs/extent-tree.c
... ... @@ -6271,6 +6271,8 @@
6271 6271 BUG_ON(!wc);
6272 6272  
6273 6273 trans = btrfs_start_transaction(tree_root, 0);
  6274 + BUG_ON(IS_ERR(trans));
  6275 +
6274 6276 if (block_rsv)
6275 6277 trans->block_rsv = block_rsv;
6276 6278  
... ... @@ -6368,6 +6370,7 @@
6368 6370  
6369 6371 btrfs_end_transaction_throttle(trans, tree_root);
6370 6372 trans = btrfs_start_transaction(tree_root, 0);
  6373 + BUG_ON(IS_ERR(trans));
6371 6374 if (block_rsv)
6372 6375 trans->block_rsv = block_rsv;
6373 6376 }
... ... @@ -7587,7 +7590,7 @@
7587 7590  
7588 7591 if (found) {
7589 7592 trans = btrfs_start_transaction(root, 1);
7590   - BUG_ON(!trans);
  7593 + BUG_ON(IS_ERR(trans));
7591 7594 ret = btrfs_commit_transaction(trans, root);
7592 7595 BUG_ON(ret);
7593 7596 }
... ... @@ -7831,7 +7834,7 @@
7831 7834  
7832 7835  
7833 7836 trans = btrfs_start_transaction(extent_root, 1);
7834   - BUG_ON(!trans);
  7837 + BUG_ON(IS_ERR(trans));
7835 7838  
7836 7839 if (extent_key->objectid == 0) {
7837 7840 ret = del_extent_zero(trans, extent_root, path, extent_key);
... ... @@ -2357,6 +2357,7 @@
2357 2357 */
2358 2358 if (is_bad_inode(inode)) {
2359 2359 trans = btrfs_start_transaction(root, 0);
  2360 + BUG_ON(IS_ERR(trans));
2360 2361 btrfs_orphan_del(trans, inode);
2361 2362 btrfs_end_transaction(trans, root);
2362 2363 iput(inode);
... ... @@ -907,6 +907,10 @@
907 907  
908 908 if (new_size > old_size) {
909 909 trans = btrfs_start_transaction(root, 0);
  910 + if (IS_ERR(trans)) {
  911 + ret = PTR_ERR(trans);
  912 + goto out_unlock;
  913 + }
910 914 ret = btrfs_grow_device(trans, device, new_size);
911 915 btrfs_commit_transaction(trans, root);
912 916 } else {
913 917  
... ... @@ -2141,9 +2145,9 @@
2141 2145 path->leave_spinning = 1;
2142 2146  
2143 2147 trans = btrfs_start_transaction(root, 1);
2144   - if (!trans) {
  2148 + if (IS_ERR(trans)) {
2145 2149 btrfs_free_path(path);
2146   - return -ENOMEM;
  2150 + return PTR_ERR(trans);
2147 2151 }
2148 2152  
2149 2153 dir_id = btrfs_super_root_dir(&root->fs_info->super_copy);
... ... @@ -2337,6 +2341,8 @@
2337 2341 u64 transid;
2338 2342  
2339 2343 trans = btrfs_start_transaction(root, 0);
  2344 + if (IS_ERR(trans))
  2345 + return PTR_ERR(trans);
2340 2346 transid = trans->transid;
2341 2347 btrfs_commit_transaction_async(trans, root, 0);
2342 2348  
fs/btrfs/relocation.c
... ... @@ -2028,6 +2028,7 @@
2028 2028  
2029 2029 while (1) {
2030 2030 trans = btrfs_start_transaction(root, 0);
  2031 + BUG_ON(IS_ERR(trans));
2031 2032 trans->block_rsv = rc->block_rsv;
2032 2033  
2033 2034 ret = btrfs_block_rsv_check(trans, root, rc->block_rsv,
... ... @@ -3665,6 +3666,7 @@
3665 3666  
3666 3667 while (1) {
3667 3668 trans = btrfs_start_transaction(rc->extent_root, 0);
  3669 + BUG_ON(IS_ERR(trans));
3668 3670  
3669 3671 if (update_backref_cache(trans, &rc->backref_cache)) {
3670 3672 btrfs_end_transaction(trans, rc->extent_root);
... ... @@ -4033,6 +4035,7 @@
4033 4035 int ret;
4034 4036  
4035 4037 trans = btrfs_start_transaction(root->fs_info->tree_root, 0);
  4038 + BUG_ON(IS_ERR(trans));
4036 4039  
4037 4040 memset(&root->root_item.drop_progress, 0,
4038 4041 sizeof(root->root_item.drop_progress));
... ... @@ -623,6 +623,8 @@
623 623 btrfs_wait_ordered_extents(root, 0, 0);
624 624  
625 625 trans = btrfs_start_transaction(root, 0);
  626 + if (IS_ERR(trans))
  627 + return PTR_ERR(trans);
626 628 ret = btrfs_commit_transaction(trans, root);
627 629 return ret;
628 630 }
... ... @@ -3112,6 +3112,7 @@
3112 3112 BUG_ON(!path);
3113 3113  
3114 3114 trans = btrfs_start_transaction(fs_info->tree_root, 0);
  3115 + BUG_ON(IS_ERR(trans));
3115 3116  
3116 3117 wc.trans = trans;
3117 3118 wc.pin = 1;
... ... @@ -1212,6 +1212,10 @@
1212 1212 return -ENOMEM;
1213 1213  
1214 1214 trans = btrfs_start_transaction(root, 0);
  1215 + if (IS_ERR(trans)) {
  1216 + btrfs_free_path(path);
  1217 + return PTR_ERR(trans);
  1218 + }
1215 1219 key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
1216 1220 key.type = BTRFS_DEV_ITEM_KEY;
1217 1221 key.offset = device->devid;
... ... @@ -1604,6 +1608,12 @@
1604 1608 }
1605 1609  
1606 1610 trans = btrfs_start_transaction(root, 0);
  1611 + if (IS_ERR(trans)) {
  1612 + kfree(device);
  1613 + ret = PTR_ERR(trans);
  1614 + goto error;
  1615 + }
  1616 +
1607 1617 lock_chunks(root);
1608 1618  
1609 1619 device->barriers = 1;
... ... @@ -1872,7 +1882,7 @@
1872 1882 return ret;
1873 1883  
1874 1884 trans = btrfs_start_transaction(root, 0);
1875   - BUG_ON(!trans);
  1885 + BUG_ON(IS_ERR(trans));
1876 1886  
1877 1887 lock_chunks(root);
1878 1888  
... ... @@ -2046,7 +2056,7 @@
2046 2056 BUG_ON(ret);
2047 2057  
2048 2058 trans = btrfs_start_transaction(dev_root, 0);
2049   - BUG_ON(!trans);
  2059 + BUG_ON(IS_ERR(trans));
2050 2060  
2051 2061 ret = btrfs_grow_device(trans, device, old_size);
2052 2062 BUG_ON(ret);
... ... @@ -2212,6 +2222,11 @@
2212 2222  
2213 2223 /* Shrinking succeeded, else we would be at "done". */
2214 2224 trans = btrfs_start_transaction(root, 0);
  2225 + if (IS_ERR(trans)) {
  2226 + ret = PTR_ERR(trans);
  2227 + goto done;
  2228 + }
  2229 +
2215 2230 lock_chunks(root);
2216 2231  
2217 2232 device->disk_total_bytes = new_size;