From patchwork Mon Nov 7 18:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 16634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2214437wru; Mon, 7 Nov 2022 10:21:20 -0800 (PST) X-Google-Smtp-Source: AMsMyM43NrCMvMM0Xlbv2QEcaC9IyZCE4Z/9FHHgA3yB8tD3YYpPPzMs+t03mhIJUdkT57JRoft6 X-Received: by 2002:a63:5246:0:b0:42b:e4a5:7252 with SMTP id s6-20020a635246000000b0042be4a57252mr43042782pgl.566.1667845280310; Mon, 07 Nov 2022 10:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667845280; cv=none; d=google.com; s=arc-20160816; b=siWkuZnsLn2u6GtFAL10y5i9dcvt1auD0xqv9zCbadkIYEmoqR31Mh/zens47jfTpw acFlcS7Hdo1pAlgl0VQ6HB0zJq/zytYuL7zzXC1tQP+4PEmfh09kBz6mspy+1iiUoNBK LpfuQf5fDPgEu9kDy6LZ1Gb+HyoW89jdCC74B3oCfnKV9r7KMlzZmNEUPAJTReP/RvHe Dso/OrnvQ5/IBm5+QBB6mpBOv+TqOI6/Q1X6tcjF6j/n+sqY4I6DGA1s4RL9ifX3c3Fd rzt6Nb1AEffuGkp1J735FrbFcjLydYkdFu3ZDSI2u4idVRNk9cZE0awC2vTZTuaix70b mT3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=w3Bna5ibdc3+BUXVbrKZPp0eEUsKlkePRjTB8RXTQzg=; b=MGrHOnAXtTDcrCc14YSQCVubEd/OEtrZ8mdpUYrUEPOC7lTSuPEXm/7EUX0/G11tHT DqGIzGJzB0r1916mfeL4J+L1H12A/4Ye5HQl5Cu3/0v6AYMi8f6a7oKD7tZAPnEpeCeU x9LXKF6vIuxoy/FQxeH7zlO2i6Qibo1smUifZjFOEs24A8BiODAcwjo57EdMDKzNWAso o17HthA6/toBz9TFcp/feRe3N/2GoFDaFMEgZ3a0J8DNBxOG2sz9Z/zVDvktEDgZ6GAu 2YmC3XQueEnRagMlc7EMn485M6+A0sIg4i5cqz0aal0p+vIxfdqe0ZiZQ9unvGFwqQYO Tcug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b0047018d5b375si11666208pge.561.2022.11.07.10.21.04; Mon, 07 Nov 2022 10:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbiKGSNm (ORCPT + 99 others); Mon, 7 Nov 2022 13:13:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232840AbiKGSNK (ORCPT ); Mon, 7 Nov 2022 13:13:10 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB5329C85 for ; Mon, 7 Nov 2022 10:11:47 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os6b3-00065f-Ia; Mon, 07 Nov 2022 19:11:45 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1os6b1-002uN5-8c; Mon, 07 Nov 2022 19:11:44 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1os6b1-00F1sJ-8Q; Mon, 07 Nov 2022 19:11:43 +0100 Date: Mon, 7 Nov 2022 19:11:35 +0100 From: Uwe =?utf-8?q?Kleine-K=C3=B6nig?= To: Julia Lawall Cc: kernel@pengutronix.de, Nicolas Palix , linux-kernel@vger.kernel.org, cocci@inria.fr Subject: [PATCH v2] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL Message-ID: <20221107181135.tm2wmwiulepsyrmk@pengutronix.de> References: <20221107114702.15706-1-u.kleine-koenig@pengutronix.de> <28e17fb9-cec1-4a89-1492-cd3ece7a9487@inria.fr> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <28e17fb9-cec1-4a89-1492-cd3ece7a9487@inria.fr> X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748838131690631914?= X-GMAIL-MSGID: =?utf-8?q?1748862533065704662?= devm_platform_get_and_ioremap_resource(pdev, index, NULL) is equivalent to the shorter devm_platform_ioremap_resource(pdev, index). Signed-off-by: Uwe Kleine-König --- On Mon, Nov 07, 2022 at 08:45:38PM +0800, Julia Lawall wrote: > On Mon, 7 Nov 2022, Uwe Kleine-König wrote: > > > devm_platform_get_and_ioremap_resource(pdev, index, NULL) is equivalent to > > the shorter devm_platform_ioremap_resource(pdev, index). > > > > Signed-off-by: Uwe Kleine-König > > --- > > Hello, > > > > a potential improvement is to check for invocations of > > devm_platform_get_and_ioremap_resource() where the res parameter isn't > > used afterwards, but my coccinelle foo isn't strong enough for that. > > ... when != res > > I'm not sure where you wanted to put it though. I tinkered a bit further and even succeeded to remove the declaration if it's otherwise unused. I failed to test the report mode, my spatch tells me some error about python2?! Best regards Uwe .../api/devm_platform_ioremap_resource.cocci | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 scripts/coccinelle/api/devm_platform_ioremap_resource.cocci diff --git a/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci new file mode 100644 index 000000000000..485dfa6ea0aa --- /dev/null +++ b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Don't use devm_platform_get_and_ioremap_resource with NULL as third parameter +// Confidence: High + +virtual patch +virtual context +virtual org +virtual report + +@r1@ +position p; +@@ + devm_platform_ioremap_resource(...) { + ... + devm_platform_get_and_ioremap_resource@p(...) + ... + } + +@depends on patch@ +expression pdev,index; +position p != r1.p; +@@ + +- devm_platform_get_and_ioremap_resource@p(pdev, index, NULL) ++ devm_platform_ioremap_resource(pdev, index) + +@depends on patch@ +expression pdev,index; +identifier res; +type T; +@@ +- T res; + ... when != res +- devm_platform_get_and_ioremap_resource(pdev, index, &res) ++ devm_platform_ioremap_resource(pdev, index) + ... when != res + +@depends on patch@ +expression pdev,index; +identifier res; +@@ + +- devm_platform_get_and_ioremap_resource(pdev, index, &res) ++ devm_platform_ioremap_resource(pdev, index) + ... when != res + +@r2 depends on !patch exists@ +expression pdev,index; +position p; +@@ + +* devm_platform_get_and_ioremap_resource@p(pdev, index, NULL) + +@script:python depends on org@ +p << r2.p; +@@ + +cocci.print_main("WARNING opportunity for devm_platform_ioremap_resource", p) + +@script:python depends on report@ +p << r2.p; +@@ + +coccilib.report.print_report(p[0], "WARNING opportunity for devm_platform_ioremap_resource") + +@r3 depends on !patch exists@ +expression pdev,index; +identifier res; +position p; +@@ + +* devm_platform_get_and_ioremap_resource@p(pdev, index, &res) + ... when != res + +@script:python depends on org@ +p << r3.p; +@@ + +cocci.print_main("WARNING opportunity for devm_platform_ioremap_resource", p) + +@script:python depends on report@ +p << r3.p; +@@ + +coccilib.report.print_report(p[0], "WARNING opportunity for devm_platform_ioremap_resource")