From 500a939db4debbd6d16b179e8e92dfb176f6d9c7 Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Sat, 16 May 2026 23:07:17 +0200 Subject: [PATCH] Fix DKMS build using the wrong kernel version The DKMS Makefile built against /lib/modules/$(uname -r), the *running* kernel. When DKMS rebuilds the module for a newly installed kernel (the common case after an apt upgrade, while the old kernel is still running), it produced a .ko with the old kernel's vermagic and installed it into the new kernel's tree. The module then failed to load with "disagrees about version of symbol module_layout". Make the Makefile honour a KVERSION variable (defaulting to the running kernel for manual builds) and have dkms.conf pass DKMS's target kernel via KVERSION=${kernelver}, so the module is always built for the kernel it is being installed for. Co-Authored-By: Claude Opus 4.7 (1M context) --- battery/dkms/Makefile | 9 +++++++-- battery/dkms/dkms.conf | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/battery/dkms/Makefile b/battery/dkms/Makefile index 31cca1c..9f3e4a8 100644 --- a/battery/dkms/Makefile +++ b/battery/dkms/Makefile @@ -1,9 +1,14 @@ obj-m += oneUpPower.o +# KVERSION is the kernel to build for. DKMS passes the *target* kernel via +# the MAKE directive in dkms.conf; default to the running kernel so a plain +# `make` still works for a manual build. +KVERSION ?= $(shell uname -r) + all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD)/src modules + make -C /lib/modules/$(KVERSION)/build M=$(PWD)/src modules clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD)/src clean + make -C /lib/modules/$(KVERSION)/build M=$(PWD)/src clean .PHONY: all clean diff --git a/battery/dkms/dkms.conf b/battery/dkms/dkms.conf index 8d6ae8f..8550a59 100644 --- a/battery/dkms/dkms.conf +++ b/battery/dkms/dkms.conf @@ -1,10 +1,9 @@ PACKAGE_NAME="oneUpPower" PACKAGE_VERSION="1.0" -MAKE="make -f ./src/Makefile" -CLEAN="make -f ./src/Makefile clean" +MAKE="make -f ./src/Makefile KVERSION=${kernelver}" +CLEAN="make -f ./src/Makefile clean KVERSION=${kernelver}" BUILT_MODULE_NAME="oneUpPower" BUILT_MODULE_LOCATION="./src/" DEST_MODULE_LOCATION="/kernel/drivers/power/supply/" AUTOINSTALL="yes" POST_INSTALL="./postinstall" -