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

btrfs: use list_first_entry() everywhere

Using the helper makes it a bit more clear that we're accessing the
first list entry.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

+53 -61
+1 -2
fs/btrfs/async-thread.c
··· 219 219 spin_lock_irqsave(lock, flags); 220 220 if (list_empty(list)) 221 221 break; 222 - work = list_entry(list->next, struct btrfs_work, 223 - ordered_list); 222 + work = list_first_entry(list, struct btrfs_work, ordered_list); 224 223 if (!test_bit(WORK_DONE_BIT, &work->flags)) 225 224 break; 226 225 /*
+4 -4
fs/btrfs/backref.c
··· 3134 3134 return; 3135 3135 3136 3136 while (!list_empty(&node->upper)) { 3137 - edge = list_entry(node->upper.next, struct btrfs_backref_edge, 3138 - list[LOWER]); 3137 + edge = list_first_entry(&node->upper, struct btrfs_backref_edge, 3138 + list[LOWER]); 3139 3139 list_del(&edge->list[LOWER]); 3140 3140 list_del(&edge->list[UPPER]); 3141 3141 btrfs_backref_free_edge(cache, edge); ··· 3473 3473 * type BTRFS_TREE_BLOCK_REF_KEY 3474 3474 */ 3475 3475 ASSERT(list_is_singular(&cur->upper)); 3476 - edge = list_entry(cur->upper.next, struct btrfs_backref_edge, 3477 - list[LOWER]); 3476 + edge = list_first_entry(&cur->upper, struct btrfs_backref_edge, 3477 + list[LOWER]); 3478 3478 ASSERT(list_empty(&edge->list[UPPER])); 3479 3479 exist = edge->node[UPPER]; 3480 3480 /*
+4 -5
fs/btrfs/block-group.c
··· 4425 4425 4426 4426 write_lock(&info->block_group_cache_lock); 4427 4427 while (!list_empty(&info->caching_block_groups)) { 4428 - caching_ctl = list_entry(info->caching_block_groups.next, 4429 - struct btrfs_caching_control, list); 4428 + caching_ctl = list_first_entry(&info->caching_block_groups, 4429 + struct btrfs_caching_control, list); 4430 4430 list_del(&caching_ctl->list); 4431 4431 btrfs_put_caching_control(caching_ctl); 4432 4432 } ··· 4497 4497 btrfs_release_global_block_rsv(info); 4498 4498 4499 4499 while (!list_empty(&info->space_info)) { 4500 - space_info = list_entry(info->space_info.next, 4501 - struct btrfs_space_info, 4502 - list); 4500 + space_info = list_first_entry(&info->space_info, 4501 + struct btrfs_space_info, list); 4503 4502 4504 4503 /* 4505 4504 * Do not hide this behind enospc_debug, this is actually
+2 -2
fs/btrfs/disk-io.c
··· 1857 1857 int i; 1858 1858 1859 1859 while (!list_empty(&fs_info->dead_roots)) { 1860 - gang[0] = list_entry(fs_info->dead_roots.next, 1861 - struct btrfs_root, root_list); 1860 + gang[0] = list_first_entry(&fs_info->dead_roots, 1861 + struct btrfs_root, root_list); 1862 1862 list_del(&gang[0]->root_list); 1863 1863 1864 1864 if (test_bit(BTRFS_ROOT_IN_RADIX, &gang[0]->state))
+1 -1
fs/btrfs/extent-io-tree.c
··· 42 42 struct extent_state *state; 43 43 44 44 while (!list_empty(&states)) { 45 - state = list_entry(states.next, struct extent_state, leak_list); 45 + state = list_first_entry(&states, struct extent_state, leak_list); 46 46 pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n", 47 47 state->start, state->end, state->state, 48 48 extent_state_in_tree(state),
+4 -6
fs/btrfs/free-space-cache.c
··· 1080 1080 1081 1081 /* Get the cluster for this block_group if it exists */ 1082 1082 if (block_group && !list_empty(&block_group->cluster_list)) { 1083 - cluster = list_entry(block_group->cluster_list.next, 1084 - struct btrfs_free_cluster, 1085 - block_group_list); 1083 + cluster = list_first_entry(&block_group->cluster_list, 1084 + struct btrfs_free_cluster, block_group_list); 1086 1085 } 1087 1086 1088 1087 if (!node && cluster) { ··· 2341 2342 struct rb_node *node; 2342 2343 struct btrfs_free_space *entry; 2343 2344 2344 - cluster = list_entry(block_group->cluster_list.next, 2345 - struct btrfs_free_cluster, 2346 - block_group_list); 2345 + cluster = list_first_entry(&block_group->cluster_list, 2346 + struct btrfs_free_cluster, block_group_list); 2347 2347 spin_lock(&cluster->lock); 2348 2348 node = rb_first(&cluster->root); 2349 2349 if (!node) {
+3 -3
fs/btrfs/inode.c
··· 1568 1568 PAGE_SHIFT; 1569 1569 1570 1570 while (!list_empty(&async_chunk->extents)) { 1571 - async_extent = list_entry(async_chunk->extents.next, 1572 - struct async_extent, list); 1571 + async_extent = list_first_entry(&async_chunk->extents, 1572 + struct async_extent, list); 1573 1573 list_del(&async_extent->list); 1574 1574 submit_one_async_extent(async_chunk, async_extent, &alloc_hint); 1575 1575 } ··· 8520 8520 struct btrfs_inode *inode; 8521 8521 struct inode *tmp_inode; 8522 8522 8523 - inode = list_entry(splice.next, struct btrfs_inode, delalloc_inodes); 8523 + inode = list_first_entry(&splice, struct btrfs_inode, delalloc_inodes); 8524 8524 8525 8525 list_move_tail(&inode->delalloc_inodes, &root->delalloc_inodes); 8526 8526
+4 -5
fs/btrfs/raid56.c
··· 519 519 520 520 spin_lock(&table->cache_lock); 521 521 while (!list_empty(&table->stripe_cache)) { 522 - rbio = list_entry(table->stripe_cache.next, 523 - struct btrfs_raid_bio, 524 - stripe_cache); 522 + rbio = list_first_entry(&table->stripe_cache, 523 + struct btrfs_raid_bio, stripe_cache); 525 524 __remove_rbio_from_cache(rbio); 526 525 } 527 526 spin_unlock(&table->cache_lock); ··· 1701 1702 list_sort(NULL, &plug->rbio_list, plug_cmp); 1702 1703 1703 1704 while (!list_empty(&plug->rbio_list)) { 1704 - cur = list_entry(plug->rbio_list.next, 1705 - struct btrfs_raid_bio, plug_list); 1705 + cur = list_first_entry(&plug->rbio_list, 1706 + struct btrfs_raid_bio, plug_list); 1706 1707 list_del_init(&cur->plug_list); 1707 1708 1708 1709 if (rbio_is_full(cur)) {
+17 -19
fs/btrfs/relocation.c
··· 196 196 int idx = *index; 197 197 198 198 while (!list_empty(&node->upper)) { 199 - edge = list_entry(node->upper.next, 200 - struct btrfs_backref_edge, list[LOWER]); 199 + edge = list_first_entry(&node->upper, struct btrfs_backref_edge, 200 + list[LOWER]); 201 201 edges[idx++] = edge; 202 202 node = edge->node[UPPER]; 203 203 } ··· 223 223 idx--; 224 224 continue; 225 225 } 226 - edge = list_entry(edge->list[LOWER].next, 227 - struct btrfs_backref_edge, list[LOWER]); 226 + edge = list_first_entry(&edge->list[LOWER], struct btrfs_backref_edge, 227 + list[LOWER]); 228 228 edges[idx - 1] = edge; 229 229 *index = idx; 230 230 return edge->node[UPPER]; ··· 348 348 struct btrfs_backref_edge *edge; 349 349 struct btrfs_backref_node *lower; 350 350 351 - edge = list_entry(cur->lower.next, 352 - struct btrfs_backref_edge, list[UPPER]); 351 + edge = list_first_entry(&cur->lower, struct btrfs_backref_edge, 352 + list[UPPER]); 353 353 list_del(&edge->list[UPPER]); 354 354 list_del(&edge->list[LOWER]); 355 355 lower = edge->node[LOWER]; ··· 1698 1698 rc->merge_reloc_tree = true; 1699 1699 1700 1700 while (!list_empty(&rc->reloc_roots)) { 1701 - reloc_root = list_entry(rc->reloc_roots.next, 1702 - struct btrfs_root, root_list); 1701 + reloc_root = list_first_entry(&rc->reloc_roots, 1702 + struct btrfs_root, root_list); 1703 1703 list_del_init(&reloc_root->root_list); 1704 1704 1705 1705 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, ··· 1814 1814 1815 1815 while (!list_empty(&reloc_roots)) { 1816 1816 found = 1; 1817 - reloc_root = list_entry(reloc_roots.next, 1818 - struct btrfs_root, root_list); 1817 + reloc_root = list_first_entry(&reloc_roots, struct btrfs_root, root_list); 1819 1818 1820 1819 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, 1821 1820 false); ··· 2109 2110 if (list_empty(&next->upper)) 2110 2111 break; 2111 2112 2112 - edge = list_entry(next->upper.next, 2113 - struct btrfs_backref_edge, list[LOWER]); 2113 + edge = list_first_entry(&next->upper, struct btrfs_backref_edge, 2114 + list[LOWER]); 2114 2115 edges[index++] = edge; 2115 2116 next = edge->node[UPPER]; 2116 2117 } ··· 2356 2357 2357 2358 for (level = 0; level < BTRFS_MAX_LEVEL; level++) { 2358 2359 while (!list_empty(&cache->pending[level])) { 2359 - node = list_entry(cache->pending[level].next, 2360 - struct btrfs_backref_node, list); 2360 + node = list_first_entry(&cache->pending[level], 2361 + struct btrfs_backref_node, list); 2361 2362 list_move_tail(&node->list, &list); 2362 2363 BUG_ON(!node->pending); 2363 2364 ··· 2395 2396 if (list_empty(&next->upper)) 2396 2397 break; 2397 2398 2398 - edge = list_entry(next->upper.next, 2399 - struct btrfs_backref_edge, list[LOWER]); 2399 + edge = list_first_entry(&next->upper, struct btrfs_backref_edge, 2400 + list[LOWER]); 2400 2401 edges[index++] = edge; 2401 2402 next = edge->node[UPPER]; 2402 2403 } ··· 4182 4183 rc->merge_reloc_tree = true; 4183 4184 4184 4185 while (!list_empty(&reloc_roots)) { 4185 - reloc_root = list_entry(reloc_roots.next, 4186 - struct btrfs_root, root_list); 4186 + reloc_root = list_first_entry(&reloc_roots, struct btrfs_root, root_list); 4187 4187 list_del(&reloc_root->root_list); 4188 4188 4189 4189 if (btrfs_root_refs(&reloc_root->root_item) == 0) { ··· 4275 4277 4276 4278 while (!list_empty(&list)) { 4277 4279 struct btrfs_ordered_sum *sums = 4278 - list_entry(list.next, struct btrfs_ordered_sum, list); 4280 + list_first_entry(&list, struct btrfs_ordered_sum, list); 4279 4281 4280 4282 list_del_init(&sums->list); 4281 4283
+2 -3
fs/btrfs/send.c
··· 3098 3098 struct recorded_ref *cur; 3099 3099 3100 3100 while (!list_empty(head)) { 3101 - cur = list_entry(head->next, struct recorded_ref, list); 3101 + cur = list_first_entry(head, struct recorded_ref, list); 3102 3102 recorded_ref_free(cur); 3103 3103 } 3104 3104 } ··· 4560 4560 /* 4561 4561 * We have a moved dir. Add the old parent to check_dirs 4562 4562 */ 4563 - cur = list_entry(sctx->deleted_refs.next, struct recorded_ref, 4564 - list); 4563 + cur = list_first_entry(&sctx->deleted_refs, struct recorded_ref, list); 4565 4564 ret = dup_ref(cur, &check_dirs); 4566 4565 if (ret < 0) 4567 4566 goto out;
+7 -7
fs/btrfs/tree-log.c
··· 860 860 struct btrfs_ordered_sum *sums; 861 861 struct btrfs_root *csum_root; 862 862 863 - sums = list_entry(ordered_sums.next, 864 - struct btrfs_ordered_sum, 865 - list); 863 + sums = list_first_entry(&ordered_sums, 864 + struct btrfs_ordered_sum, 865 + list); 866 866 csum_root = btrfs_csum_root(fs_info, 867 867 sums->logical); 868 868 if (!ret) ··· 4667 4667 ret = 0; 4668 4668 4669 4669 while (!list_empty(&ordered_sums)) { 4670 - struct btrfs_ordered_sum *sums = list_entry(ordered_sums.next, 4671 - struct btrfs_ordered_sum, 4672 - list); 4670 + struct btrfs_ordered_sum *sums = list_first_entry(&ordered_sums, 4671 + struct btrfs_ordered_sum, 4672 + list); 4673 4673 if (!ret) 4674 4674 ret = log_csums(trans, inode, log_root, sums); 4675 4675 list_del(&sums->list); ··· 4947 4947 list_sort(NULL, &extents, extent_cmp); 4948 4948 process: 4949 4949 while (!list_empty(&extents)) { 4950 - em = list_entry(extents.next, struct extent_map, list); 4950 + em = list_first_entry(&extents, struct extent_map, list); 4951 4951 4952 4952 list_del_init(&em->list); 4953 4953
+4 -4
fs/btrfs/volumes.c
··· 415 415 416 416 WARN_ON(fs_devices->opened); 417 417 while (!list_empty(&fs_devices->devices)) { 418 - device = list_entry(fs_devices->devices.next, 419 - struct btrfs_device, dev_list); 418 + device = list_first_entry(&fs_devices->devices, 419 + struct btrfs_device, dev_list); 420 420 list_del(&device->dev_list); 421 421 btrfs_free_device(device); 422 422 } ··· 428 428 struct btrfs_fs_devices *fs_devices; 429 429 430 430 while (!list_empty(&fs_uuids)) { 431 - fs_devices = list_entry(fs_uuids.next, 432 - struct btrfs_fs_devices, fs_list); 431 + fs_devices = list_first_entry(&fs_uuids, struct btrfs_fs_devices, 432 + fs_list); 433 433 list_del(&fs_devices->fs_list); 434 434 free_fs_devices(fs_devices); 435 435 }