
Recall first from How the kernel is developed
- Subsystem maintainers review and collect changes in Git trees for integration into mainline.
- linux-next combines selected branches so maintainers can detect integration problems before they affect mainline.
- The merge window ends at rc1, and the following release candidates focus on fixes.
Find the source and the submission list
3 min readThe last lesson explained the development cycle. This lesson answers how to contribute to it, with git format-patch, a proper commit message with Signed-off-by, and the DCO.
A mail client can wrap a long line or alter whitespace in a diff. The email may still look readable while the patch fails to apply. The kernel's email client documentation describes these problems. Preparing the message with Git gives you a file you can inspect and apply locally before it reaches a public list.
Kernel submissions go to the maintainers and mailing lists for the affected code. A mailing list distributes the message to its subscribers. At lore.kernel.org, you can read archived messages from many kernel lists, including the replies to a submission. Search for the affected driver, a function name, or the subject prefix you see in Git history. Reading recent messages for that area shows how contributors name changes and which lists receive them. The archive is public, so read the addresses and contents of your outgoing message with that audience in mind.
git.kernel.org hosts the mainline kernel repository and subsystem repositories. For a fresh mainline checkout, run the following commands. You can use an existing kernel clone for this lesson and inspect its sources on Ubuntu 24.04 regardless of the kernel your machine is running.
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
Before preparing a real submission, read the relevant entry in the source tree's MAINTAINERS file. Its F: entries describe paths covered by the entry, M: identifies maintainers, L: identifies mailing lists, and T: can identify a source tree. Read the entry and any linked submission instructions to choose the branch on which to base your change. The base is the commit immediately before your own commits. A patch generated against the wrong base may need edits before it can be applied, even when the intended change is small.
Create a topic branch from the chosen base. Give each commit one logical change so that a reader can understand and apply it on its own. If a driver fix also prompts you to reformat unrelated functions, leave those functions out of the fix. Before committing, read Documentation/process/coding-style.rst in the tree. For C changes, the guide specifies tabs for indentation with eight-column tab stops, and the opening brace of a function definition goes on the next line. Look at the surrounding code for local naming and layout. Use git diff --check to catch whitespace errors in unstaged changes, then git diff --cached to inspect what you have staged. A clean whitespace check says little about whether the change works, so build or test the affected code as appropriate and record what you actually ran.
Write the commit message and sign off
4 min readThe subject should name the affected area and state the action in the imperative. Read the subjects in that area's Git history to choose a prefix. For example, iio: adc: Return read error before using sample identifies the subsystem and explains the requested change. Fix ADC bug leaves the reader to find both details in the diff. Keep the subject short enough to scan in a list of patches. When you export the commit, Git supplies the [PATCH] marker for the email subject.
Leave a blank line after the subject. In the body, describe the conditions that expose the problem, the observable effect, and how the change addresses the cause. Think about the reader who finds this commit later without the original email thread or test setup. If a failure requires a specific device state or configuration, name it. For a measured result, include the test conditions and observed result when they matter to the explanation.
iio: adc: Return read error before using sample
When the register read fails, the caller can still consume the sample
value. Return the read error before copying the value so the caller
receives the failure and can discard the sample.
This example illustrates the shape of a message. In a real one, use the actual failure path and the actual consequence. Include test details when they help a reader assess the change. For example, identify the affected board and the scenario exercised if you tested on hardware. A build and a hardware test answer different questions, so describe the result of each test you performed.
At the end of the message, use a structured line such as Signed-off-by: Name <email> at the end of a commit message. Each trailer makes a specific statement:
Signed-off-by:records your certification under the Developer Certificate of Origin, or DCO. Read the certificate in the kernel submission guide before signing. It covers your right to submit a contribution you created, appropriately licensed work you can submit under its terms, or a contribution received directly from someone who certified it and which you have left unmodified. It also acknowledges that the contribution record, including the personal information you submit, is public and may be kept indefinitely.Fixes:identifies the commit that introduced the problem. Use the first 12 hexadecimal characters of that commit's ID followed by its original subject in parentheses and double quotes. Rungit log -1 --format='Fixes: %h ("%s")' --abbrev=12 COMMIT, replacingCOMMITwith the verified introducing commit, and check the result against the history. If you cannot establish the introducing commit, leave the trailer out.Reported-by:credits the person who reported the problem. Use their name and email address. Get permission before publishing their details if their report was private. When a public report exists, aCloses:trailer with its URL can also record where the issue was reported.Cc:records someone who should receive a copy, such as a contributor familiar with the affected code. The mail message has its ownCcheader.git send-emailcan pick up addresses fromCc:lines in the patch body, depending on its options and configuration. Confirm the actual recipients when you preview the message.
When your change is staged, check git config user.name and git config user.email. Use the name you use to identify yourself and an email address suitable for a public contribution. Run git commit -s to open the editor and have Git add your Signed-off-by: trailer. The option inserts that line using your committer identity. The certification comes from you. If you revise the message with git commit --amend, inspect the final result with git log -1 and check both the attribution and the sign-off before exporting.
Export, verify, and send the patch
3 min readgit format-patch writes committed changes as email messages. Each patch includes the commit's subject, author information, message, and diff. For a single commit at HEAD, the following commands create a fresh output directory and export the patch there. Run them from the repository root after committing.
patch_dir=$(mktemp -d)
git format-patch -1 HEAD -o "$patch_dir"
Read the generated .patch file. Check the subject, body, trailers, and changed paths. If the message or diff needs a correction, amend the commit and generate a fresh patch. For multiple commits, git format-patch -o "$patch_dir" BASE..HEAD exports the commits reachable from HEAD after excluding those reachable from BASE. Replace BASE with the base commit or ref and use a fresh output directory for the series. Git numbers the patch files in the series so readers can apply them in order.
git am reads an email patch, applies its diff, and creates a commit with the author's information and the commit message. Verify the single-patch export on its original base in a disposable worktree. Do this in the same shell so that patch_dir still points to the generated file.
verify_root=$(mktemp -d)
git worktree add --detach "$verify_root/tree" HEAD^
git -C "$verify_root/tree" am "$patch_dir"/*.patch
git -C "$verify_root/tree" log -1
git diff --exit-code HEAD "$(git -C "$verify_root/tree" rev-parse HEAD)"
Continue to the log and diff checks after git am succeeds. The log lets you inspect the reconstructed message. The final command compares the tracked tree in the original commit with the tracked tree in the reconstructed commit. Exit status zero means there is no tree difference. The commit IDs can differ because Git also records committer information. If git am stops on a conflict, read the error and use git -C "$verify_root/tree" am --abort to end the failed attempt before trying again. For a series, create the verification worktree at the base of the whole series and feed the patches to git am in numbered order.
On Ubuntu 24.04, install the git-email package if git send-email is unavailable. For live delivery you need an SMTP service that allows your account to send mail. Use the server, port, encryption mode, and authentication method documented by your provider. For example, if your provider specifies port 587 with STARTTLS, replace the example host and mailbox and configure Git as follows. Use your provider's supported authentication method and keep credentials out of shell commands and patch files.
git config --global sendemail.smtpServer smtp.example.org
git config --global sendemail.smtpServerPort 587
git config --global sendemail.smtpEncryption tls
git config --global sendemail.smtpUser you@example.org
From the original checkout, preview the patch with explicit recipients. The .example addresses below are placeholders. For a real submission, replace them with the addresses selected for the affected code.
git send-email --dry-run \
--to=maintainer@kernel.example \
--cc=list@kernel.example \
"$patch_dir"/*.patch
--dry-run exercises the sending command without delivering mail. Inspect the full recipient list for each patch, including recipients added by Git configuration or patch trailers. A dry run gives you a preview of addressing and formatting. A message sent to your own mailbox can also confirm that your SMTP credentials work and that the message arrives in an applicable form. For a private delivery test, use a local practice patch with your own address and check the dry run for any additional recipients before sending.
For the public submission, keep the verified recipient arguments and patch files, and replace --dry-run with --confirm=always to have Git prompt before sending. Keep the generated diff in the message so maintainers can read it inline and apply it from the email. Once a public list accepts and archives the message, you can look for it on lore.kernel.org by subject. The next lesson, “The review process and tooling,” explains what happens after the patch reaches its recipients and how to respond to feedback.
Key takeaways
- Kernel mailing lists carry patch submissions, and lore.kernel.org archives many of those lists.
- A kernel commit message records the reason for the change, and Signed-off-by records the contributor's DCO certification.
- git format-patch exports commits as email patches, and git am applies those messages as commits.
- git send-email can preview a submission with --dry-run and send it through a configured SMTP service.
Reflect
- Explain to a colleague, in two sentences: identify a kernel source tree and find relevant submissions in a mailing list archive.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel documentationSubmitting patches: the essential guide to getting your code into the kernel
- Kernel documentationLinux kernel coding style
- Kernel documentationEmail clients info for Linux
Official documentation first. Links checked when the lesson was published.