linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] coccinelle: reduce false positives
@ 2018-02-01  9:48 Julia Lawall
  2018-02-01 10:25 ` Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Julia Lawall @ 2018-02-01  9:48 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: kernel-janitors, Gilles Muller, Nicolas Palix, Michal Marek,
	cocci, linux-kernel

Some files use both a non-devm allocation and a devm_allocation.  Don't
complain about a free when the same function contains a non-devm
allocation.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 scripts/coccinelle/free/devm_free.cocci |   55 +++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci
index c990d2c..b2a2cf8b 100644
--- a/scripts/coccinelle/free/devm_free.cocci
+++ b/scripts/coccinelle/free/devm_free.cocci
@@ -56,9 +56,62 @@ expression x;
  x = devm_ioport_map(...)
 )
 
+@safe depends on context || org || report exists@
+expression x;
+position p;
+@@
+
+(
+ x = kmalloc(...)
+|
+ x = kvasprintf(...)
+|
+ x = kasprintf(...)
+|
+ x = kzalloc(...)
+|
+ x = kmalloc_array(...)
+|
+ x = kcalloc(...)
+|
+ x = kstrdup(...)
+|
+ x = kmemdup(...)
+|
+ x = get_free_pages(...)
+|
+ x = request_irq(...)
+|
+ x = ioremap(...)
+|
+ x = ioremap_nocache(...)
+|
+ x = ioport_map(...)
+)
+...
+(
+ kfree@p(x)
+|
+ kzfree@p(x)
+|
+ __krealloc@p(x, ...)
+|
+ krealloc@p(x, ...)
+|
+ free_pages@p(x, ...)
+|
+ free_page@p(x)
+|
+ free_irq@p(x)
+|
+ iounmap@p(x)
+|
+ ioport_unmap@p(x)
+)
+
 @pb@
 expression r.x;
-position p;
+position p != safe.p;
 @@
 
 (

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] coccinelle: reduce false positives
  2018-02-01  9:48 [PATCH] coccinelle: reduce false positives Julia Lawall
@ 2018-02-01 10:25 ` Dan Carpenter
  2018-02-01 11:06   ` Julia Lawall
  2018-02-01 12:28 ` Coccinelle: " SF Markus Elfring
  2018-02-07 15:15 ` [PATCH] coccinelle: " Masahiro Yamada
  2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2018-02-01 10:25 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Masahiro Yamada, kernel-janitors, Gilles Muller, Nicolas Palix,
	Michal Marek, cocci, linux-kernel

On Thu, Feb 01, 2018 at 10:48:52AM +0100, Julia Lawall wrote:
> Some files use both a non-devm allocation and a devm_allocation.  Don't
> complain about a free when the same function contains a non-devm
> allocation.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 

That's surprising...  Do you have an example false positive?

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] coccinelle: reduce false positives
  2018-02-01 10:25 ` Dan Carpenter
@ 2018-02-01 11:06   ` Julia Lawall
  2018-02-01 11:16     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-02-01 11:06 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Masahiro Yamada, kernel-janitors, Gilles Muller, Nicolas Palix,
	Michal Marek, cocci, linux-kernel

Here are the results that are eliminated by my change:

drivers/clk/axs10x/pll_clock.c:323:1-6 kfree(pll_clk);
drivers/clk/clk-gpio.c:131:2-7 kfree(clk_gpio);
drivers/clk/clk-hsdk-pll.c:410:1-6 kfree(pll_clk);
drivers/clk/hisilicon/clk.c:97:1-6 kfree(clk_data);
drivers/mfd/syscon.c:130:1-8 iounmap(base);
drivers/mfd/syscon.c:132:1-6 kfree(syscon);
drivers/pinctrl/freescale/pinctrl-mxs.c:139:2-7 kfree(group);
drivers/pinctrl/samsung/pinctrl-exynos5440.c:264:1-6 kfree(gname);
drivers/platform/chrome/cros_ec_debugfs.c:248:1-6 kfree(msg);
drivers/pwm/pwm-lp3943.c:56:3-8 kfree(pwm_map);

The semantic patch is pretty naive in that it assumes that all uses of the
same name point to the same thing.

Looking through the code, it looks like sometimes both an __init and a
probe function are provided, and the __init function doesn't have access to
a device object.

julia

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] coccinelle: reduce false positives
  2018-02-01 11:06   ` Julia Lawall
@ 2018-02-01 11:16     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2018-02-01 11:16 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Masahiro Yamada, kernel-janitors, Gilles Muller, Nicolas Palix,
	Michal Marek, cocci, linux-kernel

