DEV Community

My Linux Kernel Mentorship (Summer 2026)

Hi, I'm Ridham Khurana. I'm doing an Integrated M.Tech in CSE at the University of Hyderabad. Most of my work is in compilers. I have written a few C compilers from scratch (RMc4, RMc7 and RM-x86-64-Forge), and before this mentorship I had a patch merged in the GCC static analyzer. I also did a summer research internship at ISI Kolkata on post-quantum cryptography.

This year I was selected for the Linux Kernel Mentorship Program (Summer 2026) by the Linux Foundation. My mentors were Shuah Khan, Jori Koolstra and Brigham Campbell. To graduate you need 5 to 10 patches accepted upstream. I got 7 patches in, and all of them are now in mainline. 3 went into Linux 7.3 and 4 are in for 7.4. They are in GPIO, hwmon, regulator and one platform driver.

I did all my building and testing on linux-next, on cfarm424, a 64-core arm64 machine in the GCC Compile Farm. I had access to the farm from my GCC work.

How I found bugs

At first I looked at syzbot. But the bugs I could handle were getting fixed by other people very quickly, and I couldn't keep up. So I started reading driver code instead, looking for one kind of bug at a time: runtime PM error paths, device ID tables without MODULE_DEVICE_TABLE(), regulator descriptors where the count doesn't match the table, and signed temperature conversions in hwmon drivers.

When I found a bug in one driver, I checked similar drivers too. That's how the xilinx fix came right after the zynq one.

Before sending anything I tried to make the bug actually happen, mostly by running the real driver in QEMU with a small stub in place of the hardware. I started with GPIO because reviews there are quick. Later I followed the bug types I was looking for, and they led me to hwmon, regulator and the SoC tree.

Some of the bugs

lm70

This driver reads SPI temperature sensors like the LM70, LM71, LM74 and TMP12x. The low bits of the register are not part of the temperature, and the driver removed them by dividing, like raw / 32. In C, division rounds toward zero, so for negative temperatures the result was one step too high. For example, the LM70 reports -25 °C as 0xf39f, and the driver showed -24.75 °C.

I changed the division to a right shift (>> 5), which rounds down. To test it, I ran the real driver in QEMU with a fake SPI controller and tried all 65536 register values for every chip type, on arm64 and on 32-bit ARM. Before the fix, the LM70 alone gave 31744 wrong readings, all of them negative. After the fix there were none, and the positive values did not change at all.

In review, someone asked whether right-shifting a negative number is undefined behaviour. It's not. In C it's implementation-defined (C11 6.5.7p5), GCC documents it as an arithmetic shift, and the kernel already depends on it in sign_extend32(). Christian Lamparter, who added the TMP125 support, tested that part and gave a Reviewed-by.

tps6594

For the TPS65224 BUCK2, BUCK3 and BUCK4 regulators, the driver said there were 4 voltage ranges, but the table only has 2. When the regulator registers, the core checks voltages for every selector, so the code read past the end of the array.

I booted the real driver in QEMU with KASAN, using the regulator nodes from the J722S and AM62D2 EVM device trees. KASAN reported a global-out-of-bounds read in linear_range_get_value_array(). After changing the 4 to ARRAY_SIZE() it was gone. Mark Brown applied it the same day.

zynq and xilinx

zynq_gpio_request() used pm_runtime_get_sync(). That function increases the usage count even when it fails, and the driver returned the error without decreasing it. gpiolib doesn't call ->free() after a failed ->request(), so the count never went back down and the controller could never suspend.

The fix was pm_runtime_resume_and_get(), which only takes the reference if it succeeds. The xilinx driver had exactly the same code, so I sent the same fix there. The zynq fix was also picked up for the stable kernels.

The other three

The siox driver returned the raw bit (like 4 or 64) from its get() function instead of 0 or 1. lm95245 decoded negative temperatures using only the high byte, so writing -500 to temp2_offset read back -1000. turris-omnia-mcu was missing MODULE_DEVICE_TABLE(), so the module never loaded automatically.

All 7 patches:

  • gpio: zynq: fix runtime PM leak on request error path (7.3)
  • gpio: xilinx: fix runtime PM leak on request error path (7.3)
  • regulator: tps6594-regulator: Fix n_linear_ranges for TPS65224 BUCK2-4 (7.3)
  • gpio: siox: normalize return value of gpio_get() (7.4)
  • hwmon: (lm95245) Fix negative temperature conversion (7.4)
  • hwmon: (lm70) Fix rounding of negative temperatures (7.4)
  • platform: cznic: turris-omnia-mcu: Add missing MODULE_DEVICE_TABLE() (7.4)

What didn't work

Some bugs looked real but couldn't actually happen. For max77503 I had a patch ready, but when I ran the driver in QEMU I saw that it never reads its device tree constraints at all, so my fix changed nothing. I dropped it. After that I made it a rule to run the real driver before writing any patch.

My mt7915 (WiFi) patch from August never got a reply, even after a ping. My turris patch got no reply at first either. Later I found out that drivers/platform/cznic goes upstream through the SoC tree, so I resent it to the SoC list, and it was applied about ten days later.

What I learned

  • Fixes and new work go through different branches. My fixes reached mainline within days. The others waited for the next merge window.
  • Stable has its own flow. One of my fixes didn't apply to the 6.6 stable tree because the old code there was different.
  • Check that the people you Cc are still around. One address from get_maintainer.pl bounced.

Tips for new mentees

  • Reproduce the bug before you send a patch. QEMU plus a small stub driver covers a lot.
  • Put real numbers in the commit message: what the register holds, what the driver shows, and what it should show.
  • When you find one bug, look for the same bug in similar drivers.

Thanks

Thanks to Shuah, Jori and Brigham for running the program, and to Bartosz Golaszewski, Guenter Roeck, Mark Brown and Krzysztof Kozlowski for reviewing and applying my patches. All my commits in mainline: git.kernel.org

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.