Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

KERNEL_VERSION 📘

The KERNEL_VERSION macro is an integral part of kernel module development, especially when dealing with modules that aim to be compatible with different versions of the Linux kernel.

  • This macro is used to construct a single integer value representing the kernel version from the major, minor, and patch levels of the version number.
  • It's defined as #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)), and it's included through the <linux/version.h> header file.
  • This integer value is crucial for performing comparisons with the LINUX_VERSION_CODE to ensure compatibility and manage API changes between different kernel versions.

Curious Questions 🤔

Q: How is the KERNEL_VERSION macro used to evaluate whether the kernel version of the running system is above a certain level? A: Developers can compare the result of KERNEL_VERSION(a, b, c) with the LINUX_VERSION_CODE to determine the running kernel’s version.

  • If LINUX_VERSION_CODE >= KERNEL_VERSION(a, b, c), then the running kernel's version is equal to or higher than the specified version a.b.c.

Q: Can you explain how the shifting and addition in the KERNEL_VERSION macro lead to a unique integer representing the kernel version? A: The KERNEL_VERSION macro takes three integers representing the major, minor, and patch levels.

  • It shifts the major version a 16 bits to the left, the minor version b 8 bits to the left, and then adds them together with the patch level c.
  • This ensures a unique integer value for each different version, which can be easily compared.

Concept in simple words 🌟

Think of KERNEL_VERSION as a special formula 🧪 that takes three ingredients: the major, minor, and patch levels of a kernel version, and mixes them to create a unique number label 🏷️, representing that specific version of the kernel.

  • It’s like having a unique recipe name for each variation of a dish 🍲 you cook.
  • This way, you can easily check 🕵️‍♂️ if the recipe (kernel version) you have is the one you need for your guests (modules).
  • So, if you know your dish's name (kernel version), you can quickly tell if it’s the right one by checking the label (comparing KERNEL_VERSION and LINUX_VERSION_CODE).