Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp204559ima; Fri, 15 Mar 2019 00:30:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzITp0pjScAyqoOQHpYY1roOSJtvD4kkqEOcu6YUgi+CMqUW2NRt6BATwBX5ZOZvzE1mGBn X-Received: by 2002:a63:6193:: with SMTP id v141mr2022001pgb.392.1552635045848; Fri, 15 Mar 2019 00:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552635045; cv=none; d=google.com; s=arc-20160816; b=mPESejWxQVuzXzgEZ/LhwZGETd7kcfxwslG1jspiBBF5CylZSkJeszAuLzx72oy07+ 3Lfq2cK+StlNyqA157a+HCiHG8iVeArsCldeVD+qmn4L6kFA81gdDN6LOOZbtiHkppSs x0YGWKlCHXpVMB9YCbt+NjFBz1jAlxmzHA1xdLhI2nRgj/A8I3mp6APRdf88Agsw+5PH VazKyn3Hn/nHOizKtAVDA4LtxnCkdDGL2JnMFpE/sp4CKQuuX4XvvPouUPijF+zAcr5E ZwAb6AjzBnZ58o/K6RqpouRC8lwPZP+peU8MOTF3H+3nd7187J/+h8+mj/VUHJxgssBl 98Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=7CdbSqwNg7MM7oU9rcPuSwkXdk+uz2mdl0KYjgKJfLA=; b=cIOL7kLv/RYyPc/DOg4/6GGdKXdEUcJrw9Bhjg3AboHQrkiTHITr3ldLQR2JUGyX4d Q1x28kNlNXx4CfqV2wBSskaIG/HU1s6kQAv6Q1lQg3qBQ8dwnrKHiqnZTaUiMjlqPpmN 5rRcgSExlWGg8sLGPgvcyRaYTQJo35yG/x0gvgXdvlqWj3FdEaKREdz4hCbWF8wrIx6v 8T2kW5Y4Xs5ZNHl9EIaUgpzqvvuGpWt8Cbfpm8rYarYq+1HTP7i/B/ly2WuZxqH26QrG vBmUcIR4TvhVVOZWvmadzSJ33CdSIb5qc8HCtZ3AfMONSTsVPcmzZ1D5I5/hF7WF9Xrx KsoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si1224182pgc.362.2019.03.15.00.30.30; Fri, 15 Mar 2019 00:30:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727743AbfCOH3x (ORCPT + 99 others); Fri, 15 Mar 2019 03:29:53 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:58373 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726790AbfCOH3x (ORCPT ); Fri, 15 Mar 2019 03:29:53 -0400 X-IronPort-AV: E=Sophos;i="5.58,481,1544482800"; d="scan'208";a="299328918" Received: from abo-58-107-68.mrs.modulonet.fr (HELO hadrien) ([85.68.107.58]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2019 08:29:50 +0100 Date: Fri, 15 Mar 2019 08:29:49 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Wen Yang cc: wang.yi59@zte.com.cn, Gilles Muller , nicolas.palix@imag.fr, michal.lkml@markovi.net, cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: Re: [PATCH] coccinelle: semantic patch for missing of_node_put In-Reply-To: <1552616681-17985-1-git-send-email-wen.yang99@zte.com.cn> Message-ID: References: <1552616681-17985-1-git-send-email-wen.yang99@zte.com.cn> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 15 Mar 2019, Wen Yang wrote: > Looking for places where there is an of_node_put on some paths > but not on others. This SmPL checks that there is a put of the > same data elsewhere in the function, so perhaps that will > alleviate the concern about puts where they are not needed, > while still making it possible to find the ones that are needed. > > Suggested-by: Julia Lawall > Signed-off-by: Wen Yang > Reviewed-by: Julia Lawall > --- > scripts/coccinelle/free/of_node_put.cocci | 57 +++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > create mode 100644 scripts/coccinelle/free/of_node_put.cocci > > diff --git a/scripts/coccinelle/free/of_node_put.cocci b/scripts/coccinelle/free/of_node_put.cocci > new file mode 100644 > index 0000000..6a29830 > --- /dev/null > +++ b/scripts/coccinelle/free/of_node_put.cocci > @@ -0,0 +1,57 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/// Find missing of_node_put > +/// > +// Confidence: Moderate > +// Comments: > +// Options: --no-includes --include-headers > + > +virtual report > +virtual org > + > +@r exists@ > +local idexpression struct device_node *x; > +identifier f; > +statement S,S1,S2; > +expression e,e1; > +position p1,p2; > +type T,T1; > +@@ > + > +( > +x = f@p1(...); > +... when != e = (T)x I suggest the following: ( if (x) { ... of_node_put(x) ... } | > +if (x == NULL || ...) S1 > +else S2 > +... when != of_node_put(x) > + when != if (x) { ... of_node_put(x) ... } > + when != e1 = (T1)x > +( > +return x; > +| > +return@p2 ...; > +) ) If the first test is for success of the allocation and may lead to an of_node_put, then you can stop. Perhaps if (x) { ... when forall of_node_put(x) ... } there would be better, to check if there is always a put. This could also be done on the other if (x) > +& > +x = f(...) > +... > +if (<+...x...+>) S > +... > +of_node_put(x); There is actually an opportunity here for more reports. Perhaps we can assume that if the function calls of_node_put on anything, then it is needed on everything. So this could be of_node_put(...). But the downside of that is that the original x = f(...) may now let through things that are not reference counted. So you would want two rules, first this one where the function is f and there is a of_node_put on the result of the function, and another one where you consider a known set of functions, and then allow a subsequent of_node_put on anything. It would take some care to ensure that there is only one report per call site. julia > +) > + > +@script:python depends on report@ > +p1 << r.p1; > +p2 << r.p2; > +@@ > + > +coccilib.report.print_report(p2[0], > + "ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line " > + + p1[0].line > + + ", but without a corresponding object release within this function.") > + > +@script:python depends on org@ > +p1 << r.p1; > +p2 << r.p2; > +@@ > + > +cocci.print_main("acquired a node pointer with refcount incremented", p1) > +cocci.print_secs("needed of_node_put", p2) > -- > 2.9.5 > >