<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ridham Khurana</title>
    <description>The latest articles on DEV Community by Ridham Khurana (@rm_khurana).</description>
    <link>https://dev.to/rm_khurana</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4277897%2Fd79df8b2-df1f-44d0-9a5d-71d82dbd22bc.jpg</url>
      <title>DEV Community: Ridham Khurana</title>
      <link>https://dev.to/rm_khurana</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rm_khurana"/>
    <language>en</language>
    <item>
      <title>My Linux Kernel Mentorship (Summer 2026)</title>
      <dc:creator>Ridham Khurana</dc:creator>
      <pubDate>Wed, 02 Dec 2026 08:08:16 +0000</pubDate>
      <link>https://dev.to/rm_khurana/my-linux-kernel-mentorship-summer-2026-1obh</link>
      <guid>https://dev.to/rm_khurana/my-linux-kernel-mentorship-summer-2026-1obh</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I found bugs
&lt;/h2&gt;

&lt;p&gt;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 &lt;code&gt;MODULE_DEVICE_TABLE()&lt;/code&gt;, 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some of the bugs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  lm70
&lt;/h3&gt;

&lt;p&gt;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 &lt;code&gt;raw / 32&lt;/code&gt;. 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 &lt;code&gt;0xf39f&lt;/code&gt;, and the driver showed -24.75 °C. I changed the division to a right shift (&lt;code&gt;&amp;gt;&amp;gt; 5&lt;/code&gt;), which rounds down.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;sign_extend32()&lt;/code&gt;. Christian Lamparter, who added the TMP125 support, tested that part and gave a Reviewed-by.&lt;/p&gt;

&lt;h3&gt;
  
  
  tps6594
&lt;/h3&gt;

&lt;p&gt;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 &lt;code&gt;linear_range_get_value_array()&lt;/code&gt;. After changing the &lt;code&gt;4&lt;/code&gt; to &lt;code&gt;ARRAY_SIZE()&lt;/code&gt; it was gone. Mark Brown applied it the same day.&lt;/p&gt;

&lt;h3&gt;
  
  
  zynq and xilinx
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;zynq_gpio_request()&lt;/code&gt; used &lt;code&gt;pm_runtime_get_sync()&lt;/code&gt;. That function increases the usage count even when it fails, and the driver returned the error without decreasing it. gpiolib doesn't call &lt;code&gt;-&amp;gt;free()&lt;/code&gt; after a failed &lt;code&gt;-&amp;gt;request()&lt;/code&gt;, so the count never went back down and the controller could never suspend. The fix was &lt;code&gt;pm_runtime_resume_and_get()&lt;/code&gt;, 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.&lt;/p&gt;

&lt;h3&gt;
  
  
  The other three
&lt;/h3&gt;

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

&lt;p&gt;All 7 patches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e9438ab5328a177c9c0e5df87eb92a7162841e98" rel="noopener noreferrer"&gt;gpio: zynq: fix runtime PM leak on request error path&lt;/a&gt; (7.3)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ff82fc3a4a1d417dee1229681cc5285986edb1fa" rel="noopener noreferrer"&gt;gpio: xilinx: fix runtime PM leak on request error path&lt;/a&gt; (7.3)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2f15518682c779b1014552cb2ccb4a2052f85f27" rel="noopener noreferrer"&gt;regulator: tps6594-regulator: Fix n_linear_ranges for TPS65224 BUCK2-4&lt;/a&gt; (7.3)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=209fcf625880cd1128bc98ca835d4cb5c3b8e136" rel="noopener noreferrer"&gt;gpio: siox: normalize return value of gpio_get()&lt;/a&gt; (7.4)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f58c16056f8585ebafb0f1f5d90c23085443a4b9" rel="noopener noreferrer"&gt;hwmon: (lm95245) Fix negative temperature conversion&lt;/a&gt; (7.4)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eddb0aaacce4baa9d8176eb2f4bd9e99e867f8fc" rel="noopener noreferrer"&gt;hwmon: (lm70) Fix rounding of negative temperatures&lt;/a&gt; (7.4)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=59797443846bc2451c35816026bbb79d281c9f23" rel="noopener noreferrer"&gt;platform: cznic: turris-omnia-mcu: Add missing MODULE_DEVICE_TABLE()&lt;/a&gt; (7.4)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What didn't work
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;drivers/platform/cznic&lt;/code&gt; goes upstream through the SoC tree, so I resent it to the SoC list, and it was applied about ten days later.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fixes and new work go through different branches. My fixes reached mainline within days. The others waited for the next merge window.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;li&gt;Check that the people you Cc are still around. One address from &lt;code&gt;get_maintainer.pl&lt;/code&gt; bounced.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tips for new mentees
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Thanks
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;All my commits in mainline: &lt;a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/?qt=author&amp;amp;q=Ridham+Khurana" rel="noopener noreferrer"&gt;git.kernel.org&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>kernel</category>
      <category>c</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
