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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 DB74FC433DF for ; Tue, 13 Oct 2020 10:30:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C7E220872 for ; Tue, 13 Oct 2020 10:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730322AbgJMKaj (ORCPT ); Tue, 13 Oct 2020 06:30:39 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:62266 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729241AbgJMKai (ORCPT ); Tue, 13 Oct 2020 06:30:38 -0400 X-IronPort-AV: E=Sophos;i="5.77,370,1596492000"; d="scan'208";a="472338857" Received: from abo-173-121-68.mrs.modulonet.fr (HELO hadrien) ([85.68.121.173]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Oct 2020 12:30:36 +0200 Date: Tue, 13 Oct 2020 12:30:36 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Sumera Priyadarsini cc: cocci@systeme.lip6.fr, michal.lkml@markovi.net, nicolas.palix@imag.fr, linux-kernel@vger.kernel.org, Gilles.Muller@lip6.fr Subject: Re: [Cocci] [PATCH V2] coccinelle: iterators: Add for_each_child.cocci script In-Reply-To: <20201012171909.ihbx73evyj5dosxl@adolin> Message-ID: References: <20201012171909.ihbx73evyj5dosxl@adolin> 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 I have one more change to suggest. This one only affects the patch case, as the other cases just point to a problem but don't ompletely specify what to do about it. > +@ruleone depends on patch && !context && !org && !report@ > + > +local idexpression r.n; > +iterator r.i,i1; > +expression e; > +expression list [r.n1] es; > +statement S; > +@@ > + > + i(es,n,...) { > + ... > +( > + of_node_put(n); > +| > + e = n > +| > + return n; > +| > + i1(...,n,...) S > +| > ++ of_node_put(n); > +? return ...; > +) > + ... when any > + } There is one occurrence of the following code: for_each_available_child_of_node(search, child) { name = of_get_property(child, "regulator-compatible", NULL); if (!name) name = child->name; if (!strcmp(desc->of_match, name)) { of_node_put(search); return of_node_get(child); } } In this case, the for_each_available_child_of_node has incremented the reference count of child by 1, and then the return increments it again. It would be ok to put an of_not_put before the return, which is done by the above rule, but the code would be even simpler if it would just leave the reference count as is. So before the current return case, you can put another return case that does the following: - return of_node_get(n); + return n; julia