Road to making our first patch to linux iio
Our group in MAC0470 (Free Software Development) have just finished our first contribution patch to Kernel. In this blog post we will talk about what we did and how our experience was during this process.
Finding a patch to contribute
There are many things one can do to contribute to the Kernel. But the difficulty level of a contribution can scale from just making naive code-styling corrections or warning suppressions to doing real obscure bugs fixing and new drivers and modules creation.
We met in the middle, choosing to use device_for_each_child_node_scoped()
to simplify error handling and avoid bugs. Some drivers iterate over firmware nodes (struct fwnode_handle
) and increment (_get
) a reference for the firmware node while iterating. Ending the loop early (either because it doesn’t need to iterate until the end or due to error) requires the driver to release (_put
) the node reference which is a source of potential bugs if a future patch is not careful about node release. Using device_for_each_child_node_scoped()
helps mitigate such bugs while potentially making error handling code cleaner.
In other words, we used the available kernel macro that has the main goal to ease the iteration between firmware nodes by simplifying the error handling in loops early exits and also avoiding possible bugs.
What does it mean to be a “scoped” macro
The macro we are talking about is evice_for_each_child_node_scoped()
which was first introduced on the commit 365130fd47af
. This new scoped version removes the necessity of doing manual calls of fwnode_handle_put()
during the code that might leave the loop in advance.
Even though this new macro was accepted and introduced to the kernel for quite a long time, there are many drivers that still uses the older version.
Given this, it is a good opportunity to refactor the code in a few files to get in touch with the patches submission. Especifically, we modified this driver: drivers/iio/adc/ti-ads1015.c
.
As you can observe on the above image, by using this macro, we can remove the fwnode_handle_put()
calls. With this, we are avoiding possible future modification bugs to occur in case any developer forgets to add this call in loops early exits. Standardizing this macro usage, instead of the older version, also makes life easier for the future developer that will work with kernel drivers.
Patch creation and submission
With the proper modifications done, we wrote the following commit
message and properly signed a message as shown below:
After that, we used our own git to create and send the patch to the teaching assistants of the discipline
$ git format-patch –to=<EMAIL> HEAD~1
$ git send-email *.patch
Next step
After the approval of the TA’s we can then send our contribution to the kernel maintainers.
See you on the next post
Written by Lincoln Yuji, Luiza Soezima and Sabrina Araújo
Enjoy Reading This Article?
Here are some more articles you might like to read next: