spin_lock_irqsave(lock, flags);
                if (list_empty(list))
                        break;
-               work = list_entry(list->next, struct btrfs_work,
-                                 ordered_list);
+               work = list_first_entry(list, struct btrfs_work, ordered_list);
                if (!test_bit(WORK_DONE_BIT, &work->flags))
                        break;
                /*
 
                return;
 
        while (!list_empty(&node->upper)) {
-               edge = list_entry(node->upper.next, struct btrfs_backref_edge,
-                                 list[LOWER]);
+               edge = list_first_entry(&node->upper, struct btrfs_backref_edge,
+                                       list[LOWER]);
                list_del(&edge->list[LOWER]);
                list_del(&edge->list[UPPER]);
                btrfs_backref_free_edge(cache, edge);
                 * type BTRFS_TREE_BLOCK_REF_KEY
                 */
                ASSERT(list_is_singular(&cur->upper));
-               edge = list_entry(cur->upper.next, struct btrfs_backref_edge,
-                                 list[LOWER]);
+               edge = list_first_entry(&cur->upper, struct btrfs_backref_edge,
+                                       list[LOWER]);
                ASSERT(list_empty(&edge->list[UPPER]));
                exist = edge->node[UPPER];
                /*
 
 
        write_lock(&info->block_group_cache_lock);
        while (!list_empty(&info->caching_block_groups)) {
-               caching_ctl = list_entry(info->caching_block_groups.next,
-                                        struct btrfs_caching_control, list);
+               caching_ctl = list_first_entry(&info->caching_block_groups,
+                                              struct btrfs_caching_control, list);
                list_del(&caching_ctl->list);
                btrfs_put_caching_control(caching_ctl);
        }
        btrfs_release_global_block_rsv(info);
 
        while (!list_empty(&info->space_info)) {
-               space_info = list_entry(info->space_info.next,
-                                       struct btrfs_space_info,
-                                       list);
+               space_info = list_first_entry(&info->space_info,
+                                             struct btrfs_space_info, list);
 
                /*
                 * Do not hide this behind enospc_debug, this is actually
 
        int i;
 
        while (!list_empty(&fs_info->dead_roots)) {
-               gang[0] = list_entry(fs_info->dead_roots.next,
-                                    struct btrfs_root, root_list);
+               gang[0] = list_first_entry(&fs_info->dead_roots,
+                                          struct btrfs_root, root_list);
                list_del(&gang[0]->root_list);
 
                if (test_bit(BTRFS_ROOT_IN_RADIX, &gang[0]->state))
 
        struct extent_state *state;
 
        while (!list_empty(&states)) {
-               state = list_entry(states.next, struct extent_state, leak_list);
+               state = list_first_entry(&states, struct extent_state, leak_list);
                pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n",
                       state->start, state->end, state->state,
                       extent_state_in_tree(state),
 
 
        /* Get the cluster for this block_group if it exists */
        if (block_group && !list_empty(&block_group->cluster_list)) {
-               cluster = list_entry(block_group->cluster_list.next,
-                                    struct btrfs_free_cluster,
-                                    block_group_list);
+               cluster = list_first_entry(&block_group->cluster_list,
+                                          struct btrfs_free_cluster, block_group_list);
        }
 
        if (!node && cluster) {
                struct rb_node *node;
                struct btrfs_free_space *entry;
 
-               cluster = list_entry(block_group->cluster_list.next,
-                                    struct btrfs_free_cluster,
-                                    block_group_list);
+               cluster = list_first_entry(&block_group->cluster_list,
+                                          struct btrfs_free_cluster, block_group_list);
                spin_lock(&cluster->lock);
                node = rb_first(&cluster->root);
                if (!node) {
 
                PAGE_SHIFT;
 
        while (!list_empty(&async_chunk->extents)) {
-               async_extent = list_entry(async_chunk->extents.next,
-                                         struct async_extent, list);
+               async_extent = list_first_entry(&async_chunk->extents,
+                                               struct async_extent, list);
                list_del(&async_extent->list);
                submit_one_async_extent(async_chunk, async_extent, &alloc_hint);
        }
                struct btrfs_inode *inode;
                struct inode *tmp_inode;
 
-               inode = list_entry(splice.next, struct btrfs_inode, delalloc_inodes);
+               inode = list_first_entry(&splice, struct btrfs_inode, delalloc_inodes);
 
                list_move_tail(&inode->delalloc_inodes, &root->delalloc_inodes);
 
 
 
        spin_lock(&table->cache_lock);
        while (!list_empty(&table->stripe_cache)) {
-               rbio = list_entry(table->stripe_cache.next,
-                                 struct btrfs_raid_bio,
-                                 stripe_cache);
+               rbio = list_first_entry(&table->stripe_cache,
+                                       struct btrfs_raid_bio, stripe_cache);
                __remove_rbio_from_cache(rbio);
        }
        spin_unlock(&table->cache_lock);
        list_sort(NULL, &plug->rbio_list, plug_cmp);
 
        while (!list_empty(&plug->rbio_list)) {
-               cur = list_entry(plug->rbio_list.next,
-                                struct btrfs_raid_bio, plug_list);
+               cur = list_first_entry(&plug->rbio_list,
+                                      struct btrfs_raid_bio, plug_list);
                list_del_init(&cur->plug_list);
 
                if (rbio_is_full(cur)) {
 
        int idx = *index;
 
        while (!list_empty(&node->upper)) {
-               edge = list_entry(node->upper.next,
-                                 struct btrfs_backref_edge, list[LOWER]);
+               edge = list_first_entry(&node->upper, struct btrfs_backref_edge,
+                                       list[LOWER]);
                edges[idx++] = edge;
                node = edge->node[UPPER];
        }
                        idx--;
                        continue;
                }
-               edge = list_entry(edge->list[LOWER].next,
-                                 struct btrfs_backref_edge, list[LOWER]);
+               edge = list_first_entry(&edge->list[LOWER], struct btrfs_backref_edge,
+                                       list[LOWER]);
                edges[idx - 1] = edge;
                *index = idx;
                return edge->node[UPPER];
                        struct btrfs_backref_edge *edge;
                        struct btrfs_backref_node *lower;
 
-                       edge = list_entry(cur->lower.next,
-                                       struct btrfs_backref_edge, list[UPPER]);
+                       edge = list_first_entry(&cur->lower, struct btrfs_backref_edge,
+                                               list[UPPER]);
                        list_del(&edge->list[UPPER]);
                        list_del(&edge->list[LOWER]);
                        lower = edge->node[LOWER];
        rc->merge_reloc_tree = true;
 
        while (!list_empty(&rc->reloc_roots)) {
-               reloc_root = list_entry(rc->reloc_roots.next,
-                                       struct btrfs_root, root_list);
+               reloc_root = list_first_entry(&rc->reloc_roots,
+                                             struct btrfs_root, root_list);
                list_del_init(&reloc_root->root_list);
 
                root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
 
        while (!list_empty(&reloc_roots)) {
                found = 1;
-               reloc_root = list_entry(reloc_roots.next,
-                                       struct btrfs_root, root_list);
+               reloc_root = list_first_entry(&reloc_roots, struct btrfs_root, root_list);
 
                root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
                                         false);
                        if (list_empty(&next->upper))
                                break;
 
-                       edge = list_entry(next->upper.next,
-                                       struct btrfs_backref_edge, list[LOWER]);
+                       edge = list_first_entry(&next->upper, struct btrfs_backref_edge,
+                                               list[LOWER]);
                        edges[index++] = edge;
                        next = edge->node[UPPER];
                }
 
        for (level = 0; level < BTRFS_MAX_LEVEL; level++) {
                while (!list_empty(&cache->pending[level])) {
-                       node = list_entry(cache->pending[level].next,
-                                         struct btrfs_backref_node, list);
+                       node = list_first_entry(&cache->pending[level],
+                                               struct btrfs_backref_node, list);
                        list_move_tail(&node->list, &list);
                        BUG_ON(!node->pending);
 
                        if (list_empty(&next->upper))
                                break;
 
-                       edge = list_entry(next->upper.next,
-                                       struct btrfs_backref_edge, list[LOWER]);
+                       edge = list_first_entry(&next->upper, struct btrfs_backref_edge,
+                                               list[LOWER]);
                        edges[index++] = edge;
                        next = edge->node[UPPER];
                }
        rc->merge_reloc_tree = true;
 
        while (!list_empty(&reloc_roots)) {
-               reloc_root = list_entry(reloc_roots.next,
-                                       struct btrfs_root, root_list);
+               reloc_root = list_first_entry(&reloc_roots, struct btrfs_root, root_list);
                list_del(&reloc_root->root_list);
 
                if (btrfs_root_refs(&reloc_root->root_item) == 0) {
 
        while (!list_empty(&list)) {
                struct btrfs_ordered_sum *sums =
-                       list_entry(list.next, struct btrfs_ordered_sum, list);
+                       list_first_entry(&list, struct btrfs_ordered_sum, list);
 
                list_del_init(&sums->list);
 
 
        struct recorded_ref *cur;
 
        while (!list_empty(head)) {
-               cur = list_entry(head->next, struct recorded_ref, list);
+               cur = list_first_entry(head, struct recorded_ref, list);
                recorded_ref_free(cur);
        }
 }
                /*
                 * We have a moved dir. Add the old parent to check_dirs
                 */
-               cur = list_entry(sctx->deleted_refs.next, struct recorded_ref,
-                               list);
+               cur = list_first_entry(&sctx->deleted_refs, struct recorded_ref, list);
                ret = dup_ref(cur, &check_dirs);
                if (ret < 0)
                        goto out;
 
                                struct btrfs_ordered_sum *sums;
                                struct btrfs_root *csum_root;
 
-                               sums = list_entry(ordered_sums.next,
-                                               struct btrfs_ordered_sum,
-                                               list);
+                               sums = list_first_entry(&ordered_sums,
+                                                       struct btrfs_ordered_sum,
+                                                       list);
                                csum_root = btrfs_csum_root(fs_info,
                                                            sums->logical);
                                if (!ret)
        ret = 0;
 
        while (!list_empty(&ordered_sums)) {
-               struct btrfs_ordered_sum *sums = list_entry(ordered_sums.next,
-                                                  struct btrfs_ordered_sum,
-                                                  list);
+               struct btrfs_ordered_sum *sums = list_first_entry(&ordered_sums,
+                                                                 struct btrfs_ordered_sum,
+                                                                 list);
                if (!ret)
                        ret = log_csums(trans, inode, log_root, sums);
                list_del(&sums->list);
        list_sort(NULL, &extents, extent_cmp);
 process:
        while (!list_empty(&extents)) {
-               em = list_entry(extents.next, struct extent_map, list);
+               em = list_first_entry(&extents, struct extent_map, list);
 
                list_del_init(&em->list);
 
 
 
        WARN_ON(fs_devices->opened);
        while (!list_empty(&fs_devices->devices)) {
-               device = list_entry(fs_devices->devices.next,
-                                   struct btrfs_device, dev_list);
+               device = list_first_entry(&fs_devices->devices,
+                                         struct btrfs_device, dev_list);
                list_del(&device->dev_list);
                btrfs_free_device(device);
        }
        struct btrfs_fs_devices *fs_devices;
 
        while (!list_empty(&fs_uuids)) {
-               fs_devices = list_entry(fs_uuids.next,
-                                       struct btrfs_fs_devices, fs_list);
+               fs_devices = list_first_entry(&fs_uuids, struct btrfs_fs_devices,
+                                             fs_list);
                list_del(&fs_devices->fs_list);
                free_fs_devices(fs_devices);
        }