Why Linux Is Moving Its Kernel to C11 and What It Means for Developers

The Linux kernel, long stuck on the 1989 C89 standard, will upgrade to C11 starting with the 5.18 release, a change driven by a subtle bug in list traversal macros and Linus Torvalds' decision after community discussion.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Why Linux Is Moving Its Kernel to C11 and What It Means for Developers

After decades of using the 1989 C89 standard, the Linux kernel community announced that the kernel will be upgraded to the C11 language standard, expected to take effect after the 5.18 release in May 2024.

Linux kernel C11 upgrade illustration
Linux kernel C11 upgrade illustration

Bug that triggered the change

A recent discussion revealed a subtle bug in the list_for_each_entry() macro, which leaks the iterator variable outside the loop because C89 does not allow variable declarations inside the loop header. The bug manifested in the USB subsystem.

struct list_head {
    struct list_head *next, *prev;
};

struct foo {
    int fooness;
    struct list_head list;
};

struct foo *iterator;
list_for_each_entry(iterator, &foo_list, list) {
    do_something_with(iterator);
}
/* Should not use iterator here */

Jakob Koschel submitted a patch that stops using the iterator after the macro, fixing the issue.

Illustration of the list macro bug
Illustration of the list macro bug

Convincing Linus Torvalds

Linus initially dismissed the patch, not seeing its link to speculative‑execution vulnerabilities. After Koschel’s detailed explanation, Linus recognized that the root cause was the inability to declare the iterator inside the loop, a limitation of C89.

Because C89 is too old and some legacy gcc versions caused problems, the community considered moving to C99, but ultimately decided on C11, which is newer yet still widely supported. The kernel now requires gcc 5.1 or newer, eliminating the earlier compiler constraints.

Core developer Arnd Bergmann argued that C11 is the most practical target; moving to C17 or C2x would break compatibility with gcc 5/6/7. Linus agreed, saying “Okay, remind me to try it early in the 5.18 merge window.” The transition may introduce unexpected bugs, but if successful, the next kernel release will officially use C11.

Linus approving the C11 upgrade
Linus approving the C11 upgrade

References:

1. https://lwn.net/SubscriberLink/885941/01fdc39df2ecc25f/

2. https://news.ycombinator.com/item?id=3045963

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

C languagebug fixC11
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.