Process of creating first patch

So this blog pretty much covers everything about the process and commands which I follow for the practical session of my Linux kernel first patch workshop.

I usually prefer to go for the simple syntax errors [suggested by] for the first patch practice. Also, usually it’s a good idea to send clean up patches for the files in staging directory only. Specifically when you are newbie and sending a patch in a kernel for the 1st time.

Note that this is just a list of commands, for more detailed versions and things I explained, you can refer to the slides and first patch tutorial. Also, make sure to run all of these commands under the source code directory of the Linux kernel and where Makefile resides. Do not run these commands under specific directories.

Step 1:

Run over the directory of your choice under the staging to edit a file.

perl scripts/ -f drivers/staging/media/bcm2048/* | less

Step 2:

Check the code. Use following command to see who did that change and why. This is
useful in a practice to understand the approach of a code author.

git blame -L x,y file_path.c // x,y specifies the Line numbers

e.x  git blame -L 30,32 filr_path.c 

This will give you a list of commits. You can use ‘git show <commit id>’ to check the
whole commit.

Step 3:

Once done with changing the code, compile the file. It should produce the .o file without any errors.

make file_path.o

Sometimes you may want to run ‘make file_path/’. For example, you can run ‘make drivers/staging/media/bcm2048/’ .

Step 4:

If the file successfully compiles then go for creating a patch. For that, first
add your changes in a git.

Git add <file_path>

Step 5:

Now, create a commit.

Git commit -s -v

-s adds signed off by line and -v adds git diff in the commit you are creating.
You can read about the patch philosophy over here. For the patch best practices, refer to patch philosophy.

Step 6:

Create a patch now.

Git format-patch -o /tmp/ HEAD^

This will give you temporary .patch file. ex.

Step 7:

In the LKML, we prefer that new patches should not introduce any syntax warnings.
So, run over your temp .patch file. And solve sytax errors if there
are any.

scripts/ <.patch file>

Step 8:

Get the list of maintainers and mailing lists to send that patch.

git show HEAD | perl scripts/ –separator , –nokeywords –nogit –nogit-fallback –norolestats –nol

Step 9:

Send the patch using git send-email.

git send-email –to= –cc= <.patch file>

To setup git send-email you can go for this blog post.

Also, few other commands which I use while giving first patch workshops are here:

To check the modified file:

git status and git diff

To check the commit after creating it.

git log

I’ll write separate posts explaining what to do when going for the v2 of the


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