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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 CC698C4338F for ; Fri, 30 Jul 2021 10:58:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D74A60F9B for ; Fri, 30 Jul 2021 10:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238548AbhG3K6s (ORCPT ); Fri, 30 Jul 2021 06:58:48 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:41513 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238403AbhG3K6q (ORCPT ); Fri, 30 Jul 2021 06:58:46 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3A2eBEUquv5/I2tx8aNsVdyL8A7skDr9V00zEX?= =?us-ascii?q?/kB9WHVpm62j+/xG+c5x6faaslkssQ4b9+xoVJPgfZr3z/5ICPAqTNSftVDdyQ?= =?us-ascii?q?mVxeJZnO7fKkPbaknDH7VmpMBdmsFFYbXN5D5B/KDHCWKDfurIruPszEhd792u?= =?us-ascii?q?tkuFNTsaE52JZGxCe32m+sccfng9OXKBf6Dsm/Z6mw=3D=3D?= X-IronPort-AV: E=Sophos;i="5.84,281,1620684000"; d="scan'208";a="389360966" Received: from dt-lawall.paris.inria.fr ([128.93.67.65]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 12:58:40 +0200 Date: Fri, 30 Jul 2021 12:58:40 +0200 (CEST) From: Julia Lawall X-X-Sender: julia@hadrien To: Daniel Thompson cc: Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: Re: [PATCH] scripts: coccinelle: allow list_entry_is_head() to use pos In-Reply-To: <20210730095856.2038286-1-daniel.thompson@linaro.org> Message-ID: References: <20210730095856.2038286-1-daniel.thompson@linaro.org> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Jul 2021, Daniel Thompson wrote: > Currently use_after_iter.cocci generates false positives for code of the > following form: > ~~~ > list_for_each_entry(d, &ddata->irq_list, node) { > if (irq == d->irq) > break; > } > > if (list_entry_is_head(d, &ddata->irq_list, node)) > return IRQ_NONE; > ~~~ > [This specific example comes from drivers/power/supply/cpcap-battery.c] > > Most list macros use list_entry_is_head() as loop exit condition meaning it > is not unsafe to reuse pos (a.k.a. d) in the code above. > > Let's avoid reporting these cases. > > Signed-off-by: Daniel Thompson > --- > > Notes: > I'm pretty much a complete beginner w.r.t. SmPL. This is written > entirely by finding previous fixes and emulating them! > > However I did test it by running the checker across the current kernel > tree. The changes reduced the error count by four... which was small > enough for me to eyeball each one and check they match the pattern I > was targetting. This looks fine. Thanks for the proposal. julia > > scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci > index 9be48b520879..676edd562eef 100644 > --- a/scripts/coccinelle/iterators/use_after_iter.cocci > +++ b/scripts/coccinelle/iterators/use_after_iter.cocci > @@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S > | > list_remove_head(x,c,...) > | > +list_entry_is_head(c,...) > +| > sizeof(<+...c...+>) > | > &c->member > > base-commit: 2734d6c1b1a089fb593ef6a23d4b70903526fe0c > -- > 2.30.2 > >