Coccinelle format and IRQs

Hey! The last couple of weeks have been great. I have understood and played with the format of the Coccinelle semantic patches in the kernel so lets talk about it a bit. A Coccinelle script has 4 modes of running – context, report, org and patch. The context mode just marks out the changes that will be done without actually making the changes, so a developer can checkout if some changes are unnecessary or erroneous and ignore those files/ change the Coccinelle script. Then there’s a report mode which is the most frequently used mode and it just logs a custom message which has the lines and files with the warning or error. The org mode is rarely used and also lists down the cases in a TODO format with exact line number and column positions with the modification to be done. The patch mode is the default mode and it applies the changes to the files where it detects the problem.  Soon, there will be some semantic patches developed by me in the kernel for linux developers to check out for any warnings being introduced and also to fix existing issues!

There is another major thing that came to my notice while working with shifting resource allocation to managed interfaces. The call to request_irq allocates interrupt resources and enables the interrupt line and IRQ handling. From the point this call is made your handler function may be invoked. Since the handler function must clear any interrupt the board raises, it takes care both to initialize the hardware and to set up the interrupt handler in the right order. While using managed interfaces for allocating resources we skip the corresponding functions to free the resources like kfree, free_irq etc. as the resource is freed by the devres interface on driver detachment. But there may be a race condition in the frees. There may be instances where the hardware resources are freed before interrupt resources get freed. In such cases, the interrupt handler will try accessing resources that no longer exist leading to an error. So, we need to be careful when shifting resources allocated by request_irq/request_threaded_irq to the managed devm_request_irq function.

 Here are some details of the function:
int request_irq (unsigned int irq, irq_handler_t  handler, unsigned long  irqflags, const char * devname, void * dev_id);

irq      : Interrupt line to allocate
handler  : Function to be called when the IRQ occurs
irqflags : Interrupt type flags
devname  : An ascii name for the claiming device
dev_id     : A cookie passed back to the handler function


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s