cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Itterating matches
@ 2020-11-28  5:41 Ira Weiny
  2020-11-28  7:55 ` Julia Lawall
       [not found] ` <13b5bbf1-4dda-9dc2-46cd-a98e71537769@web.de>
  0 siblings, 2 replies; 7+ messages in thread
From: Ira Weiny @ 2020-11-28  5:41 UTC (permalink / raw)
  To: cocci

I have been looking for a way to help automate my kmap/mem*/kunmap
transformation.[1]  I'm very new to coccinelle and I'm having some trouble.

I have tried to build up a script[2][3] to do this while also learning coccinelle
but I'm not getting a couple of points.

1) How do I get matches to iterate?
	1a) What is the difference between '<+... ...+>' and '<... ...>'?
2) Why can't I get the type declaration (type VP;) matched correctly.  It works
   some times but not always.  It also matches a lot of random declarations?
	2a) and for some reason in the more advanced script[3] it completely
	    breaks.  Which is very confusing because fundamentally it does not
            seem to be any different from [2]?

Any advice is appreciated.

Thanks,
Ira

[1] https://lore.kernel.org/lkml/20201124141244.GE17322@twin.jikos.cz/

[2]
<script>
  1 @ rule0 @
  2 type VP;
  3 identifier ptr;
  4 identifier page;
  5 @@
  6 
  7 -VP ptr;
  8 <...
  9 (
 10 -ptr = kmap(page);
 11 |
 12 -ptr = kmap_atomic(page);
 13 )
 14 <+...
 15 (
 16 -memset(...);
 17 +memIra();
 18 |
 19 -memcpy(...);
 20 +memIra();
 21 )
 22 ...+>
 23 (
 24 -kunmap(page);
 25 |
 26 -kunmap_atomic(ptr);
 27 )
 28 ...>
</script>

[3]
<script>
  1 @ rule0 @
  2 type VP;
  3 identifier page;
  4 identifier ptr;
  5 expression V;
  6 expression L;
  7 expression T;
  8 expression F;
  9 expression B;
 10 expression Off;
 11 @@
 12 
 13 -VP ptr;
 14 <...
 15 (
 16 -ptr = kmap(page);
 17 |
 18 -ptr = kmap_atomic(page);
 19 )
 20 <...
 21 (
 22 -memset(ptr, 0, L); 
 23 +zero_user(page, 0, L);
 24 |
 25 -memset(ptr + Off, 0, L);
 26 +zero_user(page, Off, L);
 27 |
 28 -memset(ptr, V, L);
 29 +memset_page(page, V, 0, L);
 30 |
 31 -memset(ptr + Off, V, L);
 32 +memset_page(page, V, Off, L);
 33 |
 34 -memcpy(ptr + Off, F, B);
 35 +memcpy_to_page(page, Off, F, B);
 36 |
 37 -memcpy(ptr, F, B);
 38 +memcpy_to_page(page, 0, F, B);
 39 |
 40 -memcpy(T, ptr + Off, B);
 41 +memcpy_from_page(T, page, Off, B);
 42 |
 43 -memcpy(T, ptr, B);
 44 +memcpy_from_page(T, page, 0, B);
 45 )
 46 ...>
 47 (
 48 -kunmap(page);
 49 |
 50 -kunmap_atomic(ptr);
 51 )
 52 ...>
</script>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2020-12-01 10:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-28  5:41 [Cocci] Itterating matches Ira Weiny
2020-11-28  7:55 ` Julia Lawall
2020-11-30 19:19   ` Ira Weiny
2020-11-30 19:59     ` Julia Lawall
2020-11-30 21:06       ` Ira Weiny
2020-12-01 10:06         ` Julia Lawall
     [not found] ` <13b5bbf1-4dda-9dc2-46cd-a98e71537769@web.de>
2020-11-30 22:48   ` [Cocci] Automating a kmap/mem*/kunmap transformation Ira Weiny

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).