From: Julia Lawall <julia.lawall@lip6.fr>
To: Wen Yang <wen.yang99@zte.com.cn>
Cc: wang.yi59@zte.com.cn, michal.lkml@markovi.net,
nicolas.palix@imag.fr, linux-kernel@vger.kernel.org,
cocci@systeme.lip6.fr
Subject: Re: [Cocci] [PATCH] coccinelle: semantic patch for missing of_node_put
Date: Fri, 15 Mar 2019 08:29:49 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.1903150824150.3668@hadrien> (raw)
In-Reply-To: <1552616681-17985-1-git-send-email-wen.yang99@zte.com.cn>
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 <Julia.Lawall@lip6.fr>
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Reviewed-by: Julia Lawall <Julia.Lawall@lip6.fr>
> ---
> 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
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia.lawall@lip6.fr>
To: Wen Yang <wen.yang99@zte.com.cn>
Cc: wang.yi59@zte.com.cn, Gilles Muller <Gilles.Muller@lip6.fr>,
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
Date: Fri, 15 Mar 2019 08:29:49 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.1903150824150.3668@hadrien> (raw)
In-Reply-To: <1552616681-17985-1-git-send-email-wen.yang99@zte.com.cn>
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 <Julia.Lawall@lip6.fr>
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Reviewed-by: Julia Lawall <Julia.Lawall@lip6.fr>
> ---
> 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
>
>
next prev parent reply other threads:[~2019-03-15 7:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 2:24 [Cocci] [PATCH] coccinelle: semantic patch for missing of_node_put Wen Yang
2019-03-15 2:24 ` Wen Yang
2019-03-15 7:29 ` Julia Lawall [this message]
2019-03-15 7:29 ` Julia Lawall
2019-03-15 16:24 ` [Cocci] " Markus Elfring
2019-03-15 16:24 ` Markus Elfring
2019-03-15 16:24 ` Markus Elfring
-- strict thread matches above, loose matches on Subject: below --
2019-05-07 8:12 [Cocci] " Wen Yang
2019-05-07 15:27 ` Markus Elfring
2019-05-09 1:47 ` wen.yang99
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.21.1903150824150.3668@hadrien \
--to=julia.lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=nicolas.palix@imag.fr \
--cc=wang.yi59@zte.com.cn \
--cc=wen.yang99@zte.com.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.