Send your first patch to Linux kernel

Useful info:

First we will have to figure out which kernel tree you should use. Usually you will have to pick up the maintainer's tree for the subsystem your patch belongs to. When in doubt use linux-next.

We will try to find and fix a small issue in the staging/ driver directory. So we will use staging.git tree.

$ git clone git://

Tools setup


# setup user name
git config --global "Green Penguin"

# setup user email
$ git config --global ""

# setup default editor
$ git config --global core.editor vim

git send-email

$ sudo apt-get install git-email

# configure git-email, add this to your ~/.gitconfig

	smtpEncryption = tls
	smtpServer =
	smtpUser =
	smtpServerPort = 587

==== Misc tools  ====

  * coccinelle

$ sudo apt-get install coccinelle </code>

  • sparse
$ sudo apt install sparse


We can use defconfig for getting a smaller kernel image.

$ make defconfig
$ make 
$ make modules

Selecting a module for compilation

Use make menuconfig and in the GUI navigate to your module. For search we can use '/' as in vim.

Compiling a module

make path/file.o

Remember to always compile to code before submitting. Maintainers will get very angry if you break kernel.

Finding things to fix


This tools checks for coding style violations. Please keep in mind that:

  • this tool can report false positives. Errors or warnings which are tolerated for old code in the kernel.
  • except for drivers/staging directory most of the maintainers are reluctant to coding style fixes.
$ $ ./scripts/ --strict -f drivers/staging/greybus/pwm.c
CHECK: Please don't use multiple blank lines
#28: FILE: drivers/staging/greybus/pwm.c:28:

Now edit drivers/staging/greybus/pwm.c and remove the extra blank line.

Fix the code and submit the patch

After you fix the code you can use git to see the difference between initial file version.

$ git diff
diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index c4bf329..ab72c9e 100644
--- a/drivers/staging/greybus/pwm.c
+++ b/drivers/staging/greybus/pwm.c
@@ -25,7 +25,6 @@ struct gb_pwm_chip {
 #define pwm_chip_to_gb_pwm_chip(chip) \
        container_of(chip, struct gb_pwm_chip, chip)
 static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
        struct gb_pwm_count_response response;
$ git status
On branch staging-testing
Your branch is up-to-date with 'origin/staging-testing'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   drivers/staging/greybus/pwm.c

Create the commit

Now it's time to create the commit, make sure you add a proper commit message:

$ git commit -s

    greybus: pwm: Remove extra blank line
    This was reported by
    Signed-off-by: Daniel Baluta <>

Create the patch

$ git format-patch -1

Where to send the patch

$ ./scripts/ 0001-greybus-pwm-Remove-extra-blank-line.patch 
L3 (open list)

Send the patch

$ git send-email --to=<maintainer1> --to=<maintainer2> --cc=<list1> --cc=<list2> 0001-greybus-pwm-Remove-extra-blank-line.patch


  • make C=1 path/to/file


so2/upstream.txt · Last modified: 2017/02/24 22:34 by daniel.baluta
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0