[v1] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL
Message ID | 20221107114702.15706-1-u.kleine-koenig@pengutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2000201wru; Mon, 7 Nov 2022 03:53:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf6PTCyt34PPWwsfyRGgbi3gpGJwxtIePCVI1Vu7FhLG/1kAHMuBdOYCzp9/tZFeKq9pYxcl X-Received: by 2002:a17:906:a157:b0:7ae:5d04:c96 with SMTP id bu23-20020a170906a15700b007ae5d040c96mr7824053ejb.564.1667822009849; Mon, 07 Nov 2022 03:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667822009; cv=none; d=google.com; s=arc-20160816; b=Cv1LApR/pqgk8Xd7zO7qiuXuWBpqCfDaKRmmwXzbOscs9gigTzYSmTu5y9AyMaOB+3 uUBGu/l7rnEKh1/a7tfvT0S2/j99oEIqsBHQOxKTTy6uz3kybl7NutZ3m/S6nREp9aZv Y9LhJ3r58m0hBaguS2EhvaM7q5t0QwDSBsdZSzM2Cts4427PT8c/paoM7FGaGs/VPdLt oIRanVAogaieNKwhpfAxIbyubVm3u4F+jQz2vhrKz4zdnq6N09ncW4Qswn89BJ8wVhbe 5yFhM0M8F+/qDES3A17ScTOTsER1/f43RNlFozOkHqD0T9N+MgDvxwMIk+SaqyWfeHbY jHPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=EjdqGj77kZX7BdzBwYal3mc/7aZEl+OAgMkczfDOcv8=; b=ch28zZLAoWiKNd/8AOh3ciBAdL6JTuU8Nc+7NKraM8zIl6idLBx9Ux5dSWWFsCj+Tc VpL+hcBmuY67LJhxI9mbPGHTmJ5m8o8CtpMx7KdfZ4RbGluzQ9mqABt1BIizVxn/AcOi anNVmQCbuedSo0KA26fmqI5gh45O+Crhgpy68UYdXesk5dVHVCD7SCxmZVQlgPunUdRY 9w+10Pxs83PU5EUG43Ek1x3BIAhxz4oXsMYh3rlCOtkPj1Qqsh1dec7ZdNtE6KDXKA5A aLcj/PO9MVyjfKSE2KY49VAYv2E+G882F3lIXC21qVoLi722Zr1jlxBkLCBsq8n6TH6D pwdA== 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 e6-20020a056402190600b00461c0fd2597si11605384edz.89.2022.11.07.03.53.05; Mon, 07 Nov 2022 03:53:29 -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 S231638AbiKGLrS (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 06:47:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbiKGLrO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 06:47:14 -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 46159167F2 for <linux-kernel@vger.kernel.org>; Mon, 7 Nov 2022 03:47:13 -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 <ukl@pengutronix.de>) id 1os0at-00025I-Fz; Mon, 07 Nov 2022 12:47:11 +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 <ukl@pengutronix.de>) id 1os0ar-002qN3-5E; Mon, 07 Nov 2022 12:47:10 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from <ukl@pengutronix.de>) id 1os0ar-00ExHH-Gw; Mon, 07 Nov 2022 12:47:09 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de> To: Julia Lawall <Julia.Lawall@inria.fr>, Nicolas Palix <nicolas.palix@imag.fr> Cc: linux-kernel@vger.kernel.org, cocci@inria.fr, kernel@pengutronix.de Subject: [PATCH v1] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL Date: Mon, 7 Nov 2022 12:47:02 +0100 Message-Id: <20221107114702.15706-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> 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?1748838131690631914?= |
Series |
[v1] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL
|
|
Commit Message
Uwe Kleine-König
Nov. 7, 2022, 11:47 a.m. UTC
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 <u.kleine-koenig@pengutronix.de>
---
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.
Best regards
Uwe
.../api/devm_platform_ioremap_resource.cocci | 44 +++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
Comments
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 <u.kleine-koenig@pengutronix.de> > --- > 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. julia > > Best regards > Uwe > > .../api/devm_platform_ioremap_resource.cocci | 44 +++++++++++++++++++ > 1 file changed, 44 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..401610b9a17d > --- /dev/null > +++ b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci > @@ -0,0 +1,44 @@ > +// 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) > + > +@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") > -- > 2.38.1 > >
On Mon, Nov 07, 2022 at 08:00:33PM +0100, Markus Elfring wrote: > > > devm_platform_get_and_ioremap_resource(pdev, index, NULL) is equivalent to > > the shorter devm_platform_ioremap_resource(pdev, index). > … > > create mode 100644 scripts/coccinelle/api/devm_platform_ioremap_resource.cocci > … > > +@depends on patch@ > > +expression pdev,index; > > +position p != r1.p; > > > Why do you think that different source code positions would be required for > your transformation approach? That is important that the implementation of devm_platform_ioremap_resource isn't adapted. > > +@@ > > + > > +- devm_platform_get_and_ioremap_resource@p(pdev, index, NULL) > > ++ devm_platform_ioremap_resource(pdev, index) > > I suggest to use the following SmPL code variant instead. > > -devm_platform_get_and_ioremap_resource@p > +devm_platform_ioremap_resource > (pdev, index > - , NULL > ) I don't care much, but IMHO my variant is easier to read. Might be subjective, though. > > +@r2 depends on !patch exists@ > > +expression pdev,index; > > +position p; > > +@@ > > + > > +* devm_platform_get_and_ioremap_resource@p(pdev, index, NULL) > > > I doubt that the usage of the SmPL asterisk is appropriate for the operation > modes “org” and “report”. I have no idea about org and report modes. When I try these I get a python2 error message: uwe@taurus:~/gsrc/linux$ make coccicheck You have not explicitly specified the mode to use. Using default "report" mode. Available modes are the following: patch, report, context, org, chain You can specify the mode with "make coccicheck MODE=<mode>" Note however that some modes are not implemented by some semantic patches. Please check for false positives in the output before submitting a patch. When using "patch" mode, carefully review the patch before submitting it. /usr/bin/spatch -D report --no-show-diff --very-quiet --cocci-file ./scripts/coccinelle/api/alloc/alloc_cast.cocci --no-includes --include-headers --dir . -I ./arch/x86/include -I ./arch/x86/include/generated -I ./include -I ./arch/x86/include/uapi -I ./arch/x86/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi --include ./include/linux/compiler-version.h --include ./include/linux/kconfig.h --jobs 4 --chunksize 1 Py.find_library: unable to find the Python library [libpython2.7m.so returned libpython2.7m.so: cannot open shared object file: No such file or directory] [/usr/bin/../lib/libpython2.7m.so returned /usr/bin/../lib/libpython2.7m.so: cannot open shared object file: No such file or directory] [libpython2.7.so returned libpython2.7.so: cannot open shared object file: No such file or directory] [/usr/bin/../lib/libpython2.7.so returned /usr/bin/../lib/libpython2.7.so: cannot open shared object file: No such file or directory] coccicheck failed make: *** [Makefile:2076: coccicheck] Error 255 After uninstalling python2 this ends in: Cannot find Python library coccicheck failed make: *** [Makefile:2076: coccicheck] Error 255 Didn't try to debug that any further. Is that worth a bug report against coccinelle (which is shipped by my distribution)? I tried to adapt the org and report modes from other patches in the same directory. So a critical glimpse by someone more knowledgable than me is recommended. However I don't know how to react to "I doubt ... is appropriate", I'd need a more constructive feedback to act on. Best regards Uwe
> After uninstalling python2 this ends in: > > Cannot find Python library > coccicheck failed > make: *** [Makefile:2076: coccicheck] Error 255 > > Didn't try to debug that any further. Is that worth a bug report against > coccinelle (which is shipped by my distribution)? > > I tried to adapt the org and report modes from other patches in the same > directory. So a critical glimpse by someone more knowledgable than me is > recommended. However I don't know how to react to "I doubt ... is > appropriate", I'd need a more constructive feedback to act on. I'm not a python expert, so I'm not sure what to do about this python2 vs python3 problem. Is there some strategy for printing that works in both of them? julia
Hi all, On 08/11/2022 06:51, Julia Lawall wrote: > >> After uninstalling python2 this ends in: >> >> Cannot find Python library >> coccicheck failed >> make: *** [Makefile:2076: coccicheck] Error 255 >> >> Didn't try to debug that any further. Is that worth a bug report against >> coccinelle (which is shipped by my distribution)? >> >> I tried to adapt the org and report modes from other patches in the same >> directory. So a critical glimpse by someone more knowledgable than me is >> recommended. However I don't know how to react to "I doubt ... is >> appropriate", I'd need a more constructive feedback to act on. > > I'm not a python expert, so I'm not sure what to do about this python2 vs python3 problem. Is there some strategy for printing that works in both of them? It sounds like a missing dependency in the package system of the distribution. Coccinelle has been build with Python support, but some libraries are missing. Which distribution is it ? Can you install some packages that provide the two missing shared librairies ? > > julia
Hello, On Tue, Nov 08, 2022 at 08:55:04AM +0100, Nicolas Palix wrote: > On 08/11/2022 06:51, Julia Lawall wrote: > > > > > After uninstalling python2 this ends in: > > > > > > Cannot find Python library > > > coccicheck failed > > > make: *** [Makefile:2076: coccicheck] Error 255 > > > > > > Didn't try to debug that any further. Is that worth a bug report against > > > coccinelle (which is shipped by my distribution)? > > > > > > I tried to adapt the org and report modes from other patches in the same > > > directory. So a critical glimpse by someone more knowledgable than me is > > > recommended. However I don't know how to react to "I doubt ... is > > > appropriate", I'd need a more constructive feedback to act on. > > > > I'm not a python expert, so I'm not sure what to do about this python2 vs python3 problem. Is there some strategy for printing that works in both of them? > > It sounds like a missing dependency in the package system of the > distribution. Coccinelle has been build with Python support, but > some libraries are missing. > > Which distribution is it ? > Can you install some packages that provide the two missing shared librairies > ? After installing python-is-python3 (which provides a symlink /usr/bin/python -> python3) it works. This is on Debian testing. Best regards Uwe
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..401610b9a17d --- /dev/null +++ b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci @@ -0,0 +1,44 @@ +// 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) + +@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")