Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable

* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: (33 commits)
Btrfs: Fix page count calculation
btrfs: Drop __exit attribute on btrfs_exit_compress
btrfs: cleanup error handling in btrfs_unlink_inode()
Btrfs: exclude super blocks when we read in block groups
Btrfs: make sure search_bitmap finds something in remove_from_bitmap
btrfs: fix return value check of btrfs_start_transaction()
btrfs: checking NULL or not in some functions
Btrfs: avoid uninit variable warnings in ordered-data.c
Btrfs: catch errors from btrfs_sync_log
Btrfs: make shrink_delalloc a little friendlier
Btrfs: handle no memory properly in prepare_pages
Btrfs: do error checking in btrfs_del_csums
Btrfs: use the global block reserve if we cannot reserve space
Btrfs: do not release more reserved bytes to the global_block_rsv than we need
Btrfs: fix check_path_shared so it returns the right value
btrfs: check return value of btrfs_start_ioctl_transaction() properly
btrfs: fix return value check of btrfs_join_transaction()
fs/btrfs/inode.c: Add missing IS_ERR test
btrfs: fix missing break in switch phrase
btrfs: fix several uncheck memory allocations
...

+371 -116
+6
fs/btrfs/acl.c
··· 37 37 char *value = NULL; 38 38 struct posix_acl *acl; 39 39 40 + if (!IS_POSIXACL(inode)) 41 + return NULL; 42 + 40 43 acl = get_cached_acl(inode, type); 41 44 if (acl != ACL_NOT_CACHED) 42 45 return acl; ··· 86 83 { 87 84 struct posix_acl *acl; 88 85 int ret = 0; 86 + 87 + if (!IS_POSIXACL(dentry->d_inode)) 88 + return -EOPNOTSUPP; 89 89 90 90 acl = btrfs_get_acl(dentry->d_inode, type); 91 91
+24 -3
fs/btrfs/compression.c
··· 562 562 u64 em_len; 563 563 u64 em_start; 564 564 struct extent_map *em; 565 - int ret; 565 + int ret = -ENOMEM; 566 566 u32 *sums; 567 567 568 568 tree = &BTRFS_I(inode)->io_tree; ··· 577 577 578 578 compressed_len = em->block_len; 579 579 cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS); 580 + if (!cb) 581 + goto out; 582 + 580 583 atomic_set(&cb->pending_bios, 0); 581 584 cb->errors = 0; 582 585 cb->inode = inode; ··· 600 597 601 598 nr_pages = (compressed_len + PAGE_CACHE_SIZE - 1) / 602 599 PAGE_CACHE_SIZE; 603 - cb->compressed_pages = kmalloc(sizeof(struct page *) * nr_pages, 600 + cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages, 604 601 GFP_NOFS); 602 + if (!cb->compressed_pages) 603 + goto fail1; 604 + 605 605 bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; 606 606 607 607 for (page_index = 0; page_index < nr_pages; page_index++) { 608 608 cb->compressed_pages[page_index] = alloc_page(GFP_NOFS | 609 609 __GFP_HIGHMEM); 610 + if (!cb->compressed_pages[page_index]) 611 + goto fail2; 610 612 } 611 613 cb->nr_pages = nr_pages; 612 614 ··· 622 614 cb->len = uncompressed_len; 623 615 624 616 comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS); 617 + if (!comp_bio) 618 + goto fail2; 625 619 comp_bio->bi_private = cb; 626 620 comp_bio->bi_end_io = end_compressed_bio_read; 627 621 atomic_inc(&cb->pending_bios); ··· 691 681 692 682 bio_put(comp_bio); 693 683 return 0; 684 + 685 + fail2: 686 + for (page_index = 0; page_index < nr_pages; page_index++) 687 + free_page((unsigned long)cb->compressed_pages[page_index]); 688 + 689 + kfree(cb->compressed_pages); 690 + fail1: 691 + kfree(cb); 692 + out: 693 + free_extent_map(em); 694 + return ret; 694 695 } 695 696 696 697 static struct list_head comp_idle_workspace[BTRFS_COMPRESS_TYPES]; ··· 921 900 return ret; 922 901 } 923 902 924 - void __exit btrfs_exit_compress(void) 903 + void btrfs_exit_compress(void) 925 904 { 926 905 free_workspaces(); 927 906 }
+7
fs/btrfs/disk-io.c
··· 1550 1550 spin_unlock(&root->fs_info->new_trans_lock); 1551 1551 1552 1552 trans = btrfs_join_transaction(root, 1); 1553 + BUG_ON(IS_ERR(trans)); 1553 1554 if (transid == trans->transid) { 1554 1555 ret = btrfs_commit_transaction(trans, root); 1555 1556 BUG_ON(ret); ··· 2454 2453 up_write(&root->fs_info->cleanup_work_sem); 2455 2454 2456 2455 trans = btrfs_join_transaction(root, 1); 2456 + if (IS_ERR(trans)) 2457 + return PTR_ERR(trans); 2457 2458 ret = btrfs_commit_transaction(trans, root); 2458 2459 BUG_ON(ret); 2459 2460 /* run commit again to drop the original snapshot */ 2460 2461 trans = btrfs_join_transaction(root, 1); 2462 + if (IS_ERR(trans)) 2463 + return PTR_ERR(trans); 2461 2464 btrfs_commit_transaction(trans, root); 2462 2465 ret = btrfs_write_and_wait_transaction(NULL, root); 2463 2466 BUG_ON(ret); ··· 2559 2554 kfree(fs_info->chunk_root); 2560 2555 kfree(fs_info->dev_root); 2561 2556 kfree(fs_info->csum_root); 2557 + kfree(fs_info); 2558 + 2562 2559 return 0; 2563 2560 } 2564 2561
+2
fs/btrfs/export.c
··· 171 171 int ret; 172 172 173 173 path = btrfs_alloc_path(); 174 + if (!path) 175 + return ERR_PTR(-ENOMEM); 174 176 175 177 if (dir->i_ino == BTRFS_FIRST_FREE_OBJECTID) { 176 178 key.objectid = root->root_key.objectid;
+81 -17
fs/btrfs/extent-tree.c
··· 320 320 if (!path) 321 321 return -ENOMEM; 322 322 323 - exclude_super_stripes(extent_root, block_group); 324 - spin_lock(&block_group->space_info->lock); 325 - block_group->space_info->bytes_readonly += block_group->bytes_super; 326 - spin_unlock(&block_group->space_info->lock); 327 - 328 323 last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET); 329 324 330 325 /* ··· 462 467 cache->cached = BTRFS_CACHE_NO; 463 468 } 464 469 spin_unlock(&cache->lock); 465 - if (ret == 1) 470 + if (ret == 1) { 471 + free_excluded_extents(fs_info->extent_root, cache); 466 472 return 0; 473 + } 467 474 } 468 475 469 476 if (load_cache_only) ··· 3341 3344 u64 reserved; 3342 3345 u64 max_reclaim; 3343 3346 u64 reclaimed = 0; 3347 + long time_left; 3344 3348 int pause = 1; 3345 3349 int nr_pages = (2 * 1024 * 1024) >> PAGE_CACHE_SHIFT; 3350 + int loops = 0; 3346 3351 3347 3352 block_rsv = &root->fs_info->delalloc_block_rsv; 3348 3353 space_info = block_rsv->space_info; ··· 3357 3358 3358 3359 max_reclaim = min(reserved, to_reclaim); 3359 3360 3360 - while (1) { 3361 + while (loops < 1024) { 3361 3362 /* have the flusher threads jump in and do some IO */ 3362 3363 smp_mb(); 3363 3364 nr_pages = min_t(unsigned long, nr_pages, ··· 3365 3366 writeback_inodes_sb_nr_if_idle(root->fs_info->sb, nr_pages); 3366 3367 3367 3368 spin_lock(&space_info->lock); 3368 - if (reserved > space_info->bytes_reserved) 3369 + if (reserved > space_info->bytes_reserved) { 3370 + loops = 0; 3369 3371 reclaimed += reserved - space_info->bytes_reserved; 3372 + } else { 3373 + loops++; 3374 + } 3370 3375 reserved = space_info->bytes_reserved; 3371 3376 spin_unlock(&space_info->lock); 3372 3377 ··· 3381 3378 return -EAGAIN; 3382 3379 3383 3380 __set_current_state(TASK_INTERRUPTIBLE); 3384 - schedule_timeout(pause); 3381 + time_left = schedule_timeout(pause); 3382 + 3383 + /* We were interrupted, exit */ 3384 + if (time_left) 3385 + break; 3386 + 3385 3387 pause <<= 1; 3386 3388 if (pause > HZ / 10) 3387 3389 pause = HZ / 10; ··· 3596 3588 3597 3589 if (num_bytes > 0) { 3598 3590 if (dest) { 3599 - block_rsv_add_bytes(dest, num_bytes, 0); 3600 - } else { 3591 + spin_lock(&dest->lock); 3592 + if (!dest->full) { 3593 + u64 bytes_to_add; 3594 + 3595 + bytes_to_add = dest->size - dest->reserved; 3596 + bytes_to_add = min(num_bytes, bytes_to_add); 3597 + dest->reserved += bytes_to_add; 3598 + if (dest->reserved >= dest->size) 3599 + dest->full = 1; 3600 + num_bytes -= bytes_to_add; 3601 + } 3602 + spin_unlock(&dest->lock); 3603 + } 3604 + if (num_bytes) { 3601 3605 spin_lock(&space_info->lock); 3602 3606 space_info->bytes_reserved -= num_bytes; 3603 3607 spin_unlock(&space_info->lock); ··· 4032 4012 4033 4013 num_bytes = ALIGN(num_bytes, root->sectorsize); 4034 4014 atomic_dec(&BTRFS_I(inode)->outstanding_extents); 4015 + WARN_ON(atomic_read(&BTRFS_I(inode)->outstanding_extents) < 0); 4035 4016 4036 4017 spin_lock(&BTRFS_I(inode)->accounting_lock); 4037 4018 nr_extents = atomic_read(&BTRFS_I(inode)->outstanding_extents); ··· 5654 5633 struct btrfs_root *root, u32 blocksize) 5655 5634 { 5656 5635 struct btrfs_block_rsv *block_rsv; 5636 + struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; 5657 5637 int ret; 5658 5638 5659 5639 block_rsv = get_block_rsv(trans, root); ··· 5662 5640 if (block_rsv->size == 0) { 5663 5641 ret = reserve_metadata_bytes(trans, root, block_rsv, 5664 5642 blocksize, 0); 5665 - if (ret) 5643 + /* 5644 + * If we couldn't reserve metadata bytes try and use some from 5645 + * the global reserve. 5646 + */ 5647 + if (ret && block_rsv != global_rsv) { 5648 + ret = block_rsv_use_bytes(global_rsv, blocksize); 5649 + if (!ret) 5650 + return global_rsv; 5666 5651 return ERR_PTR(ret); 5652 + } else if (ret) { 5653 + return ERR_PTR(ret); 5654 + } 5667 5655 return block_rsv; 5668 5656 } 5669 5657 5670 5658 ret = block_rsv_use_bytes(block_rsv, blocksize); 5671 5659 if (!ret) 5672 5660 return block_rsv; 5661 + if (ret) { 5662 + WARN_ON(1); 5663 + ret = reserve_metadata_bytes(trans, root, block_rsv, blocksize, 5664 + 0); 5665 + if (!ret) { 5666 + spin_lock(&block_rsv->lock); 5667 + block_rsv->size += blocksize; 5668 + spin_unlock(&block_rsv->lock); 5669 + return block_rsv; 5670 + } else if (ret && block_rsv != global_rsv) { 5671 + ret = block_rsv_use_bytes(global_rsv, blocksize); 5672 + if (!ret) 5673 + return global_rsv; 5674 + } 5675 + } 5673 5676 5674 5677 return ERR_PTR(-ENOSPC); 5675 5678 } ··· 6268 6221 BUG_ON(!wc); 6269 6222 6270 6223 trans = btrfs_start_transaction(tree_root, 0); 6224 + BUG_ON(IS_ERR(trans)); 6225 + 6271 6226 if (block_rsv) 6272 6227 trans->block_rsv = block_rsv; 6273 6228 ··· 6367 6318 6368 6319 btrfs_end_transaction_throttle(trans, tree_root); 6369 6320 trans = btrfs_start_transaction(tree_root, 0); 6321 + BUG_ON(IS_ERR(trans)); 6370 6322 if (block_rsv) 6371 6323 trans->block_rsv = block_rsv; 6372 6324 } ··· 6496 6446 int ret = 0; 6497 6447 6498 6448 ra = kzalloc(sizeof(*ra), GFP_NOFS); 6449 + if (!ra) 6450 + return -ENOMEM; 6499 6451 6500 6452 mutex_lock(&inode->i_mutex); 6501 6453 first_index = start >> PAGE_CACHE_SHIFT; ··· 7529 7477 BUG_ON(reloc_root->commit_root != NULL); 7530 7478 while (1) { 7531 7479 trans = btrfs_join_transaction(root, 1); 7532 - BUG_ON(!trans); 7480 + BUG_ON(IS_ERR(trans)); 7533 7481 7534 7482 mutex_lock(&root->fs_info->drop_mutex); 7535 7483 ret = btrfs_drop_snapshot(trans, reloc_root); ··· 7587 7535 7588 7536 if (found) { 7589 7537 trans = btrfs_start_transaction(root, 1); 7590 - BUG_ON(!trans); 7538 + BUG_ON(IS_ERR(trans)); 7591 7539 ret = btrfs_commit_transaction(trans, root); 7592 7540 BUG_ON(ret); 7593 7541 } ··· 7831 7779 7832 7780 7833 7781 trans = btrfs_start_transaction(extent_root, 1); 7834 - BUG_ON(!trans); 7782 + BUG_ON(IS_ERR(trans)); 7835 7783 7836 7784 if (extent_key->objectid == 0) { 7837 7785 ret = del_extent_zero(trans, extent_root, path, extent_key); ··· 8322 8270 if (block_group->cached == BTRFS_CACHE_STARTED) 8323 8271 wait_block_group_cache_done(block_group); 8324 8272 8273 + /* 8274 + * We haven't cached this block group, which means we could 8275 + * possibly have excluded extents on this block group. 8276 + */ 8277 + if (block_group->cached == BTRFS_CACHE_NO) 8278 + free_excluded_extents(info->extent_root, block_group); 8279 + 8325 8280 btrfs_remove_free_space_cache(block_group); 8326 8281 btrfs_put_block_group(block_group); 8327 8282 ··· 8444 8385 cache->sectorsize = root->sectorsize; 8445 8386 8446 8387 /* 8388 + * We need to exclude the super stripes now so that the space 8389 + * info has super bytes accounted for, otherwise we'll think 8390 + * we have more space than we actually do. 8391 + */ 8392 + exclude_super_stripes(root, cache); 8393 + 8394 + /* 8447 8395 * check for two cases, either we are full, and therefore 8448 8396 * don't need to bother with the caching work since we won't 8449 8397 * find any space, or we are empty, and we can just add all ··· 8458 8392 * time, particularly in the full case. 8459 8393 */ 8460 8394 if (found_key.offset == btrfs_block_group_used(&cache->item)) { 8461 - exclude_super_stripes(root, cache); 8462 8395 cache->last_byte_to_unpin = (u64)-1; 8463 8396 cache->cached = BTRFS_CACHE_FINISHED; 8464 8397 free_excluded_extents(root, cache); 8465 8398 } else if (btrfs_block_group_used(&cache->item) == 0) { 8466 - exclude_super_stripes(root, cache); 8467 8399 cache->last_byte_to_unpin = (u64)-1; 8468 8400 cache->cached = BTRFS_CACHE_FINISHED; 8469 8401 add_new_free_space(cache, root->fs_info,
+4 -2
fs/btrfs/extent_io.c
··· 1865 1865 bio_get(bio); 1866 1866 1867 1867 if (tree->ops && tree->ops->submit_bio_hook) 1868 - tree->ops->submit_bio_hook(page->mapping->host, rw, bio, 1868 + ret = tree->ops->submit_bio_hook(page->mapping->host, rw, bio, 1869 1869 mirror_num, bio_flags, start); 1870 1870 else 1871 1871 submit_bio(rw, bio); ··· 1920 1920 nr = bio_get_nr_vecs(bdev); 1921 1921 1922 1922 bio = btrfs_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH); 1923 + if (!bio) 1924 + return -ENOMEM; 1923 1925 1924 1926 bio_add_page(bio, page, page_size, offset); 1925 1927 bio->bi_end_io = end_io_func; ··· 2128 2126 ret = __extent_read_full_page(tree, page, get_extent, &bio, 0, 2129 2127 &bio_flags); 2130 2128 if (bio) 2131 - submit_one_bio(READ, bio, 0, bio_flags); 2129 + ret = submit_one_bio(READ, bio, 0, bio_flags); 2132 2130 return ret; 2133 2131 } 2134 2132
+5
fs/btrfs/file-item.c
··· 536 536 root = root->fs_info->csum_root; 537 537 538 538 path = btrfs_alloc_path(); 539 + if (!path) 540 + return -ENOMEM; 539 541 540 542 while (1) { 541 543 key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; ··· 550 548 if (path->slots[0] == 0) 551 549 goto out; 552 550 path->slots[0]--; 551 + } else if (ret < 0) { 552 + goto out; 553 553 } 554 + 554 555 leaf = path->nodes[0]; 555 556 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 556 557
+14 -6
fs/btrfs/file.c
··· 793 793 for (i = 0; i < num_pages; i++) { 794 794 pages[i] = grab_cache_page(inode->i_mapping, index + i); 795 795 if (!pages[i]) { 796 - err = -ENOMEM; 797 - BUG_ON(1); 796 + int c; 797 + for (c = i - 1; c >= 0; c--) { 798 + unlock_page(pages[c]); 799 + page_cache_release(pages[c]); 800 + } 801 + return -ENOMEM; 798 802 } 799 803 wait_on_page_writeback(pages[i]); 800 804 } ··· 950 946 PAGE_CACHE_SIZE, PAGE_CACHE_SIZE / 951 947 (sizeof(struct page *))); 952 948 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); 949 + if (!pages) { 950 + ret = -ENOMEM; 951 + goto out; 952 + } 953 953 954 954 /* generic_write_checks can change our pos */ 955 955 start_pos = pos; ··· 992 984 size_t write_bytes = min(iov_iter_count(&i), 993 985 nrptrs * (size_t)PAGE_CACHE_SIZE - 994 986 offset); 995 - size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >> 996 - PAGE_CACHE_SHIFT; 987 + size_t num_pages = (write_bytes + offset + 988 + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 997 989 998 990 WARN_ON(num_pages > nrptrs); 999 991 memset(pages, 0, sizeof(struct page *) * nrptrs); ··· 1023 1015 1024 1016 copied = btrfs_copy_from_user(pos, num_pages, 1025 1017 write_bytes, pages, &i); 1026 - dirty_pages = (copied + PAGE_CACHE_SIZE - 1) >> 1027 - PAGE_CACHE_SHIFT; 1018 + dirty_pages = (copied + offset + PAGE_CACHE_SIZE - 1) >> 1019 + PAGE_CACHE_SHIFT; 1028 1020 1029 1021 if (num_pages > dirty_pages) { 1030 1022 if (copied > 0)
+100 -62
fs/btrfs/free-space-cache.c
··· 987 987 return entry; 988 988 } 989 989 990 - static void unlink_free_space(struct btrfs_block_group_cache *block_group, 991 - struct btrfs_free_space *info) 990 + static inline void 991 + __unlink_free_space(struct btrfs_block_group_cache *block_group, 992 + struct btrfs_free_space *info) 992 993 { 993 994 rb_erase(&info->offset_index, &block_group->free_space_offset); 994 995 block_group->free_extents--; 996 + } 997 + 998 + static void unlink_free_space(struct btrfs_block_group_cache *block_group, 999 + struct btrfs_free_space *info) 1000 + { 1001 + __unlink_free_space(block_group, info); 995 1002 block_group->free_space -= info->bytes; 996 1003 } 997 1004 ··· 1023 1016 u64 max_bytes; 1024 1017 u64 bitmap_bytes; 1025 1018 u64 extent_bytes; 1019 + u64 size = block_group->key.offset; 1026 1020 1027 1021 /* 1028 1022 * The goal is to keep the total amount of memory used per 1gb of space 1029 1023 * at or below 32k, so we need to adjust how much memory we allow to be 1030 1024 * used by extent based free space tracking 1031 1025 */ 1032 - max_bytes = MAX_CACHE_BYTES_PER_GIG * 1033 - (div64_u64(block_group->key.offset, 1024 * 1024 * 1024)); 1026 + if (size < 1024 * 1024 * 1024) 1027 + max_bytes = MAX_CACHE_BYTES_PER_GIG; 1028 + else 1029 + max_bytes = MAX_CACHE_BYTES_PER_GIG * 1030 + div64_u64(size, 1024 * 1024 * 1024); 1034 1031 1035 1032 /* 1036 1033 * we want to account for 1 more bitmap than what we have so we can make ··· 1182 1171 recalculate_thresholds(block_group); 1183 1172 } 1184 1173 1174 + static void free_bitmap(struct btrfs_block_group_cache *block_group, 1175 + struct btrfs_free_space *bitmap_info) 1176 + { 1177 + unlink_free_space(block_group, bitmap_info); 1178 + kfree(bitmap_info->bitmap); 1179 + kfree(bitmap_info); 1180 + block_group->total_bitmaps--; 1181 + recalculate_thresholds(block_group); 1182 + } 1183 + 1185 1184 static noinline int remove_from_bitmap(struct btrfs_block_group_cache *block_group, 1186 1185 struct btrfs_free_space *bitmap_info, 1187 1186 u64 *offset, u64 *bytes) ··· 1216 1195 */ 1217 1196 search_start = *offset; 1218 1197 search_bytes = *bytes; 1198 + search_bytes = min(search_bytes, end - search_start + 1); 1219 1199 ret = search_bitmap(block_group, bitmap_info, &search_start, 1220 1200 &search_bytes); 1221 1201 BUG_ON(ret < 0 || search_start != *offset); ··· 1233 1211 1234 1212 if (*bytes) { 1235 1213 struct rb_node *next = rb_next(&bitmap_info->offset_index); 1236 - if (!bitmap_info->bytes) { 1237 - unlink_free_space(block_group, bitmap_info); 1238 - kfree(bitmap_info->bitmap); 1239 - kfree(bitmap_info); 1240 - block_group->total_bitmaps--; 1241 - recalculate_thresholds(block_group); 1242 - } 1214 + if (!bitmap_info->bytes) 1215 + free_bitmap(block_group, bitmap_info); 1243 1216 1244 1217 /* 1245 1218 * no entry after this bitmap, but we still have bytes to ··· 1267 1250 return -EAGAIN; 1268 1251 1269 1252 goto again; 1270 - } else if (!bitmap_info->bytes) { 1271 - unlink_free_space(block_group, bitmap_info); 1272 - kfree(bitmap_info->bitmap); 1273 - kfree(bitmap_info); 1274 - block_group->total_bitmaps--; 1275 - recalculate_thresholds(block_group); 1276 - } 1253 + } else if (!bitmap_info->bytes) 1254 + free_bitmap(block_group, bitmap_info); 1277 1255 1278 1256 return 0; 1279 1257 } ··· 1371 1359 return ret; 1372 1360 } 1373 1361 1374 - int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, 1375 - u64 offset, u64 bytes) 1362 + bool try_merge_free_space(struct btrfs_block_group_cache *block_group, 1363 + struct btrfs_free_space *info, bool update_stat) 1376 1364 { 1377 - struct btrfs_free_space *right_info = NULL; 1378 - struct btrfs_free_space *left_info = NULL; 1379 - struct btrfs_free_space *info = NULL; 1380 - int ret = 0; 1381 - 1382 - info = kzalloc(sizeof(struct btrfs_free_space), GFP_NOFS); 1383 - if (!info) 1384 - return -ENOMEM; 1385 - 1386 - info->offset = offset; 1387 - info->bytes = bytes; 1388 - 1389 - spin_lock(&block_group->tree_lock); 1365 + struct btrfs_free_space *left_info; 1366 + struct btrfs_free_space *right_info; 1367 + bool merged = false; 1368 + u64 offset = info->offset; 1369 + u64 bytes = info->bytes; 1390 1370 1391 1371 /* 1392 1372 * first we want to see if there is free space adjacent to the range we ··· 1392 1388 else 1393 1389 left_info = tree_search_offset(block_group, offset - 1, 0, 0); 1394 1390 1395 - /* 1396 - * If there was no extent directly to the left or right of this new 1397 - * extent then we know we're going to have to allocate a new extent, so 1398 - * before we do that see if we need to drop this into a bitmap 1399 - */ 1400 - if ((!left_info || left_info->bitmap) && 1401 - (!right_info || right_info->bitmap)) { 1402 - ret = insert_into_bitmap(block_group, info); 1403 - 1404 - if (ret < 0) { 1405 - goto out; 1406 - } else if (ret) { 1407 - ret = 0; 1408 - goto out; 1409 - } 1410 - } 1411 - 1412 1391 if (right_info && !right_info->bitmap) { 1413 - unlink_free_space(block_group, right_info); 1392 + if (update_stat) 1393 + unlink_free_space(block_group, right_info); 1394 + else 1395 + __unlink_free_space(block_group, right_info); 1414 1396 info->bytes += right_info->bytes; 1415 1397 kfree(right_info); 1398 + merged = true; 1416 1399 } 1417 1400 1418 1401 if (left_info && !left_info->bitmap && 1419 1402 left_info->offset + left_info->bytes == offset) { 1420 - unlink_free_space(block_group, left_info); 1403 + if (update_stat) 1404 + unlink_free_space(block_group, left_info); 1405 + else 1406 + __unlink_free_space(block_group, left_info); 1421 1407 info->offset = left_info->offset; 1422 1408 info->bytes += left_info->bytes; 1423 1409 kfree(left_info); 1410 + merged = true; 1424 1411 } 1425 1412 1413 + return merged; 1414 + } 1415 + 1416 + int btrfs_add_free_space(struct btrfs_block_group_cache *block_group, 1417 + u64 offset, u64 bytes) 1418 + { 1419 + struct btrfs_free_space *info; 1420 + int ret = 0; 1421 + 1422 + info = kzalloc(sizeof(struct btrfs_free_space), GFP_NOFS); 1423 + if (!info) 1424 + return -ENOMEM; 1425 + 1426 + info->offset = offset; 1427 + info->bytes = bytes; 1428 + 1429 + spin_lock(&block_group->tree_lock); 1430 + 1431 + if (try_merge_free_space(block_group, info, true)) 1432 + goto link; 1433 + 1434 + /* 1435 + * There was no extent directly to the left or right of this new 1436 + * extent then we know we're going to have to allocate a new extent, so 1437 + * before we do that see if we need to drop this into a bitmap 1438 + */ 1439 + ret = insert_into_bitmap(block_group, info); 1440 + if (ret < 0) { 1441 + goto out; 1442 + } else if (ret) { 1443 + ret = 0; 1444 + goto out; 1445 + } 1446 + link: 1426 1447 ret = link_free_space(block_group, info); 1427 1448 if (ret) 1428 1449 kfree(info); ··· 1650 1621 node = rb_next(&entry->offset_index); 1651 1622 rb_erase(&entry->offset_index, &cluster->root); 1652 1623 BUG_ON(entry->bitmap); 1624 + try_merge_free_space(block_group, entry, false); 1653 1625 tree_insert_offset(&block_group->free_space_offset, 1654 1626 entry->offset, &entry->offset_index, 0); 1655 1627 } ··· 1715 1685 ret = offset; 1716 1686 if (entry->bitmap) { 1717 1687 bitmap_clear_bits(block_group, entry, offset, bytes); 1718 - if (!entry->bytes) { 1719 - unlink_free_space(block_group, entry); 1720 - kfree(entry->bitmap); 1721 - kfree(entry); 1722 - block_group->total_bitmaps--; 1723 - recalculate_thresholds(block_group); 1724 - } 1688 + if (!entry->bytes) 1689 + free_bitmap(block_group, entry); 1725 1690 } else { 1726 1691 unlink_free_space(block_group, entry); 1727 1692 entry->offset += bytes; ··· 1814 1789 1815 1790 ret = search_start; 1816 1791 bitmap_clear_bits(block_group, entry, ret, bytes); 1792 + if (entry->bytes == 0) 1793 + free_bitmap(block_group, entry); 1817 1794 out: 1818 1795 spin_unlock(&cluster->lock); 1819 1796 spin_unlock(&block_group->tree_lock); ··· 1869 1842 entry->offset += bytes; 1870 1843 entry->bytes -= bytes; 1871 1844 1872 - if (entry->bytes == 0) { 1845 + if (entry->bytes == 0) 1873 1846 rb_erase(&entry->offset_index, &cluster->root); 1874 - kfree(entry); 1875 - } 1876 1847 break; 1877 1848 } 1878 1849 out: 1879 1850 spin_unlock(&cluster->lock); 1851 + 1852 + if (!ret) 1853 + return 0; 1854 + 1855 + spin_lock(&block_group->tree_lock); 1856 + 1857 + block_group->free_space -= bytes; 1858 + if (entry->bytes == 0) { 1859 + block_group->free_extents--; 1860 + kfree(entry); 1861 + } 1862 + 1863 + spin_unlock(&block_group->tree_lock); 1880 1864 1881 1865 return ret; 1882 1866 }
+23 -12
fs/btrfs/inode.c
··· 416 416 } 417 417 if (start == 0) { 418 418 trans = btrfs_join_transaction(root, 1); 419 - BUG_ON(!trans); 419 + BUG_ON(IS_ERR(trans)); 420 420 btrfs_set_trans_block_group(trans, inode); 421 421 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 422 422 ··· 612 612 GFP_NOFS); 613 613 614 614 trans = btrfs_join_transaction(root, 1); 615 + BUG_ON(IS_ERR(trans)); 615 616 ret = btrfs_reserve_extent(trans, root, 616 617 async_extent->compressed_size, 617 618 async_extent->compressed_size, ··· 772 771 773 772 BUG_ON(root == root->fs_info->tree_root); 774 773 trans = btrfs_join_transaction(root, 1); 775 - BUG_ON(!trans); 774 + BUG_ON(IS_ERR(trans)); 776 775 btrfs_set_trans_block_group(trans, inode); 777 776 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 778 777 ··· 1050 1049 } else { 1051 1050 trans = btrfs_join_transaction(root, 1); 1052 1051 } 1053 - BUG_ON(!trans); 1052 + BUG_ON(IS_ERR(trans)); 1054 1053 1055 1054 cow_start = (u64)-1; 1056 1055 cur_offset = start; ··· 1558 1557 out_page: 1559 1558 unlock_page(page); 1560 1559 page_cache_release(page); 1560 + kfree(fixup); 1561 1561 } 1562 1562 1563 1563 /* ··· 1705 1703 trans = btrfs_join_transaction_nolock(root, 1); 1706 1704 else 1707 1705 trans = btrfs_join_transaction(root, 1); 1708 - BUG_ON(!trans); 1706 + BUG_ON(IS_ERR(trans)); 1709 1707 btrfs_set_trans_block_group(trans, inode); 1710 1708 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1711 1709 ret = btrfs_update_inode(trans, root, inode); ··· 1722 1720 trans = btrfs_join_transaction_nolock(root, 1); 1723 1721 else 1724 1722 trans = btrfs_join_transaction(root, 1); 1723 + BUG_ON(IS_ERR(trans)); 1725 1724 btrfs_set_trans_block_group(trans, inode); 1726 1725 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1727 1726 ··· 2357 2354 */ 2358 2355 if (is_bad_inode(inode)) { 2359 2356 trans = btrfs_start_transaction(root, 0); 2357 + BUG_ON(IS_ERR(trans)); 2360 2358 btrfs_orphan_del(trans, inode); 2361 2359 btrfs_end_transaction(trans, root); 2362 2360 iput(inode); ··· 2385 2381 2386 2382 if (root->orphan_block_rsv || root->orphan_item_inserted) { 2387 2383 trans = btrfs_join_transaction(root, 1); 2384 + BUG_ON(IS_ERR(trans)); 2388 2385 btrfs_end_transaction(trans, root); 2389 2386 } 2390 2387 ··· 2646 2641 path = btrfs_alloc_path(); 2647 2642 if (!path) { 2648 2643 ret = -ENOMEM; 2649 - goto err; 2644 + goto out; 2650 2645 } 2651 2646 2652 2647 path->leave_spinning = 1; ··· 2719 2714 struct extent_buffer *eb; 2720 2715 int level; 2721 2716 u64 refs = 1; 2722 - int uninitialized_var(ret); 2723 2717 2724 2718 for (level = 0; level < BTRFS_MAX_LEVEL; level++) { 2719 + int ret; 2720 + 2725 2721 if (!path->nodes[level]) 2726 2722 break; 2727 2723 eb = path->nodes[level]; ··· 2733 2727 if (refs > 1) 2734 2728 return 1; 2735 2729 } 2736 - return ret; /* XXX callers? */ 2730 + return 0; 2737 2731 } 2738 2732 2739 2733 /* ··· 4140 4134 } 4141 4135 srcu_read_unlock(&root->fs_info->subvol_srcu, index); 4142 4136 4143 - if (root != sub_root) { 4137 + if (!IS_ERR(inode) && root != sub_root) { 4144 4138 down_read(&root->fs_info->cleanup_work_sem); 4145 4139 if (!(inode->i_sb->s_flags & MS_RDONLY)) 4146 4140 btrfs_orphan_cleanup(sub_root); ··· 4353 4347 trans = btrfs_join_transaction_nolock(root, 1); 4354 4348 else 4355 4349 trans = btrfs_join_transaction(root, 1); 4350 + if (IS_ERR(trans)) 4351 + return PTR_ERR(trans); 4356 4352 btrfs_set_trans_block_group(trans, inode); 4357 4353 if (nolock) 4358 4354 ret = btrfs_end_transaction_nolock(trans, root); ··· 4380 4372 return; 4381 4373 4382 4374 trans = btrfs_join_transaction(root, 1); 4375 + BUG_ON(IS_ERR(trans)); 4383 4376 btrfs_set_trans_block_group(trans, inode); 4384 4377 4385 4378 ret = btrfs_update_inode(trans, root, inode); ··· 5185 5176 em = NULL; 5186 5177 btrfs_release_path(root, path); 5187 5178 trans = btrfs_join_transaction(root, 1); 5179 + if (IS_ERR(trans)) 5180 + return ERR_CAST(trans); 5188 5181 goto again; 5189 5182 } 5190 5183 map = kmap(page); ··· 5291 5280 btrfs_drop_extent_cache(inode, start, start + len - 1, 0); 5292 5281 5293 5282 trans = btrfs_join_transaction(root, 0); 5294 - if (!trans) 5295 - return ERR_PTR(-ENOMEM); 5283 + if (IS_ERR(trans)) 5284 + return ERR_CAST(trans); 5296 5285 5297 5286 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 5298 5287 ··· 5516 5505 * while we look for nocow cross refs 5517 5506 */ 5518 5507 trans = btrfs_join_transaction(root, 0); 5519 - if (!trans) 5508 + if (IS_ERR(trans)) 5520 5509 goto must_cow; 5521 5510 5522 5511 if (can_nocow_odirect(trans, inode, start, len) == 1) { ··· 5651 5640 BUG_ON(!ordered); 5652 5641 5653 5642 trans = btrfs_join_transaction(root, 1); 5654 - if (!trans) { 5643 + if (IS_ERR(trans)) { 5655 5644 err = -ENOMEM; 5656 5645 goto out; 5657 5646 }
+14 -5
fs/btrfs/ioctl.c
··· 203 203 204 204 205 205 trans = btrfs_join_transaction(root, 1); 206 - BUG_ON(!trans); 206 + BUG_ON(IS_ERR(trans)); 207 207 208 208 ret = btrfs_update_inode(trans, root, inode); 209 209 BUG_ON(ret); ··· 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 { ··· 1902 1898 1903 1899 memcpy(&new_key, &key, sizeof(new_key)); 1904 1900 new_key.objectid = inode->i_ino; 1905 - new_key.offset = key.offset + destoff - off; 1901 + if (off <= key.offset) 1902 + new_key.offset = key.offset + destoff - off; 1903 + else 1904 + new_key.offset = destoff; 1906 1905 1907 1906 trans = btrfs_start_transaction(root, 1); 1908 1907 if (IS_ERR(trans)) { ··· 2089 2082 2090 2083 ret = -ENOMEM; 2091 2084 trans = btrfs_start_ioctl_transaction(root, 0); 2092 - if (!trans) 2085 + if (IS_ERR(trans)) 2093 2086 goto out_drop; 2094 2087 2095 2088 file->private_data = trans; ··· 2145 2138 path->leave_spinning = 1; 2146 2139 2147 2140 trans = btrfs_start_transaction(root, 1); 2148 - if (!trans) { 2141 + if (IS_ERR(trans)) { 2149 2142 btrfs_free_path(path); 2150 - return -ENOMEM; 2143 + return PTR_ERR(trans); 2151 2144 } 2152 2145 2153 2146 dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); ··· 2341 2334 u64 transid; 2342 2335 2343 2336 trans = btrfs_start_transaction(root, 0); 2337 + if (IS_ERR(trans)) 2338 + return PTR_ERR(trans); 2344 2339 transid = trans->transid; 2345 2340 btrfs_commit_transaction_async(trans, root, 0); 2346 2341
+1 -1
fs/btrfs/ordered-data.c
··· 141 141 u64 file_offset) 142 142 { 143 143 struct rb_root *root = &tree->tree; 144 - struct rb_node *prev; 144 + struct rb_node *prev = NULL; 145 145 struct rb_node *ret; 146 146 struct btrfs_ordered_extent *entry; 147 147
+1
fs/btrfs/print-tree.c
··· 260 260 #else 261 261 BUG(); 262 262 #endif 263 + break; 263 264 case BTRFS_BLOCK_GROUP_ITEM_KEY: 264 265 bi = btrfs_item_ptr(l, i, 265 266 struct btrfs_block_group_item);
+26 -3
fs/btrfs/relocation.c
··· 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, ··· 2148 2147 } 2149 2148 2150 2149 trans = btrfs_join_transaction(rc->extent_root, 1); 2150 + if (IS_ERR(trans)) { 2151 + if (!err) 2152 + btrfs_block_rsv_release(rc->extent_root, 2153 + rc->block_rsv, num_bytes); 2154 + return PTR_ERR(trans); 2155 + } 2151 2156 2152 2157 if (!err) { 2153 2158 if (num_bytes != rc->merging_rsv_size) { ··· 3229 3222 trans = btrfs_join_transaction(root, 0); 3230 3223 if (IS_ERR(trans)) { 3231 3224 btrfs_free_path(path); 3225 + ret = PTR_ERR(trans); 3232 3226 goto out; 3233 3227 } 3234 3228 ··· 3636 3628 set_reloc_control(rc); 3637 3629 3638 3630 trans = btrfs_join_transaction(rc->extent_root, 1); 3631 + BUG_ON(IS_ERR(trans)); 3639 3632 btrfs_commit_transaction(trans, rc->extent_root); 3640 3633 return 0; 3641 3634 } ··· 3666 3657 3667 3658 while (1) { 3668 3659 trans = btrfs_start_transaction(rc->extent_root, 0); 3660 + BUG_ON(IS_ERR(trans)); 3669 3661 3670 3662 if (update_backref_cache(trans, &rc->backref_cache)) { 3671 3663 btrfs_end_transaction(trans, rc->extent_root); ··· 3814 3804 3815 3805 /* get rid of pinned extents */ 3816 3806 trans = btrfs_join_transaction(rc->extent_root, 1); 3817 - btrfs_commit_transaction(trans, rc->extent_root); 3807 + if (IS_ERR(trans)) 3808 + err = PTR_ERR(trans); 3809 + else 3810 + btrfs_commit_transaction(trans, rc->extent_root); 3818 3811 out_free: 3819 3812 btrfs_free_block_rsv(rc->extent_root, rc->block_rsv); 3820 3813 btrfs_free_path(path); ··· 4035 4022 int ret; 4036 4023 4037 4024 trans = btrfs_start_transaction(root->fs_info->tree_root, 0); 4025 + BUG_ON(IS_ERR(trans)); 4038 4026 4039 4027 memset(&root->root_item.drop_progress, 0, 4040 4028 sizeof(root->root_item.drop_progress)); ··· 4139 4125 set_reloc_control(rc); 4140 4126 4141 4127 trans = btrfs_join_transaction(rc->extent_root, 1); 4128 + if (IS_ERR(trans)) { 4129 + unset_reloc_control(rc); 4130 + err = PTR_ERR(trans); 4131 + goto out_free; 4132 + } 4142 4133 4143 4134 rc->merge_reloc_tree = 1; 4144 4135 ··· 4173 4154 unset_reloc_control(rc); 4174 4155 4175 4156 trans = btrfs_join_transaction(rc->extent_root, 1); 4176 - btrfs_commit_transaction(trans, rc->extent_root); 4177 - out: 4157 + if (IS_ERR(trans)) 4158 + err = PTR_ERR(trans); 4159 + else 4160 + btrfs_commit_transaction(trans, rc->extent_root); 4161 + out_free: 4178 4162 kfree(rc); 4163 + out: 4179 4164 while (!list_empty(&reloc_roots)) { 4180 4165 reloc_root = list_entry(reloc_roots.next, 4181 4166 struct btrfs_root, root_list);
+7 -2
fs/btrfs/super.c
··· 383 383 struct btrfs_fs_devices **fs_devices) 384 384 { 385 385 substring_t args[MAX_OPT_ARGS]; 386 - char *opts, *p; 386 + char *opts, *orig, *p; 387 387 int error = 0; 388 388 int intarg; 389 389 ··· 397 397 opts = kstrdup(options, GFP_KERNEL); 398 398 if (!opts) 399 399 return -ENOMEM; 400 + orig = opts; 400 401 401 402 while ((p = strsep(&opts, ",")) != NULL) { 402 403 int token; ··· 433 432 } 434 433 435 434 out_free_opts: 436 - kfree(opts); 435 + kfree(orig); 437 436 out: 438 437 /* 439 438 * If no subvolume name is specified we use the default one. Allocate ··· 624 623 btrfs_wait_ordered_extents(root, 0, 0); 625 624 626 625 trans = btrfs_start_transaction(root, 0); 626 + if (IS_ERR(trans)) 627 + return PTR_ERR(trans); 627 628 ret = btrfs_commit_transaction(trans, root); 628 629 return ret; 629 630 } ··· 764 761 } 765 762 766 763 btrfs_close_devices(fs_devices); 764 + kfree(fs_info); 765 + kfree(tree_root); 767 766 } else { 768 767 char b[BDEVNAME_SIZE]; 769 768
+5
fs/btrfs/transaction.c
··· 1161 1161 INIT_DELAYED_WORK(&ac->work, do_async_commit); 1162 1162 ac->root = root; 1163 1163 ac->newtrans = btrfs_join_transaction(root, 0); 1164 + if (IS_ERR(ac->newtrans)) { 1165 + int err = PTR_ERR(ac->newtrans); 1166 + kfree(ac); 1167 + return err; 1168 + } 1164 1169 1165 1170 /* take transaction reference */ 1166 1171 mutex_lock(&root->fs_info->trans_mutex);
+34 -1
fs/btrfs/tree-log.c
··· 338 338 } 339 339 dst_copy = kmalloc(item_size, GFP_NOFS); 340 340 src_copy = kmalloc(item_size, GFP_NOFS); 341 + if (!dst_copy || !src_copy) { 342 + btrfs_release_path(root, path); 343 + kfree(dst_copy); 344 + kfree(src_copy); 345 + return -ENOMEM; 346 + } 341 347 342 348 read_extent_buffer(eb, src_copy, src_ptr, item_size); 343 349 ··· 671 665 btrfs_dir_item_key_to_cpu(leaf, di, &location); 672 666 name_len = btrfs_dir_name_len(leaf, di); 673 667 name = kmalloc(name_len, GFP_NOFS); 668 + if (!name) 669 + return -ENOMEM; 670 + 674 671 read_extent_buffer(leaf, name, (unsigned long)(di + 1), name_len); 675 672 btrfs_release_path(root, path); 676 673 ··· 753 744 int match = 0; 754 745 755 746 path = btrfs_alloc_path(); 747 + if (!path) 748 + return -ENOMEM; 749 + 756 750 ret = btrfs_search_slot(NULL, log, key, path, 0, 0); 757 751 if (ret != 0) 758 752 goto out; ··· 979 967 key.offset = (u64)-1; 980 968 981 969 path = btrfs_alloc_path(); 970 + if (!path) 971 + return -ENOMEM; 982 972 983 973 while (1) { 984 974 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ··· 1192 1178 1193 1179 name_len = btrfs_dir_name_len(eb, di); 1194 1180 name = kmalloc(name_len, GFP_NOFS); 1181 + if (!name) 1182 + return -ENOMEM; 1183 + 1195 1184 log_type = btrfs_dir_type(eb, di); 1196 1185 read_extent_buffer(eb, name, (unsigned long)(di + 1), 1197 1186 name_len); ··· 1709 1692 root_owner = btrfs_header_owner(parent); 1710 1693 1711 1694 next = btrfs_find_create_tree_block(root, bytenr, blocksize); 1695 + if (!next) 1696 + return -ENOMEM; 1712 1697 1713 1698 if (*level == 1) { 1714 1699 wc->process_func(root, next, wc, ptr_gen); ··· 2051 2032 wait_log_commit(trans, log_root_tree, 2052 2033 log_root_tree->log_transid); 2053 2034 mutex_unlock(&log_root_tree->log_mutex); 2035 + ret = 0; 2054 2036 goto out; 2055 2037 } 2056 2038 atomic_set(&log_root_tree->log_commit[index2], 1); ··· 2116 2096 smp_mb(); 2117 2097 if (waitqueue_active(&root->log_commit_wait[index1])) 2118 2098 wake_up(&root->log_commit_wait[index1]); 2119 - return 0; 2099 + return ret; 2120 2100 } 2121 2101 2122 2102 static void free_log_tree(struct btrfs_trans_handle *trans, ··· 2214 2194 2215 2195 log = root->log_root; 2216 2196 path = btrfs_alloc_path(); 2197 + if (!path) 2198 + return -ENOMEM; 2199 + 2217 2200 di = btrfs_lookup_dir_item(trans, log, path, dir->i_ino, 2218 2201 name, name_len, -1); 2219 2202 if (IS_ERR(di)) { ··· 2617 2594 2618 2595 ins_data = kmalloc(nr * sizeof(struct btrfs_key) + 2619 2596 nr * sizeof(u32), GFP_NOFS); 2597 + if (!ins_data) 2598 + return -ENOMEM; 2599 + 2620 2600 ins_sizes = (u32 *)ins_data; 2621 2601 ins_keys = (struct btrfs_key *)(ins_data + nr * sizeof(u32)); 2622 2602 ··· 2751 2725 log = root->log_root; 2752 2726 2753 2727 path = btrfs_alloc_path(); 2728 + if (!path) 2729 + return -ENOMEM; 2754 2730 dst_path = btrfs_alloc_path(); 2731 + if (!dst_path) { 2732 + btrfs_free_path(path); 2733 + return -ENOMEM; 2734 + } 2755 2735 2756 2736 min_key.objectid = inode->i_ino; 2757 2737 min_key.type = BTRFS_INODE_ITEM_KEY; ··· 3112 3080 BUG_ON(!path); 3113 3081 3114 3082 trans = btrfs_start_transaction(fs_info->tree_root, 0); 3083 + BUG_ON(IS_ERR(trans)); 3115 3084 3116 3085 wc.trans = trans; 3117 3086 wc.pin = 1;
+17 -2
fs/btrfs/volumes.c
··· 1213 1213 return -ENOMEM; 1214 1214 1215 1215 trans = btrfs_start_transaction(root, 0); 1216 + if (IS_ERR(trans)) { 1217 + btrfs_free_path(path); 1218 + return PTR_ERR(trans); 1219 + } 1216 1220 key.objectid = BTRFS_DEV_ITEMS_OBJECTID; 1217 1221 key.type = BTRFS_DEV_ITEM_KEY; 1218 1222 key.offset = device->devid; ··· 1610 1606 } 1611 1607 1612 1608 trans = btrfs_start_transaction(root, 0); 1609 + if (IS_ERR(trans)) { 1610 + kfree(device); 1611 + ret = PTR_ERR(trans); 1612 + goto error; 1613 + } 1614 + 1613 1615 lock_chunks(root); 1614 1616 1615 1617 device->writeable = 1; ··· 1883 1873 return ret; 1884 1874 1885 1875 trans = btrfs_start_transaction(root, 0); 1886 - BUG_ON(!trans); 1876 + BUG_ON(IS_ERR(trans)); 1887 1877 1888 1878 lock_chunks(root); 1889 1879 ··· 2057 2047 BUG_ON(ret); 2058 2048 2059 2049 trans = btrfs_start_transaction(dev_root, 0); 2060 - BUG_ON(!trans); 2050 + BUG_ON(IS_ERR(trans)); 2061 2051 2062 2052 ret = btrfs_grow_device(trans, device, old_size); 2063 2053 BUG_ON(ret); ··· 2223 2213 2224 2214 /* Shrinking succeeded, else we would be at "done". */ 2225 2215 trans = btrfs_start_transaction(root, 0); 2216 + if (IS_ERR(trans)) { 2217 + ret = PTR_ERR(trans); 2218 + goto done; 2219 + } 2220 + 2226 2221 lock_chunks(root); 2227 2222 2228 2223 device->disk_total_bytes = new_size;