Coccinellery – Part 1

This week I’m going to talk of some of the interesting scripts I’ve found in Coccinellery.

There are A LOT of scripts in coccinellery which you can see here.

One of the first few scripts that I submitted a patch for was using badcheck.cocci. This script checks the devm_ioremap_resource error detection code. Some functions in the kernel like devm_ioremap_resource use an IS_ERR test instead of a NULL test for error detection but in many places in the kernel developers have not updated the error detection code. Excitingly, this script, if all goes well, after some required updation I will be sending to the kernel 🙂

bugon.cocci is a script that replaces an if condition and a BUG() statement with a simple BUG_ON() statement. You can see an example patch that I submitted and has been applied here.

Some functions like kmem_cache_alloc, kmem_cache_zalloc, etc have a corresponding freeing function known as kmem_cache_free; but some developers have used kfree instead of kmem_cache_free. A script to solve this issue is given here.

countptr.cocci is a script that removes an exceptional ‘&’ in front of a function name. Interestingly this one gives a lot of results in the kernel and is a good semantic patch to submit and get patches accepted. It is very easy too 🙂

Typically, we use devm_kzalloc in probe function of a driver to allocate managed resources. But sometimes, both devm_kzalloc and kzalloc are used in the probe function. This is generally an incorrect practice and devm functions should be used consistently. These inconsistencies can be found with the help of this script.

Two scripts on devm functions are given here and here which find places where freeing functions like iounmap and kfree have been used for devm_ allocated data.

There are lots of interesting scripts on devm functions and a number of opportunities to submit patches on the same.


Interesting times ahead indeed!


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s