]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: prefer IS_ERR_OR_NULL() over manual NULL check
authorPhilipp Hahn <phahn-oss@avm.de>
Tue, 10 Mar 2026 11:48:28 +0000 (12:48 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:56:02 +0000 (18:56 +0200)
Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL
check.

IS_ERR_OR_NULL() already uses likely(!ptr) internally. checkpatch does
not like nesting it:
> WARNING: nested (un)?likely() calls, IS_ERR_OR_NULL already uses
> unlikely() internally
Remove the explicit use of likely().

Change generated with coccinelle.

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c
fs/btrfs/transaction.c
fs/btrfs/tree-log.c
fs/btrfs/uuid-tree.c

index c1abeb72069ca9b0f2bb36238f710fb9819f8b3d..8d97a8ad3858bf9e4d26266d95ef369249843568 100644 (file)
@@ -4691,7 +4691,7 @@ static noinline int may_destroy_subvol(struct btrfs_root *root)
        dir_id = btrfs_super_root_dir(fs_info->super_copy);
        di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
                                   dir_id, &name, 0);
-       if (di && !IS_ERR(di)) {
+       if (!IS_ERR_OR_NULL(di)) {
                btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
                if (key.objectid == btrfs_root_id(root)) {
                        ret = -EPERM;
index 79c488f120b232fe2084d88cb656f67bab953526..4358f4b630572c2d796aa16c05333fe74b4456a3 100644 (file)
@@ -1754,7 +1754,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        dir_item = btrfs_lookup_dir_item(NULL, parent_root, path,
                                         btrfs_ino(parent_inode),
                                         &fname.disk_name, 0);
-       if (unlikely(dir_item != NULL && !IS_ERR(dir_item))) {
+       if (!IS_ERR_OR_NULL(dir_item)) {
                pending->error = -EEXIST;
                goto dir_item_existed;
        } else if (IS_ERR(dir_item)) {
index af8de67d1304bb642d67be462f454a3309fa3c61..a87fdfd465b31defdca5343d141e797a94942b88 100644 (file)
@@ -5801,7 +5801,7 @@ static int btrfs_check_ref_name_override(struct extent_buffer *eb,
                name_str.len = this_name_len;
                di = btrfs_lookup_dir_item(NULL, inode->root, search_path,
                                parent, &name_str, 0);
-               if (di && !IS_ERR(di)) {
+               if (!IS_ERR_OR_NULL(di)) {
                        struct btrfs_key di_key;
 
                        btrfs_dir_item_key_to_cpu(search_path->nodes[0],
index 276f0eb874d4f7646323456b142371c71dc4435f..467dff7212d692ed170cfd20aecbf6df7b876b1b 100644 (file)
@@ -513,7 +513,7 @@ skip:
 
 out:
        btrfs_free_path(path);
-       if (trans && !IS_ERR(trans))
+       if (!IS_ERR_OR_NULL(trans))
                btrfs_end_transaction(trans);
        if (ret)
                btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret);