Page MenuHomeFreeBSD

LinuxKPI: add KERNEL_VERSION() macro
ClosedPublic

Authored by bz on Jun 14 2026, 6:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Aug 8, 4:57 AM
Unknown Object (File)
Fri, Aug 7, 1:20 AM
Unknown Object (File)
Sat, Aug 1, 8:19 AM
Unknown Object (File)
Fri, Jul 31, 2:32 PM
Unknown Object (File)
Fri, Jul 31, 2:20 PM
Unknown Object (File)
Fri, Jul 31, 4:35 AM
Unknown Object (File)
Tue, Jul 28, 12:44 AM
Unknown Object (File)
Sun, Jul 26, 2:39 PM

Details

Summary

Add a KERNEL_VERSION() macro which normally would be in linux/version.h.
On Linux that file is auto-generated and we are supporting more than
one Linux version in LinuxKPI anyway so any further defines in there
would likely be wrong.

Adding the macro helps to support (vendor/out of tree) drivers more
easily which are supporting multiple Linux versions.

MFC after: 3 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested review of this revision.Jun 14 2026, 6:57 PM

What are the use cases for this macro?

I’m curious because of the relationship it could have with LINUXKPI_VERSION we define and compare in several places.

What are the use cases for this macro?

I’m curious because of the relationship it could have with LINUXKPI_VERSION we define and compare in several places.

LINUXKPI_VERSION we define "readable" as 70000; that's how I found it, that's how I kept doing it.

The equivalent would be LINUX_VERSION_CODE which uses the KERNEL_VERSION encoding.
So for an external driver which checks against KERNEL_VERSION() I have to define:

CFLAGS+=        -DLINUX_VERSION_CODE=458752     # 7.0.0

Don't ask me; that's the way it seems to be.

I should add; obviously if I define it as 0x70000 that would likely work too but seems less common (at least in the code I was looking at).

In D57590#1319911, @bz wrote:

I should add; obviously if I define it as 0x70000 that would likely work too but seems less common (at least in the code I was looking at).

So if I think it to the end, in theory LINUXKPI_VERSION should have been 0xNNNNN and not just NNNNN and we would almost be good.

Thanks for the explanation!

This revision is now accepted and ready to land.Jun 15 2026, 7:56 AM
This revision was automatically updated to reflect the committed changes.