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

btrfs: fix passing 0 to ERR_PTR in btrfs_search_dir_index_item()

The ret may be zero in btrfs_search_dir_index_item() and should not
passed to ERR_PTR(). Now btrfs_unlink_subvol() is the only caller to
this, reconstructed it to check ERR_PTR(-ENOENT) while ret >= 0.

This fixes smatch warnings:

fs/btrfs/dir-item.c:353
btrfs_search_dir_index_item() warn: passing zero to 'ERR_PTR'

Fixes: 9dcbe16fccbb ("btrfs: use btrfs_for_each_slot in btrfs_search_dir_index_item")
CC: stable@vger.kernel.org # 6.1+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Yue Haibing and committed by
David Sterba
75f49c3d 3c36a72c

+4 -7
+2 -2
fs/btrfs/dir-item.c
··· 347 347 return di; 348 348 } 349 349 /* Adjust return code if the key was not found in the next leaf. */ 350 - if (ret > 0) 351 - ret = 0; 350 + if (ret >= 0) 351 + ret = -ENOENT; 352 352 353 353 return ERR_PTR(ret); 354 354 }
+2 -5
fs/btrfs/inode.c
··· 4368 4368 */ 4369 4369 if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) { 4370 4370 di = btrfs_search_dir_index_item(root, path, dir_ino, &fname.disk_name); 4371 - if (IS_ERR_OR_NULL(di)) { 4372 - if (!di) 4373 - ret = -ENOENT; 4374 - else 4375 - ret = PTR_ERR(di); 4371 + if (IS_ERR(di)) { 4372 + ret = PTR_ERR(di); 4376 4373 btrfs_abort_transaction(trans, ret); 4377 4374 goto out; 4378 4375 }