Thanks, it works.

-------------------------------------------------------------------------------------
From: Julia Lawall
Sent: Thursday, June 28, 2012 3:44 PM
To: yafo lee
Cc: [email protected]
Subject: Re: [Cocci] How to remove a function call in the for loop

On Thu, 28 Jun 2012, yafo lee wrote:

Hi guys,
I write the following rules to remove "request_irq" from funciton
"alx_request_msix_irq":
@@
expression ret;
@@
static int alx_request_msix_irq(struct alx_adapter *adpt)
{
+ int rid = 0;
...
- ret = request_irq(...);
...
}

Use a nest: <... ...>.  ... matches a control-flow path that doesn't
contain what is before and after the ...  But when there is a loop, there
is necessarily the possibility of a call to request_irq before and after,
ie the one in the next and previous iterations of the loop.

julia


but it doesn't work for the source code:

static int alx_request_msix_irq(struct alx_adapter *adpt)
{
   irqreturn_t (*handler)(int, void *);
   int msix_idx;
   int num_msix_intrs = adpt->num_msix_intrs;
   int retval = 0;

   for (msix_idx = 0; msix_idx < num_msix_intrs; msix_idx++) {

       handler = alx_msix_rtx;

       retval = request_irq(adpt->msix_entries[msix_idx].vector,
            handler, 0, msix->name, msix);

       if (retval)
           return retval;
   }

   return 0;
}


it only works when I move the "request_irq" call out of the for loop:

static int alx_request_msix_irq(struct alx_adapter *adpt)
{
   irqreturn_t (*handler)(int, void *);
   int msix_idx;
   int num_msix_intrs = adpt->num_msix_intrs;
   int retval = 0;

   handler = alx_msix_rtx;
   retval = request_irq(adpt->msix_entries[msix_idx].vector,
       handler, 0, msix->name, msix);

   for (msix_idx = 0; msix_idx < num_msix_intrs; msix_idx++) {
       if (retval)
           return retval;
   }

   return 0;
}

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)


_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to