From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 171BDC43603 for ; Wed, 18 Dec 2019 16:31:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE246227BF for ; Wed, 18 Dec 2019 16:31:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727482AbfLRQbW (ORCPT ); Wed, 18 Dec 2019 11:31:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:49828 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbfLRQbW (ORCPT ); Wed, 18 Dec 2019 11:31:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77D64AB71; Wed, 18 Dec 2019 16:31:20 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 1F1DDDA730; Wed, 18 Dec 2019 17:31:18 +0100 (CET) Date: Wed, 18 Dec 2019 17:31:18 +0100 From: David Sterba To: Aditya Pakki Cc: kjlu@umn.edu, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] btrfs: remove BUG_ON used as assertions Message-ID: <20191218163117.GN3929@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Aditya Pakki , kjlu@umn.edu, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20191215171237.27482-1-pakki001@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191215171237.27482-1-pakki001@umn.edu> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 15, 2019 at 11:12:36AM -0600, Aditya Pakki wrote: > alloc_extent_state_atomic() allocates extents via GFP_ATOMIC flag > and cannot fail. Here you say it cannot fail (without a proof) > There are multiple invocations of BUG_ON on the > return value to check for failure. The patch replaces certain > invocations of BUG_ON by returning the error upstream. > > Signed-off-by: Aditya Pakki > --- > fs/btrfs/extent_io.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index eb8bd0258360..e72e5a333e71 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -989,7 +989,10 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, > node = tree_search_for_insert(tree, start, &p, &parent); > if (!node) { > prealloc = alloc_extent_state_atomic(prealloc); > - BUG_ON(!prealloc); > + if (!prealloc) { > + err = -ENOMEM; > + goto out; And add error handling when it fails, which is in contradiction but anyway, replacing BUG_ON with error checks requires auditing the whole call chain up. We've had attempts to do this change already, none of them was correct so unfortunatelly the BUG_ON needs to stay to avoid errors being silently ignored.