kb:driver_software:driver_software_for_linux:troubleshooting_build_problems:build_error_related_to_calling_class_create_function

Build Error Related to Calling 'class_create' Function

When a make command for the Meinberg driver package for Linux is run, there are build errors like:

mbgclock/mbgclock_main.c: In function ‘mbgclock_init_module’:
./include/linux/export.h:17:22: error: passing argument 1 of ‘class_create’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   17 | #define THIS_MODULE (&__this_module)
      |                     ~^~~~~~~~~~~~~~~

or

mbgclock/mbgclock_main.c:2747:26: error: too many arguments to function ‘class_create’
 2747 |         mbgclock_class = class_create( THIS_MODULE, mbgclock_class_name );
      |                          ^~~~~~~~~~~~


This has been observed with Red Hat 9.2 and RedHat 9.4, but other RedHat versions as well as some versions of the Fedora distro may be affected, too, possibly after a kernel upgrade.


The problem is due to the way the kernel function class_create has to be called.

In the original kernel up to version 6.3, the function class_create expects 2 parameters, but starting with kernel 6.4 it only expects a single parameter.

Driver packages mbgtools-lx-4.2.24 and newer can handle this properly, depending on the version number of the target kernel for which the driver is built.

The observed issue occurs because RedHat apparently backported the change from the standard 6.4 kernel to their own 5.x kernels. So the calling method is like 6.4, although the kernel version is only 5.x, which confuses the automatic detection by our driver code.


The symptoms described above may occur with version 4.2.26 of the Meinberg driver packages for Linux, and with all earlier versions.

Please note there is no problem with the driver itself, as long as the build procedure finishes successfully.


A fix is available in the current development code 4.2.27, and will be available in future release versions 4.2.28 or newer, once these versions have been released.

The development version of the driver package is available from our git repo at


If you are familiar with git, you can clone the repo or update your local repo, checkout the devel branch and run git pull to update the code base to the latest version.

Alternatively, you can you can download a .tar.gz or .zip archive of the current devel version from this page:


Run the following commands in the base directory of the driver package to build the driver:

make clean
make KERNEL_CLASS_WITHOUT_OWNER=1

The parameter KERNEL_CLASS_WITHOUT_OWNER=1 overrides the automatic detection of the changed kernel API and enforces calling class_create with a single parameter.

This workaround will also be supported by the next release versions 4.2.28 and newer.


It is advisable to use the developer version of the driver package as explained above, because it contains a persistent workaround for the problem.

However, if you don't want to use the development version, you can use driver version 4.2.26 (which is the current release version at the time of this writing) and change a single line in the source code.

In the file mbgclock/mbgclock_main.c around line 270 there are the relevant lines of code that determine how to call the function class_create:

#if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 4, 0 ) )
  #define HAVE_CLASS_WITHOUT_OWNER  1
#else
  #define HAVE_CLASS_WITHOUT_OWNER  0
#endif


Change the 2nd occurrence of HAVE_CLASS_WITHOUT_OWNER also to '1', so that the result looks like:

#if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 4, 0 ) )
  #define HAVE_CLASS_WITHOUT_OWNER  1
#else
  #define HAVE_CLASS_WITHOUT_OWNER  1
#endif

After you have saved the changed file, run make clean; make in the base directory to rebuild the driver package.


Martin Burnicki martin.burnicki@meinberg.de, last updated 2024-05-15

  • kb/driver_software/driver_software_for_linux/troubleshooting_build_problems/build_error_related_to_calling_class_create_function.txt
  • Last modified: 2024-05-15 12:17
  • by 127.0.0.1