From: Jia-Ju Bai Date: Sat, 27 Jul 2019 08:51:13 +0000 (+0800) Subject: btrfs: Add an assertion to warn incorrect case in insert_inline_extent() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=982f1f5d161735efb85f85cd9c5fb4d61ccfc0aa;p=linux.git btrfs: Add an assertion to warn incorrect case in insert_inline_extent() In insert_inline_extent(), the case that checks compressed_size > 0 and compressed_pages = NULL cannot occur, otherwise a null-pointer dereference may occur on line 215: cpage = compressed_pages[i]; To catch this incorrect case, an assertion is added. Reviewed-by: Qu Wenruo Signed-off-by: Jia-Ju Bai Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c3feb5310e17c..20963b6567aef 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -176,6 +176,9 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, size_t cur_size = size; unsigned long offset; + ASSERT((compressed_size > 0 && compressed_pages) || + (compressed_size == 0 && !compressed_pages)); + if (compressed_size && compressed_pages) cur_size = compressed_size;