Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6844859pxv; Fri, 30 Jul 2021 03:59:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeVQkEHMbubyUgVNeMq6ImaxXnSaY/g+WfIyMLFlPIgXspccEV9aSwUqKcU8kYBeJc72zl X-Received: by 2002:a5e:c70d:: with SMTP id f13mr1992763iop.95.1627642773122; Fri, 30 Jul 2021 03:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627642773; cv=none; d=google.com; s=arc-20160816; b=PBnl3metWqj/FMHXhgILdQGOHdzlXPGpHF8exJwVGR1kE3yXMC0J6WQqwlGWJPjvTT ot7ewDd7/TMLOSwbfpXyGKAyQ1SKybSVxvEEy+cX0hnawgxXlucVkSqpK+4YgOd2qy/b 9xOhIij/0hWd8dokMpNMYuRZM6uhVpK2GNoxEtwZtZ2exzeGRi5ELVD3Bxf6AfHJ5e6R 5FODaQylaSXdmpzjSbyVT41TYYusfuwNAWjwlQiL/4hW1gMLdnglSFzjiveqIB+2d+49 xcMaS5dOnqhEXZ6gQDGLAmL6iEY3bh5ZNRSvrQNScYlYZaJvUZaD2+4NQTWAvcjwl60q 2/7Q== 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=m4dG24edm5FuZnVIVPqbI5I57WIklTEPzm/T5DUqlnE=; b=VqT8jBtVw+BEWdEDFNEd18g5/MEt1E5Wsbag7XA4oZoxDpE+7PQc3bviBxxYI/jqTa 3XzTxvU66KmzLhBH2vB3ywnglfHV+uqBKvAbHXoyQknaSxrMuEg0mtwDZiGtG1bPabj/ ZPaZR79UBAWAzZLDicup2XRDTO0uRlVGWVGlEgaVnpB/Jo9Uck741zx0WB7kPIIaz+0P PysBYG/EEZqgQgo9Ssj4KLIbGBklfmvTgXcOt4FxZROxceVfc/8NbrWRHoY8aG1sEPTo LGELtfzWTEJcXbGkk09/3ks2Wa1Sn2dxjvFsfI6Gdpnx6xuypiRJ8EWdsuORMmo0jBqF idTw== 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 n3si1552015ioh.98.2021.07.30.03.59.21; Fri, 30 Jul 2021 03:59:33 -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 S238461AbhG3K6r (ORCPT + 99 others); Fri, 30 Jul 2021 06:58:47 -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 > >