From: Julia Lawall <julia.lawall@lip6.fr>
To: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
nicolas.palix@imag.fr, mmarek@suse.com, cocci@systeme.lip6.fr,
linux-kernel@vger.kernel.org, wsa@the-dreams.de
Subject: Re: [PATCH v2] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource
Date: Mon, 25 Jul 2016 10:50:28 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1607251047060.3293@hadrien> (raw)
In-Reply-To: <20160725082120.GA5055@amitoj-Inspiron-3542>
On Mon, 25 Jul 2016, Amitoj Kaur Chawla wrote:
> This script detects cases which have incorrect error handling for
> devm_ioremap_resource function, employing a NULL test instead of an
> IS_ERR() test.
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
> ---
> Changes in v2:
> -Changed script to correct error handling instead of just
> detecting cases of incorrect error handling
>
> .../null/devm_ioremap_resource_test.cocci | 66 ++++++++++++++++++++++
> 1 file changed, 66 insertions(+)
> create mode 100644 scripts/coccinelle/null/devm_ioremap_resource_test.cocci
>
> diff --git a/scripts/coccinelle/null/devm_ioremap_resource_test.cocci b/scripts/coccinelle/null/devm_ioremap_resource_test.cocci
> new file mode 100644
> index 0000000..671970a
> --- /dev/null
> +++ b/scripts/coccinelle/null/devm_ioremap_resource_test.cocci
> @@ -0,0 +1,66 @@
> +/// Correct error handling for devm_ioremap_resource
> +///
> +// Confidence: High
> +// Copyright: (C) 2016 Amitoj Kaur Chawla
> +// Keywords: devm, devm_ioremap_resource
> +
> +virtual patch
> +virtual context
> +virtual org
> +virtual report
> +
> +@err depends on patch && !context && !org && !report@
> +expression e,e1;
> +@@
> +
> + e = devm_ioremap_resource(...);
> + if(
> +- e == NULL
> ++ IS_ERR(e)
> + )
> + {
> + ...
> + return
> +- e1
> ++ PTR_ERR(e)
> + ;
> + }
Sorry not to have thought about this earlier, but this rule is going to
cause problems. The ... return e1; hops over any gotos in the if branch.
So it could end up at the return at the end of the function, which might
be reachable from places in which e is not defined in the way expected.
This is likely to result in an error about modifying inconsistent paths.
The rule could be made more complicated to protect against this issue, but
given that the problem found by this semantic patch is now rare in the
first place, perhaps it is not worth it. People can just make the change
by hand based on the report, and we can just use the original version of
the semantic patch.
julia
> +// ----------------------------------------------------------------------------
> +
> +@err_context depends on !patch && (context || org || report)@
> +expression e, e1;
> +position j0, j1;
> +@@
> +
> + e@j0 = devm_ioremap_resource(...);
> + if(
> +* e == NULL
> + )
> + {
> + ...
> + return
> +* e1@j1
> + ;
> + }
> +
> +// ----------------------------------------------------------------------------
> +
> +@script:python err_org depends on org@
> +j0 << err_context.j0;
> +j1 << err_context.j1;
> +@@
> +
> +msg = "Incorrect error handling."
> +coccilib.org.print_todo(j0[0], msg)
> +coccilib.org.print_link(j1[0], "")
> +
> +// ----------------------------------------------------------------------------
> +
> +@script:python err_report depends on report@
> +j0 << err_context.j0;
> +j1 << err_context.j1;
> +@@
> +
> +msg = "Incorrect error handling around line %s." % (j1[0].line)
> +coccilib.report.print_report(j0[0], msg)
> --
> 1.9.1
>
>
prev parent reply other threads:[~2016-07-25 8:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-25 8:21 Amitoj Kaur Chawla
2016-07-25 8:50 ` Julia Lawall [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.10.1607251047060.3293@hadrien \
--to=julia.lawall@lip6.fr \
--cc=Gilles.Muller@lip6.fr \
--cc=amitoj1606@gmail.com \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.com \
--cc=nicolas.palix@imag.fr \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®