Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp50149ima; Thu, 14 Mar 2019 19:25:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1xr59PkGTkA1eYpt8ZF02Y8EK5Mt2CPeEWERhXw8Op7kWmPoHiK0F83qBdp7lS+OKIFD5 X-Received: by 2002:a17:902:784c:: with SMTP id e12mr1580270pln.117.1552616720381; Thu, 14 Mar 2019 19:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552616720; cv=none; d=google.com; s=arc-20160816; b=rxk2IgRYVCl70ZA7ZBTylbS/aN0BAeGv6Usu8M3fWRLB6/eXdonEBRrVbDz7zBcwi2 Ei6/uLOlHTb8HdVRUTiJwXgor+dp0EjIGN46iQm7DeeJKJLCGu8VK64W3MU8Tdwq2kiN 8rJZpQa7gFgs7umkxkBlB/PMk5Oqk+Np+LfJx2a7YfVUA0aBBqOMFMmRxoSbmKYPc/GV iflBsUZNZqk7DoN6dD70pa3I/RXplT43oj+DN8Z3lcN5ap4fstrGnMf8te93bafJcVer SKw+8onyTiv+acorHQSS955RfE9+53n3IA0k4TYyVd/UYkhnX+SN5brhGY2qMUqtqzQt qEcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=xKDGQY3N1OSaeuHZ74H9CqhKouK9JJHTHytS4cOBOKs=; b=nDeJSyEKniz2TF7Y5ugpQwnrTXd24KiTJLERRbxSPqNdygI1We9tpaWSuLXilGpr+O bF8cOTEEmAtIQ3heeW5fFc7CPxU8HtS4PHs8oybf5D1EGFxknJiWCuOcP39sxB0WR9ig vwoggkqFhWsUFNzVIwAlMFvREQmEokGDjz1ml9XnVfnFFWIxrJyqLrh5C8F46DWJnxMz HWTpOAh5dk+ePbkih65vgLZ69EWnDlHOvF64SK/dmOcIe7q34y0qhdRW2mrjnMCX6F9L u2rMg47bklbi9XC6um50ubneL1bmP1AL5HLXrkwhFN/yXX+x9pqwTbMbA24njYBKW3vV 0Fhw== 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 b39si577849pla.381.2019.03.14.19.25.05; Thu, 14 Mar 2019 19:25:20 -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 S1728199AbfCOCY2 (ORCPT + 99 others); Thu, 14 Mar 2019 22:24:28 -0400 Received: from mxhk.zte.com.cn ([63.217.80.70]:23546 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbfCOCY2 (ORCPT ); Thu, 14 Mar 2019 22:24:28 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id CE52A2E56648D56CFF59; Fri, 15 Mar 2019 10:24:24 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x2F2OG0C097582; Fri, 15 Mar 2019 10:24:16 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019031510245239-4956102 ; Fri, 15 Mar 2019 10:24:52 +0800 From: Wen Yang To: Julia.Lawall@lip6.fr Cc: wang.yi59@zte.com.cn, Gilles.Muller@lip6.fr, nicolas.palix@imag.fr, michal.lkml@markovi.net, cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Wen Yang Subject: [PATCH] coccinelle: semantic patch for missing of_node_put Date: Fri, 15 Mar 2019 10:24:41 +0800 Message-Id: <1552616681-17985-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-03-15 10:24:52, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-03-15 10:24:01, Serialize complete at 2019-03-15 10:24:01 X-MAIL: mse01.zte.com.cn x2F2OG0C097582 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 +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 ...; +) +& +x = f(...) +... +if (<+...x...+>) S +... +of_node_put(x); +) + +@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