mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrzej Hajda <a.hajda@samsung.com>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Andrzej Hajda <a.hajda@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <mmarek@suse.com>,
	cocci@systeme.lip6.fr (moderated list:COCCINELLE/Semantic
	Patches (SmPL)),
	linux-kernel@vger.kernel.org
Subject: [PATCH] coccinelle: memdup.cocci: fix matching rules
Date: Thu, 06 Aug 2015 14:14:14 +0200	[thread overview]
Message-ID: <1438863254-19897-1-git-send-email-a.hajda@samsung.com> (raw)

This patch fixes three things, listed in order of importance.
1. Removes matching of kmemdup from !patch rule - it is incorrect and
in fact makes report mode unusable.
2. Adds unlikely to if clause. It allows to match more cases - the ones with
unlikely and the ones without it.
3. Fixes report message.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
Hi Julia,

I guess 1st and 3rd changes are OK. I am not sure about 2nd change, without
it I was not able to catch cases containing unlikely macro. For example
fs/ntfs/dir.c:1175:
  ir = kmalloc(rc, GFP_NOFS);
  if (unlikely(!ir)) {
    err = -ENOMEM;
    goto err_out;
  }
  /* Copy the index root value (it has been verified in read_inode). */
  memcpy(ir, (u8*)ctx->attr +
    le16_to_cpu(ctx->attr->data.resident.value_offset), rc);

It seems quite strange for me, as these rules looks to me isomorphic.
Is this expected behavior of coccinelle or just some bug?

After this fix, cocci finds 46 places to patch, I will send patchset if this
change looks OK to you.

I have used:
spatch version 1.0.1 with Python support and with PCRE support
latest linux-next.

Regards
Andrzej
---
 scripts/coccinelle/api/memdup.cocci | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci
index 3d1aa71..2297205 100644
--- a/scripts/coccinelle/api/memdup.cocci
+++ b/scripts/coccinelle/api/memdup.cocci
@@ -39,7 +39,7 @@ statement S;
 
 -  to = \(kmalloc@p\|kzalloc@p\)(size,flag);
 +  to = kmemdup(from,size,flag);
-   if (to==NULL || ...) S
+   if (unlikely(to==NULL) || ...) S
 -  memcpy(to, from, size);
 
 @r depends on !patch@
@@ -49,18 +49,17 @@ statement S;
 @@
 
 *  to = \(kmalloc@p\|kzalloc@p\)(size,flag);
-   to = kmemdup(from,size,flag);
-   if (to==NULL || ...) S
+   if (unlikely(to==NULL) || ...) S
 *  memcpy(to, from, size);
 
 @script:python depends on org@
 p << r.p;
 @@
 
-coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdep")
+coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdup")
 
 @script:python depends on report@
 p << r.p;
 @@
 
-coccilib.report.print_report(p[0], "WARNING opportunity for kmemdep")
+coccilib.report.print_report(p[0], "WARNING opportunity for kmemdup")
-- 
1.9.1


             reply	other threads:[~2015-08-06 12:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-06 12:14 Andrzej Hajda [this message]
2015-08-06 13:37 ` [Cocci] " Nicholas Mc Guire
2015-08-06 13:58   ` Julia Lawall
2015-08-06 14:37 ` Julia Lawall

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=1438863254-19897-1-git-send-email-a.hajda@samsung.com \
    --to=a.hajda@samsung.com \
    --cc=Gilles.Muller@lip6.fr \
    --cc=Julia.Lawall@lip6.fr \
    --cc=b.zolnierkie@samsung.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mmarek@suse.com \
    --cc=nicolas.palix@imag.fr \
    /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®