btrfs: simplify extracting delayed node at btrfs_first_delayed_node()
authorFilipe Manana <fdmanana@suse.com>
Thu, 1 May 2025 12:05:10 +0000 (13:05 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:55 +0000 (14:30 +0200)
Instead of grabbing the next pointer from the list and then doing a
list_entry() call, we can simply use list_first_entry(), removing the need
for list_head variable.

Also there's no need to check if the list is empty before attempting to
extract the first element, we can use list_first_entry_or_null(), removing
the need for a special if statement and the 'out' label.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delayed-inode.c

index 206d39e5ce5791fe9c89a168515c5ac8594c899b..a1ac35bc789adcda11b9e21f2e4ab5860b823355 100644 (file)
@@ -216,17 +216,13 @@ static void btrfs_dequeue_delayed_node(struct btrfs_delayed_root *root,
 static struct btrfs_delayed_node *btrfs_first_delayed_node(
                        struct btrfs_delayed_root *delayed_root)
 {
-       struct list_head *p;
-       struct btrfs_delayed_node *node = NULL;
+       struct btrfs_delayed_node *node;
 
        spin_lock(&delayed_root->lock);
-       if (list_empty(&delayed_root->node_list))
-               goto out;
-
-       p = delayed_root->node_list.next;
-       node = list_entry(p, struct btrfs_delayed_node, n_list);
-       refcount_inc(&node->refs);
-out:
+       node = list_first_entry_or_null(&delayed_root->node_list,
+                                       struct btrfs_delayed_node, n_list);
+       if (node)
+               refcount_inc(&node->refs);
        spin_unlock(&delayed_root->lock);
 
        return node;