From 76c4cb0e45febbe94cc8922db79a485f915152ad Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Fri, 9 May 2025 16:10:59 +0100 Subject: [PATCH] fix kernel_modules build on default v5.9.2 --- kernel_modules/memfile.c | 10 ++++++++++ kernel_modules/scull.c | 17 +++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/kernel_modules/memfile.c b/kernel_modules/memfile.c index 33bd5f0..d39c317 100644 --- a/kernel_modules/memfile.c +++ b/kernel_modules/memfile.c @@ -4,12 +4,14 @@ #include /* EFAULT */ #include /* file_operations */ #include /* min */ +#include #include #include /* printk */ #include /* kvzalloc, kvrealloc, kvfree */ #include /* memset */ #include /* copy_from_user, copy_to_user */ #include +#include #include /* S_IRUSR */ /* Params */ @@ -48,7 +50,15 @@ int dyn_arr_reserve(dyn_arr_t *a, size_t off, size_t len) new_used = off + len; if (new_used > a->_size) { new_size = new_used * 2; +/* Added in de2860f4636256836450c6543be744a50118fc66 */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) + /* TODO is this correct? kvrealloc seems more correct. Doing it without + * much thought just to make build happy for now. kvrealloc makes more sense + * so as to match kvzalloc. */ + a->buf = krealloc(a->buf, new_size, GFP_KERNEL); +#else a->buf = kvrealloc(a->buf, a->_size, new_size, GFP_KERNEL); +#endif if (!a->buf) return -ENOMEM; a->_size = new_size; diff --git a/kernel_modules/scull.c b/kernel_modules/scull.c index 7c59438..e8df58f 100644 --- a/kernel_modules/scull.c +++ b/kernel_modules/scull.c @@ -20,15 +20,11 @@ */ #define INCLUDE_VERMAGIC -#include -#include #include #include #include #include /* current_uid(), current_euid() */ -#include #include /* error codes */ -#include #include #include #include @@ -48,6 +44,15 @@ #include /* copy_*_user */ #include #include +/* As a Linux kernel bug tested on Linux v5.9.2 these includes must come after some other includes + * otherwise the build fails with: error: unknown type name ‘mm_segment_t’; + * Their origin from LDD3 give a clue as to what may need to come before: + * https://github.com/martinezjavier/ldd3/blob/d0c90d4d872b8591563d5a4ba7b3f522c5072551/scull/pipe.c#L29 + * https://github.com/martinezjavier/ldd3/blob/d0c90d4d872b8591563d5a4ba7b3f522c5072551/scull/access.c#L29 + * This bug had been fixed somewhere by linux v6.8.12. + */ +#include +#include /* Liner kernel version dependant stuff. */ @@ -265,7 +270,7 @@ static int scull_s_open(struct inode *inode, struct file *filp) { struct scull_dev *dev = &scull_s_device; /* device information */ - if (! atomic_dec_and_test (&scull_s_available)) { + if (!atomic_dec_and_test(&scull_s_available)) { atomic_inc(&scull_s_available); return -EBUSY; /* already open */ } @@ -1610,8 +1615,8 @@ void scull_p_cleanup(void) } BUILD_SALT; -BUILD_LTO_INFO; MODULE_INFO(vermagic, VERMAGIC_STRING); + MODULE_INFO(name, KBUILD_MODNAME); MODULE_AUTHOR("Alessandro Rubini, Jonathan Corbet"); MODULE_LICENSE("Dual BSD/GPL");