Table of Contents
Introduction
What Is LFX?
I recently got selected for the LFX Mentorship program for the Linux kernel, Summer 2026.
LFX is a platform run by the Linux Foundation. It has tools for finding open source projects, joining mentorship programs, and working with communities. The mentorship program pairs you with experienced mentors, and you spend a few months working on already established projects.
I have always been fascinated by the Linux kernel and contributing to it is something I have wanted to do for a long time. So when I got the selection email, I was really happy.
Building & Testing
First stage is being able to build and test changes. I do have some experience in it, and surprisingly it is pretty easy and straight forward. The entire kernel uses something called as Kbuild 1. It is a combination of Makefiles 2 & Kconfig 3, and it is pretty powerful as well, you can ask it to run static analyzers, generate warnings, build documentation, or even build only a specific part of the kernel, it will do just that.
Drivers
Staging Drivers
I have always wanted to get into writing drivers, and I have heard people say that staging drivers are a relatively easy place to start. It houses many drivers which are not fully ready yet to be placed in the kernel as stable drivers. So instead, they are kept in this subdirectory.
It contains a lot of small tasks beginners can do in order to learn how to contribute to the kernel and understand the process. Currently there is an Octeon Ethernet driver in this directory. I started by looking into the TODOs and the code of this driver and soon enough, I found an issue in the driver.
1. Improving Octeon Ethernet Initialization Error Handling
The Problem
Probe & Remove
Drivers have two functions which they "export", probe and remove. You could think of them as a constructor and destructor. The probe routine's job is to allocate resources, check for hardware sanity, initialize the hardware state, and register the device.
/* bare bones example of a probe function */
static int foo_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
struct clk *cclk;
int ret;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
if (!indio_dev)
return -ENOMEM;
/* more initialization */
return iio_device_register(indio_dev);
}While remove routine's job is to do the opposite, deallocate any resource it had allocated, de-register the device, cleanup.
/* bare bones example of a remove function */
static void foo_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
}Probe and remove functions can fail, because the things they do are fallible. When that happens, the function should return an error to its caller so the kernel can handle it properly.
The Octeon Ethernet driver did not do that. It handled error like so:
int cvm_oct_rx_initialize(struct platform_device *pdev)
{
/* ... */
if (!dev_for_napi)
panic("No net_devices were allocated.");
/* ... */
}If that made you raise an eyebrow, good. Because panic() stops the entire system. The kernel only uses it when it truly cannot continue, and it is meant to crash with useful logs. Here, the problem was just that no network devices were allocated. That’s an error one driver can report, not a reason to bring down the whole machine.
The Fix
The panic() calls were in three places:
- No net devices allocated (rx)
- Failing to get the rx IRQ
- Failing to get the tx IRQ
I replaced all of them with proper error returns in four small patches so each one is easy to review.
a30679ddf124f 4: Factor out device removal into a helper. The remove function had a loop that cancels work, shuts down tx, unregisters and frees each net device. I moved that into
cvm_oct_remove_device(). This patch changes no behavior. It just lets the probe error path reuse the same cleanup.ae4350364008b 5: Propagate rx initialization failures.
cvm_oct_rx_initialize()used to return void and callpanic(). Now it returns int. If no net devices exist, it logs an error and returns-ENODEV. If requesting the IRQ fails, it logs the error and returns the error code fromrequest_irq().53113fbfb9316 6: Propagate tx initialization failures. Same idea for
cvm_oct_tx_initialize(). It now returns the error fromrequest_irq()instead of panicking. I also passedpdevinto it so the log message can name the device, and so it matches the rx function.4bcc688a11da4 7: Handle rx/tx failures in probe. Probe now checks both return values. If either fails, it jumps to error labels that undo what was set up so far and then return the error.
The result is that if something goes wrong, only this particular driver fails to load. The kernel keeps running. Klara Modin tested the patch series, and Greg Kroah-Hartman merged it.
2. The mt76 Memory Leak
My ASUS TUF A15 uses a MediaTek wifi card that runs on the mt7921 driver, and over time I had noticed a lot of crashes coming from it. That made me curious about the driver code, so I started reading through it to see what was going on.
That is where I found a small memory leak in the code that handles events coming from the firmware.
The Problem
When a packet buffer (skb) arrives, ownership of it passes to mt7921_queue_rx_skb. From there, every path is responsible for freeing the skb or handing it off to something that will. mt7921_mcu_rx_event follows this rule on its success path, it either queues the skb or frees it right away.
But if skb_linearize() failed, the function returned without freeing skb:
void mt7921_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb)
{
struct mt76_connac2_mcu_rxd *rxd;
if (skb_linearize(skb)) {
/* skb is not cleaned when this path is taken */
return;
}
rxd = (struct mt76_connac2_mcu_rxd *)skb->data;
if (rxd->option & MCU_UNI_CMD_UNSOLICITED_EVENT) {
/* mt7921_mcu_uni_rx_unsolicited_event cleans up skb */
mt7921_mcu_uni_rx_unsolicited_event(dev, skb);
return;
}
if (rxd->eid == 0x6) {
/* mt76_mcu_rx_event cleans up skb */
mt76_mcu_rx_event(&dev->mt76, skb);
return;
}
if (/* .. */ )
/* mt7921_mcu_rx_unsolicited_event cleans up skb */
mt7921_mcu_rx_unsolicited_event(dev, skb);
else
/* mt76_mcu_rx_event cleans up skb */
mt76_mcu_rx_event(&dev->mt76, skb);
}The Fix
- 4361f16601012 8: The fix is one line, freeing the buffer before returning:
if (skb_linearize(skb)) {
+ dev_kfree_skb(skb);
return;
}You might ask whether this matters, since skb_linearize() only fails when the system is very low on memory. That's exactly the problem. Leaking memory when memory is already short makes the out of memory situation worse. It is a rare case, but the fix is cheap and correct.
Felix Fietkau merged it.
3. The IIO Cleanups
These two were smaller. They are from an earlier patch series and they are a good example of the kind of cleanup that fits a first contribution.
Both drivers are ADC (analog to digital converter) drivers in the IIO subsystem, which handles sensors and converters. In each one, the probe function set up a triggered buffer and, on failure, did this:
if (ret) {
dev_err(&spi->dev, "Failed to setup triggered buffer\n");
return ret;
}I replaced it with dev_err_probe():
if (ret)
return dev_err_probe(&spi->dev, ret, "Failed to setup triggered buffer\n");It's the same idea in fewer lines: dev_err_probe() logs the message and returns the error code in one call. It also handles deferred probing (-EPROBE_DEFER) quietly, so a driver that's just waiting for a resource doesn't spam the log with errors. It also keeps error reporting consistent across drivers.
- 2b26ccd886927 9: iio: adc: ti-adc084s021: use
dev_err_probe()for probe time error - 306e3e855f2b9 10: iio: adc: ti-adc081c: use
dev_err_probe()for probe time error
Jonathan Cameron, the IIO maintainer, merged both, and Andy Shevchenko reviewed the ti-adc081c one.
The Sheer Scale of the Linux Kernel - a Tangent
The scale of Linux kernel development has always fascinated me, so I want to talk about it a little.
Kernel development does not happen on GitHub or any other git hosting platform. The whole community works over plain text emails. That might sound like a weird choice, and by today's standards it kind of is. But the kernel isn't built by a single company or a single team. Thousands of people from many different companies and countries work on it, so everyone needs a common ground, the bare minimum that anyone can use to collaborate and get work done. And that's where plain text email comes in. The kernel is also one of the largest software projects developed collaboratively anywhere.
linux on HEAD on Nov 25th, 2026
❯ tokei --sort lines
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Language Files Lines Code Comments Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
C 38054 27272619 20319498 3031542 3921579
C Header 27372 11206121 8731293 1668071 806757
Device Tree 6742 2274256 1867052 97504 309700
ReStructuredText 4135 856520 650449 0 206071
YAML 6034 696928 569091 25436 102401
JSON 1069 620493 620491 0 2
GNU Style Assembly 1342 368864 268149 56950 43765
Shell 1310 239880 166658 31089 42133
Python 481 147643 116634 8723 22286
Plain Text 879 103479 0 84894 18585
Makefile 3268 90521 63018 13872 13631
Rust 601 182694 145644 17171 19879
...
[REDACTED]
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total 91901 44272593 33662291 5082233 5528069
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Stats for 2024 alone
4992 developers 355+ employers 78,209 changes accepted
8.9 changes per hour
40 changes per day in stable trees
13 CVEs assigned per day
New release every 8–9 weeks 11
Linux has been around for more than 30 years now. GitHub didn't exist 30 years ago, and it may not exist 30 years from now. But Linux will probably still be running a huge part of the world.
I hope these stats are enough to convey what I am trying to say. I highly recommend you watch this, still relevant, 10 years old talk by Greg Kroah-Hartman
Conclusion
Looking back, I started this mentorship wanting to contribute to the kernel, and I ended up doing it. I fixed panic() calls in the Octeon driver, fixed a memory leak in the mt7921 wifi driver, and cleaned up probe error handling in a couple of IIO drivers.
Once thing I learned is that kernel work is mostly about small, careful changes. A fix can be one line, like the mt76 leak, but you still have to understand who owns what and what happens on the error path. I also learned how to split a change into small patches, and that review feedback makes a patch better.
The biggest thing I learned was not technical. During my first IIO patches, some of the feedback felt rude to me. It was blunt and to the point, and I took it personally. Later I realized I had misunderstood. Kernel reviewers are hard on the code, never on you. They are not trying to put you down. They're just trying to keep the kernel good, and that is the same thing I want. Once I saw it that way, reading reviews got a lot better.
Thank you to my mentors: Shuah Khan 12, Jori Koolstra 13 and Brigham Campbell 14. Thanks also to Klara Modin for testing the Octeon series, and to the maintainers and reviewers who took the time to look at my patches.
This isn't the end for me. I plan to keep contributing to the areas of the kernel that interest me.
If you're thinking about doing the same, here's what I would tell you:
Start reading code early, even if you don't understand all of it. Begin with small fixes. They count, and they teach you the process. Don't be afraid to send a patch. Reviewers are there to help you get it right.
And Thank you for reading!