All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Filter out field names
@ 2016-01-21  9:47 Daniel Wagner
  2016-01-21 11:02 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Wagner @ 2016-01-21  9:47 UTC (permalink / raw)
  To: cocci

Hi,

I am trying to transform Linux kernel code in order to test for data
races. Let me illustrate this by an example


struct lpctx {
	spinlock_t lock;
	int cnt;
};
static struct lpctx *lpctx;

static void lpctx_good1(struct lpctx *lx)
{
	spin_lock(&lx->lock);

	lx->cnt++;

	spin_unlock(&lx->lock);
}

static void lpctx_warning1(struct lpctx *lx)
{
	lx->cnt++;
}


As you can see lptctx_warning1() is increasing the counter without
holding the lock. The main idea(*) is to annotate all accesses to lx by
adding a WARN_ON(!lock_is_held(&lx->lock.dep_map)).

Thanks to Julia's excellent help on IRC I have currently this somewhat
working cocci script:


@depends on patch@
struct lpctx *x;
identifier f;
statement S;
@@

( S
+	WARN_ON(!lock_is_held(&x->lock.dep_map));
&
	x->f
)


This results in:

@@ -16,10 +16,13 @@ static void lpctx_good1(struct lpctx *lx
        DBG("");

        spin_lock(&lx->lock);
+       WARN_ON(!lock_is_held(&lx->lock.dep_map));

        lx->cnt++;
+       WARN_ON(!lock_is_held(&lx->lock.dep_map));

        spin_unlock(&lx->lock);
+       WARN_ON(!lock_is_held(&lx->lock.dep_map));
 }

 static void lpctx_warning1(struct lpctx *lx)
@@ -27,6 +30,7 @@ static void lpctx_warning1(struct lpctx
        DBG("");

        lx->cnt++;
+       WARN_ON(!lock_is_held(&lx->lock.dep_map));
 }


There are a bunch of problems, e,g. the hard coded type/names or the
WARN_ON() should be put in front of the deferences but that is something
for later to improve. The main problem I face at this point is to filter
out the spin_lock() and spin_unlock() access. All my attempts didn't let
to the expected result. I think the best thing would be to match on the
type. So if 'f' is of type spinlock_t ignore it. Any ideas how this
could be expressed?

Thanks,
Daniel


(*) Talking with Nicholas over a coffee helps a lot. Thanks a lot!

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

end of thread, other threads:[~2016-02-26 12:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-21  9:47 [Cocci] Filter out field names Daniel Wagner
2016-01-21 11:02 ` Julia Lawall
2016-01-22 14:32   ` Daniel Wagner
2016-01-22 16:09   ` SF Markus Elfring
2016-02-26 10:40   ` Daniel Wagner
2016-02-26 12:40     ` SF Markus Elfring

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.