Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4887525ybi; Tue, 30 Jul 2019 09:51:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuH9WlHZWlc308JfkZd+dnG2kZaV584FLv1epXXpm+9sagw+VEzRyY7c7r8HNYW9lLjFg+ X-Received: by 2002:a17:90a:3225:: with SMTP id k34mr116184043pjb.31.1564505495592; Tue, 30 Jul 2019 09:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564505495; cv=none; d=google.com; s=arc-20160816; b=xdXwMh/7NV0klsds6QdjmTde8aNDo0wSvwN/YjY05YNuuW6A6E5Mp5qcL0rhHmZvKF jvueVT4O3HjqC9FuTJo9lO3Yzk+05NT13y2FkFPoG51PnnjD+Ug4Lx753kn6JC1QX/L9 1Tn0gmMgsv8iGIbYLZDLjefdNrFtx9/RnqDcvvE9Bv/adjqgJXmouRxR1529AlwjqAZL AlrGiSyaTK/Vc8S6rWPbiXc5KM+dTjBDX5Rv+isJMHvaSaYmB63luLd21NjlXvKvjN9p VXSC3qHtUKxLmVqda/uQ7EbcuVV2Pu8fi+i5iub9ipoegt8o7+RJ1SBNbiEVTP0sIP6/ mu/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=AhD7T97WuqDfJIligUOdr0xYEbyqrfvCvLWGque7i3w=; b=exrxnVobnu7m2ab1071EBd4TOeYkOg4KhBLeQ1WU3EkuOU+aOJDX7yEngD+ktPl6/Z yO+x1rwbenZJuPqpdIcoPCn5+OA8GiFfxBT8/AWAVKxhwcS9m/qVBfzprVng8vcRgD9h WD/d/THt7EMRJa5XbjhKzp3ZYqwaWEYy6rJfwWgS6d7uk/bBYNqZ9lQH+Ak93E/i+GDo LdfIy+owKoV5DlrNQ63kI3lH7iNhFpUehVUsrlELkZzvjJk+TPfaiVOyxgyIiVg2gLYH OkdaTRu10DUG3J6FXeESvca5q73MntRAtbHQNLfXvqQXEaJ7ErA80NP9BNZH+jjrMwVa VRWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k5si26339288plt.355.2019.07.30.09.51.20; Tue, 30 Jul 2019 09:51:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729290AbfG3QdR (ORCPT + 99 others); Tue, 30 Jul 2019 12:33:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:60568 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727924AbfG3QdP (ORCPT ); Tue, 30 Jul 2019 12:33:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 992B1B03C; Tue, 30 Jul 2019 16:33:14 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5990ADA808; Tue, 30 Jul 2019 18:33:49 +0200 (CEST) Date: Tue, 30 Jul 2019 18:33:49 +0200 From: David Sterba To: Jia-Ju Bai Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.cz, quwenruo.btrfs@gmx.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs: btrfs: Add an assertion to warn incorrct case in insert_inline_extent() Message-ID: <20190730163349.GD28208@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Jia-Ju Bai , clm@fb.com, josef@toxicpanda.com, quwenruo.btrfs@gmx.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190727085113.11530-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190727085113.11530-1-baijiaju1990@gmail.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 27, 2019 at 04:51:13PM +0800, Jia-Ju Bai wrote: > In insert_inline_extent(), the case that compressed_size > 0 > and compressed_pages = NULL cannot occur, otherwise a null-pointer > dereference may occur on line 215: > cpage = compressed_pages[i]; > > To warn this incorrect case, an assertion is added. > Thank Qu Wenruo and David Sterba for good advice. > > Signed-off-by: Jia-Ju Bai > --- > fs/btrfs/inode.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 1af069a9a0c7..21d6e2dcc25f 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -178,6 +178,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)) Thanks. I expect that the static checking tools can be instructed to understand that the condition has been checked and is not missing in the code below. ASSERT is conditinally a BUG() wrapper, otherwise a no-op. Btw, it's also good to check that the code compiles, the statement is missing semicolon.