On Tue, Nov 01, 2011 at 09:07:14AM +0100, Julia Lawall wrote:
> On Mon, 31 Oct 2011, Russell King wrote:
>
> > Is there a neater way to write this:
> >
> > @ rule1 @
> > identifier fn;
> > @@
> > arch_reset = fn;
> > @@
> > identifier rule1.fn, mode, cmd;
> > @@
> > void fn(char mode, const char *cmd)
> > {
> > ...
> > - local_irq_disable();
> > ...
> > }
> > @@
> > identifier mode, cmd;
> > @@
> > arch_reset(char mode, const char *cmd)
> > {
> > ...
> > - local_irq_disable();
> > ...
> > }
> >
> > The idea is to remove calls to local_irq_disable() inside any function
> > to do with the arch_reset(). Some ARM platforms define this as an inline
> > function, others define arch_reset() as a pointer, and assign some other
> > function to that pointer.
> >
> > I'm wondering whether there's a way to express both conditions with
> > the 'fn' identifier above.
>
> No, I don't think so. For your
>
> ...
> - local_irq_disable();
> ...
>
> put instead:
>
> <...
> - local_irq_disable();
> ...>
>
> Then you will remove all of the calls. In your version, it would actually
> remove a call in the case where there is exactly one, because ... takes
> the shortest path between something that matches what is before and what
> is after.
Thanks.
> You don't want to do anything with local_irq_enable?
The function shouldn't be calling local_irq_enable() (it's already called
with IRQs disabled, and people tend to add new calls to disable IRQs.)
The next thing I want to do is add a call to setup_restart() to each of
the arch_reset() functions. I've not yet found a way to tell coccinelle
to add the call after any local variable declarations. My last try was:
@@
identifier m, c, a;
type t;
@@
arch_reset(char m, const char *c)
{
t a;
+setup_restart(m);
...
}
@@
identifier m, c;
@@
arch_reset(char m, const char *c)
{
+setup_restart(m);
...
}
This produces:
static void arch_reset(char mode, const char *cmd)
{
+ setup_restart(mode);
if (mode == 's') {
/* Jump into ROM at address 0 */
cpu_reset(0);
but also:
void arch_reset(char mode, const char *cmd)
{
+ setup_restart(mode);
short temp;
+ setup_restart(mode);
/* Reset the Machine via pc[3] of the sequoia chipset */
outw(0x09,0x24);
temp=inw(0x26);
which is wrong. Again, can this be written as one rule?
--
Russell King
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)