btrfs: assume fs_info is non-NULL and drop ternary check
RFC 1/1 btrfs: assume fs_info is non-NULL and drop ternary check
When assigning max_bytes, fs_info is checked for being non-NULL and a value is assigned accordingly.
However, a few lines below we do dereference fs_info multiple times without checking whether it is non-NULL anymore.
This pattern has triggered Coverity Scan which thinks that we may hit a NULL-ptr-dereference.
If we know for sure that fs_info cannot be NULL (and this seems to be the case since various instructions assume so), we should drop the ternary check when assigning max_bytes in order to avoid confusing the casual reader or static analyzers.
Address-Coverity-ID: 1659628 ("Null pointer dereferences (FORWARD_NULL)")
--- fs/btrfs/extent_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/extent_io.c +1 -2
@@ -374,8 +374,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree;const u64 orig_start = *start;const u64 orig_end = *end; -/* The sanity tests may not set a valid fs_info. */ -u64 max_bytes = fs_info ? fs_info->max_extent_size :BTRFS_MAX_EXTENT_SIZE ; +u64 max_bytes = fs_info->max_extent_size;u64 delalloc_start;u64 delalloc_end;bool found;
Signature · 1 line
2.49.1
Quoted 8 lines · Antonio Quartulli
When assigning
max_bytes,fs_infois checked for being non-NULL and a value is assigned accordingly.
However, a few lines below we do dereferencefs_infomultiple times without checking whether it is non-NULL anymore.This pattern has triggered Coverity Scan which thinks that we may hit a NULL-ptr-dereference.
Quoted 8 lines
If we know for sure that
fs_infocannot be NULL (and this seems to be the case since various instructions assume so), we should drop the ternary check when assigningmax_bytesin order to avoid confusing the casual reader or static analyzers.Fixes f7b12a62f008a ("btrfs: replace BTRFS_MAX_EXTENT_SIZE with fs_info->max_extent_size")Address-Coverity-ID: 1659628 ("Null pointer dereferences (
FORWARD_NULL)")Signed-off-by Antonio Quartulli <[email protected]>
Thanks, the fix for that was sent yesterday and is now in for-next.
Quoted 3 lines · David Sterba
Thanks, the fix for that was sent yesterday and is now in for-next.
Ah perfect!
Thanks for the quick feedback.
Regards,
Signature · 5 lines
Antonio Quartulli CEO and Co-Founder Mandelbit Srl https://www.mandelbit.com