Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2142256pxt; Sun, 8 Aug 2021 13:05:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/OndOAvwB+WfZ6V1+HxLp8qOiC1/L+102SDK4rsH2vv+2hdANTqbGxmsvVRb/y/K1eQs/ X-Received: by 2002:a5d:9b8b:: with SMTP id r11mr130800iom.26.1628453145090; Sun, 08 Aug 2021 13:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628453145; cv=none; d=google.com; s=arc-20160816; b=kA8qsi9olZsYcoT4XqMY0A7RDadQ9TNw+jlPRycfzYmlakpWeDnN4GgOBO0e/eEqtZ qZ84+95Us/tNj197KmSLYgzwlc75rYEEwgDXFGul36iE2Vv0ViCPAxUKtfVa8+UoTjcY 6DM4qbYOSpDVj4AyPlRFmQdExerL6VD9d10MtS8zCKW2iDh8141gZ1qZGP0I3aL9O1t0 ++ABHpwkBtYfWcSAiiImw0Fn55ih5GlpXl4y9UG1TTBDuy3Q9MDKmVy6yQQpph5LXBxQ AfDEF5h1S/gswbrY2r8SKUV4CLvYkaoXLlyq/8WLGOKlkiHdiyD17WE58xVOKy90XXiz q8Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:ironport-hdrordr; bh=f/+XbRR44XtTMom5qVvpPqCrNQ1LOAYtgK7kIDWz7po=; b=a1K7B326drDiY9oJmCXYFm3Pn1wpUTcvLNLQP+PXGDG4R49QDfSN0WDiuxG0qEQBNy BbgNOF+hdoDLXxd+LnbFo8x9VvWveSBfk5X8u9eF/UvdAhcWZCmD6FTJQuuXqobH3uQm Gw7KMRRkpzm1ioBvhVz29/ZEmkYEueN9WIptvFdFL5vXWsGUNdawvHLVEZJZOeaA2pzk x8RGq18PWniCGoiboA5o6PhiduHSXvt2W131RgTBwFmf1jQZAbqBW5qnjdAZ3IfBhZ/k BbCio6A986yop4sLhshcybgu9Uk7h+AOKgXbfVY6PFtoh0wHSv15jSUjU+N+SMiMLwI2 Hg8g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e14si8577029ilq.20.2021.08.08.13.05.33; Sun, 08 Aug 2021 13:05:45 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232123AbhHHUCy (ORCPT + 99 others); Sun, 8 Aug 2021 16:02:54 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:50909 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbhHHUCx (ORCPT ); Sun, 8 Aug 2021 16:02:53 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3Ac78dvq8XcAmcKH/WlMBuk+DfI+orL9Y04lQ7?= =?us-ascii?q?vn2ZKCYlFvBw+PrEoB1273XJYXMqOU3I+urwXZVoI0m9yXcd2+B4AV7hZniEhI?= =?us-ascii?q?LCFu9fBOXZrwEIVxeOlNJ15ONQN5JzD9D9FjFB4PrS6gPQKbkd/OU=3D?= X-IronPort-AV: E=Sophos;i="5.84,305,1620684000"; d="scan'208";a="389930998" Received: from 173.121.68.85.rev.sfr.net (HELO hadrien) ([85.68.121.173]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Aug 2021 22:02:33 +0200 Date: Sun, 8 Aug 2021 22:02:32 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@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. Applied. The function is really nice. The use_after_iter.cocci rule gives a lot of false positives where people have used random variables as flags to indicate how the loop was executed... thanks, julia > > 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. > > 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 > >