On Thu, Feb 01, 2018 at 12:06:35PM +0100, Julia Lawall wrote:
> Here are the results that are eliminated by my change:
> 
> drivers/clk/axs10x/pll_clock.c:323:1-6 kfree(pll_clk);
> drivers/clk/clk-gpio.c:131:2-7 kfree(clk_gpio);
> drivers/clk/clk-hsdk-pll.c:410:1-6 kfree(pll_clk);
> drivers/clk/hisilicon/clk.c:97:1-6 kfree(clk_data);
> drivers/mfd/syscon.c:130:1-8 iounmap(base);
> drivers/mfd/syscon.c:132:1-6 kfree(syscon);
> drivers/pinctrl/freescale/pinctrl-mxs.c:139:2-7 kfree(group);
> drivers/pinctrl/samsung/pinctrl-exynos5440.c:264:1-6 kfree(gname);
> drivers/platform/chrome/cros_ec_debugfs.c:248:1-6 kfree(msg);
> drivers/pwm/pwm-lp3943.c:56:3-8 kfree(pwm_map);
> 
> The semantic patch is pretty naive in that it assumes that all uses of the
> same name point to the same thing.
> 

Huh...  It leads to false positives but it is an easier way to do cross
function analysis.  I had wondered about that.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Coccinelle: reduce false positives
  2018-02-01  9:48 [PATCH] coccinelle: reduce false positives Julia Lawall
  2018-02-01 10:25 ` Dan Carpenter
@ 2018-02-01 12:28 ` SF Markus Elfring
  2018-02-07 15:15 ` [PATCH] coccinelle: " Masahiro Yamada
  2 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2018-02-01 12:28 UTC (permalink / raw)
  To: cocci, Julia Lawall; +Cc: LKML, kernel-janitors, Masahiro Yamada

> +@safe depends on context || org || report exists@
> +expression x;
> +position p;
> +@@
> +
> +(
> + x = kmalloc(...)
> +|
> + x = kvasprintf(...)
…

* How do you think about to reduce also a bit of duplicate SmPL code?

* Can it help to work with nested SmPL disjunctions here?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] coccinelle: reduce false positives
  2018-02-01  9:48 [PATCH] coccinelle: reduce false positives Julia Lawall
  2018-02-01 10:25 ` Dan Carpenter
  2018-02-01 12:28 ` Coccinelle: " SF Markus Elfring
@ 2018-02-07 15:15 ` Masahiro Yamada
  2 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-02-07 15:15 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Gilles Muller, Nicolas Palix, Michal Marek,
	cocci, Linux Kernel Mailing List

2018-02-01 18:48 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
> Some files use both a non-devm allocation and a devm_allocation.  Don't
> complain about a free when the same function contains a non-devm
> allocation.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>  scripts/coccinelle/free/devm_free.cocci |   55 +++++++++++++++++++++++++++++++-
>  1 file changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci
> index c990d2c..b2a2cf8b 100644
> --- a/scripts/coccinelle/free/devm_free.cocci
> +++ b/scripts/coccinelle/free/devm_free.cocci
> @@ -56,9 +56,62 @@ expression x;
>   x = devm_ioport_map(...)
>  )
>
> +@safe depends on context || org || report exists@
> +expression x;
> +position p;
> +@@
> +
> +(
> + x = kmalloc(...)
> +|
> + x = kvasprintf(...)
> +|
> + x = kasprintf(...)
> +|
> + x = kzalloc(...)
> +|
> + x = kmalloc_array(...)
> +|
> + x = kcalloc(...)
> +|
> + x = kstrdup(...)
> +|
> + x = kmemdup(...)
> +|
> + x = get_free_pages(...)
> +|
> + x = request_irq(...)
> +|
> + x = ioremap(...)
> +|
> + x = ioremap_nocache(...)
> +|
> + x = ioport_map(...)
> +)
> +...
> +(
> + kfree@p(x)
> +|
> + kzfree@p(x)
> +|
> + __krealloc@p(x, ...)
> +|
> + krealloc@p(x, ...)
> +|
> + free_pages@p(x, ...)
> +|
> + free_page@p(x)
> +|
> + free_irq@p(x)
> +|
> + iounmap@p(x)
> +|
> + ioport_unmap@p(x)
> +)
> +
>  @pb@
>  expression r.x;
> -position p;
> +position p != safe.p;
>  @@
>
>  (
>

Anyway, it looks like
this patch makes the situation better.


Applied to linux-kbuild/kbuild.  Thanks!


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-07 15:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01  9:48 [PATCH] coccinelle: reduce false positives Julia Lawall
2018-02-01 10:25 ` Dan Carpenter
2018-02-01 11:06   ` Julia Lawall
2018-02-01 11:16     ` Dan Carpenter
2018-02-01 12:28 ` Coccinelle: " SF Markus Elfring
2018-02-07 15:15 ` [PATCH] coccinelle: " Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).