Interesting scripts and points encountered

These days I have been working with some Coccinelle semantic patches and fixing different bugs.
I have used a simple semantic patch to transform cases of if(expression) BUG() to BUG_ON(expression).
Here is the Coccinelle script for it:

expression e;
-if (e) BUG();

I have worked with some patches that correct the argument to a memory allocation function when the allocated data is a double pointer and erroneously the elements are sizeof the struct instead of pointer. I have hardened the semantic patch with all four modes. Here is the basic patch for the transformation:

@disable sizeof_type_expr@
type T;
T **x;

x =

– T
+ *x

I have also had some patches fixing bugs involving converting !x & y to !(x & y). The semantic patch used for it is:

@@ expression E1,E2; @@
!E1 & !E2
– !E1 & E2
+ !(E1 & E2)

I had added a managed interface devm_gpio_request_array which allocates multiple GPIOs in a single call in a managed manner but the function addition was already in queue. It was however fun coding up my first devm function :P.

Many unmanaged to managed interface conversion patches have been applied :). Also, I learnt an important point while introducing managed interfaces in the ASoC driver. Using the managed functions within the ASoC level probe functions doesn’t work as devm_ is only usable as part of the driver model binding and unbinding. All the resource allocation needs to be moved into the device level probe (which is a better thing anyway) before it is converted to devm. So, I set out to analyze the various types of probe functions to find which probe functions already use devm. A list of the various probe functions using devm functions and having possibilities of some conversions was made using Coccinelle. Also, I am looking at some uses of managed interfaces in the remove functions understanding the usage as it is a bit stange.

Thanks Julia and the awesome Linux community for being the best mentors and guides and letting me experiment and learn SOOO much 🙂


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