Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp144556pxu; Thu, 7 Jan 2021 00:35:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJz24NmbYTojiXDFT4u75nMdHX/n/vuPbNhIwem/MT05+mFhZ4uOlOCw5lOjEVyYiRuDxaio X-Received: by 2002:a17:906:16da:: with SMTP id t26mr5493885ejd.478.1610008556001; Thu, 07 Jan 2021 00:35:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610008555; cv=none; d=google.com; s=arc-20160816; b=QFSbvBwXrNBbGFwbcSES20nW/gQjyG6OLc2B9SZ1pHszqORwplZH7veVnCOkxZ4Gac VFSnFVgZssZzys7KKNijyA5/TL6f19wQ+50lOWyem5Ws9zwytZyM9eTfPvtdjrb0UR4e I+DZI85F1+0VTN/FmN9ybMFFK2O4F4HOzHGFqluGeu1xwu5NhOfqqH1KznrgYJM1fC1v nON9uf/6hhGVvEvy38HueXO+sp52FjK0ERprv1zsO5bST9tFN+UqDkzYo0YNIHC+GUql Wuvp4Z0yCjiuDGKwnDDva4R3cKdNtpi5j2jsb4n7t7iIEBM+Ol2l818pFMYSOYihiUQD qc4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=atqkR6C9/ExhC/8cuG/QGTvgoAMgF5+BLpqtsv0ezpE=; b=wEiu7tOebDPbsvZ6MH+xZD6EWAV1s2Hxtka3rBGA3iKlC3YFnHWYczmbD/p0O30K/n 5zsoBbjNeP56d6Wo54L5HgzXgDRJXz1ogOOlmXd18it9uX2RN+WgtZs9QdKetWhKnplC RPjj5Ggfr3mYlXZwK3U6T4kE03MUBeIfv3zrYw4eokk/qCWNhsrBEAYWH46iGIaHmS9k HwlopQ7tWFr878c+DUM54JZidGbgJu3gwHT1QMrFEj1H6Q73+SM65+Ha/lIN6InnY0V1 5ISiFP7CwbNIYVNs+Ge0mz5SQbG7soXEnysVmgXdWaSiJSd/DEuZi8f560PAF7GnKvBs 8WLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=eaMrF6pB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si1821020ejr.334.2021.01.07.00.35.32; Thu, 07 Jan 2021 00:35:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=eaMrF6pB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbhAGIeL (ORCPT + 99 others); Thu, 7 Jan 2021 03:34:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:40436 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbhAGIeL (ORCPT ); Thu, 7 Jan 2021 03:34:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610008404; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=atqkR6C9/ExhC/8cuG/QGTvgoAMgF5+BLpqtsv0ezpE=; b=eaMrF6pBLcI5HmqeMr5Jwf+N7AZJQq8O4+DcXq7tmFfc6hk/5BvC3NJALjUFiUgr3EsOQy TVCRQCSZ54+/t5HcLebSjTy5EAKb2FrsJwfKw9q95ofQN5XWd4wRKVxjX3MrehNuBRZ9cP UWa5doHmCnua8SQfLS3A6ARHjKlIsnI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 76E86B762; Thu, 7 Jan 2021 08:33:24 +0000 (UTC) Date: Thu, 7 Jan 2021 09:33:23 +0100 From: Michal Hocko To: Hugh Dickins Cc: Andrew Morton , Alex Shi , Minchan Kim , Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/mmap: replace if (cond) BUG() with BUG_ON() Message-ID: <20210107083323.GZ13207@dhcp22.suse.cz> References: <1607743586-80303-1-git-send-email-alex.shi@linux.alibaba.com> <1607743586-80303-2-git-send-email-alex.shi@linux.alibaba.com> <20210106114620.5c221690f3a9cad7afcc3077@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 06-01-21 12:10:30, Hugh Dickins wrote: > On Wed, 6 Jan 2021, Andrew Morton wrote: > > On Tue, 5 Jan 2021 20:28:27 -0800 (PST) Hugh Dickins wrote: > > > > > Alex, please consider why the authors of these lines (whom you > > > did not Cc) chose to write them without BUG_ON(): it has always > > > been preferred practice to use BUG_ON() on predicates, but not on > > > functionally effective statements (sorry, I've forgotten the proper > > > term: I'd say statements with side-effects, but here they are not > > > just side-effects: they are their main purpose). > > > > > > We prefer not to hide those away inside BUG macros > > > > Should we change that? I find BUG_ON(something_which_shouldnt_fail()) > > to be quite natural and readable. > > Fair enough. Whereas my mind tends to filter out the BUG lines when > skimming code, knowing they can be skipped, not needing that effort > to pull out what's inside them. > > Perhaps I'm a relic and everyone else is with you: I can only offer > my own preference, which until now was supported by kernel practice. I agree with Hugh. BUG_ON on something that is not a trivial predicate makes the code slightly harder to follow. I also do agree that accomodating the coding style to the existing code is better as well because the resulting code is more compact. In general I consider code transformations like this without a higher goal that is stated explicitly a pointless churn which doesn't bring much while it consumes a very scarce review bandwidth. Even when those look trivial there is always a room to introduce silent breakage. Be it a checkpatch or coccinelle the change shouldn't be based solely on the script complains. Really, what is the point of changing an existing if (cond) BUG into BUG_ON? Fewer lines? Taste? Code consistency? -- Michal Hocko SUSE Labs