Skip to content

Commit 76c4cb0

Browse files
committed
fix kernel_modules build on default v5.9.2
1 parent 1e28f2e commit 76c4cb0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

kernel_modules/memfile.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
#include <linux/errno.h> /* EFAULT */
55
#include <linux/fs.h> /* file_operations */
66
#include <linux/kernel.h> /* min */
7+
#include <linux/mm.h>
78
#include <linux/module.h>
89
#include <linux/printk.h> /* printk */
910
#include <linux/slab.h> /* kvzalloc, kvrealloc, kvfree */
1011
#include <linux/string.h> /* memset */
1112
#include <linux/uaccess.h> /* copy_from_user, copy_to_user */
1213
#include <linux/rwsem.h>
14+
#include <linux/version.h>
1315
#include <uapi/linux/stat.h> /* S_IRUSR */
1416

1517
/* Params */
@@ -48,7 +50,15 @@ int dyn_arr_reserve(dyn_arr_t *a, size_t off, size_t len)
4850
new_used = off + len;
4951
if (new_used > a->_size) {
5052
new_size = new_used * 2;
53+
/* Added in de2860f4636256836450c6543be744a50118fc66 */
54+
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
55+
/* TODO is this correct? kvrealloc seems more correct. Doing it without
56+
* much thought just to make build happy for now. kvrealloc makes more sense
57+
* so as to match kvzalloc. */
58+
a->buf = krealloc(a->buf, new_size, GFP_KERNEL);
59+
#else
5160
a->buf = kvrealloc(a->buf, a->_size, new_size, GFP_KERNEL);
61+
#endif
5262
if (!a->buf)
5363
return -ENOMEM;
5464
a->_size = new_size;

kernel_modules/scull.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
*/
2121

2222
#define INCLUDE_VERMAGIC
23-
#include <asm/atomic.h>
24-
#include <asm/uaccess.h>
2523
#include <linux/build-salt.h>
2624
#include <linux/cdev.h>
2725
#include <linux/compiler.h>
2826
#include <linux/cred.h> /* current_uid(), current_euid() */
29-
#include <linux/elfnote-lto.h>
3027
#include <linux/errno.h> /* error codes */
31-
#include <linux/export-internal.h>
3228
#include <linux/fcntl.h>
3329
#include <linux/fs.h>
3430
#include <linux/init.h>
@@ -48,6 +44,15 @@
4844
#include <linux/uaccess.h> /* copy_*_user */
4945
#include <linux/vermagic.h>
5046
#include <linux/version.h>
47+
/* As a Linux kernel bug tested on Linux v5.9.2 these includes must come after some other includes
48+
* otherwise the build fails with: error: unknown type name ‘mm_segment_t’;
49+
* Their origin from LDD3 give a clue as to what may need to come before:
50+
* https://github.com/martinezjavier/ldd3/blob/d0c90d4d872b8591563d5a4ba7b3f522c5072551/scull/pipe.c#L29
51+
* https://github.com/martinezjavier/ldd3/blob/d0c90d4d872b8591563d5a4ba7b3f522c5072551/scull/access.c#L29
52+
* This bug had been fixed somewhere by linux v6.8.12.
53+
*/
54+
#include <asm/uaccess.h>
55+
#include <linux/atomic.h>
5156

5257
/* Liner kernel version dependant stuff. */
5358

@@ -265,7 +270,7 @@ static int scull_s_open(struct inode *inode, struct file *filp)
265270
{
266271
struct scull_dev *dev = &scull_s_device; /* device information */
267272

268-
if (! atomic_dec_and_test (&scull_s_available)) {
273+
if (!atomic_dec_and_test(&scull_s_available)) {
269274
atomic_inc(&scull_s_available);
270275
return -EBUSY; /* already open */
271276
}
@@ -1610,8 +1615,8 @@ void scull_p_cleanup(void)
16101615
}
16111616

16121617
BUILD_SALT;
1613-
BUILD_LTO_INFO;
16141618
MODULE_INFO(vermagic, VERMAGIC_STRING);
1619+
16151620
MODULE_INFO(name, KBUILD_MODNAME);
16161621
MODULE_AUTHOR("Alessandro Rubini, Jonathan Corbet");
16171622
MODULE_LICENSE("Dual BSD/GPL");

0 commit comments

Comments
 (0)