How to figure out the specific kernel version when the kernel interface changes

I maintains a test suites which need run in Linux kernel, so I have to adapt the code to many Linux systems Ubuntu 18.04/20.04/22.04, CentOS7/CentOS8, terrible work :frowning:
Here is an example

    memset(wlData, 0, fileStat.size);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0)
    ret = kernel_read(fp, wlData, fileStat.size, &pos);
#else
    ret = kernel_read(fp, pos, wlData, fileStat.size);
#endif

    if (ret < 0 || ret != fileStat.size) {
        printk("Read file failure\n");
        goto err1;
    }

So how can I exactly figure out from which Linux kernel version the interface kernel_read() changes it’s interface?
Currently I just run the test suite on a special Linux system for example Ubuntu 18.04, when compile failed I check the Linux kernel version of this Linux system, and added upper macro … I don’t think this a solution, it’s just a workaround …

In this particular case it’s this commit that changed the function prototype, which is:

$ git describe bdd1d2d3d251c65b74ac4493e08db18971c09240
v4.13-rc7-5-gbdd1d2d3d251

Just looking at the kernel version is sub-optimal since distros pick commits from other kernel versions. For example, a distro could decide that they need this for whatever reason in an older kernel so that version check would be incorrect.

Maybe you could query Module.symvers at runtime but I’m not sure how reliable that information is.

1 Like

Thanks for your tips, I realise the Linux project is maintained on github.com where I visit frequently, I used to think the Linux project might be periodically published on website linux.com or linux.org
Now I can figure out the exactly kernel version from which the kernel interfaces/structures changed, thank you !

On github.com are mirrors of the kernel repos. The real location is: https://www.kernel.org/

1 Like