mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
fix kernel_modules build on default v5.9.2
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
#include <linux/errno.h> /* EFAULT */
|
||||
#include <linux/fs.h> /* file_operations */
|
||||
#include <linux/kernel.h> /* min */
|
||||
#include <linux/mm.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/printk.h> /* printk */
|
||||
#include <linux/slab.h> /* kvzalloc, kvrealloc, kvfree */
|
||||
#include <linux/string.h> /* memset */
|
||||
#include <linux/uaccess.h> /* copy_from_user, copy_to_user */
|
||||
#include <linux/rwsem.h>
|
||||
#include <linux/version.h>
|
||||
#include <uapi/linux/stat.h> /* 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;
|
||||
|
||||
@@ -20,15 +20,11 @@
|
||||
*/
|
||||
|
||||
#define INCLUDE_VERMAGIC
|
||||
#include <asm/atomic.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/build-salt.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/cred.h> /* current_uid(), current_euid() */
|
||||
#include <linux/elfnote-lto.h>
|
||||
#include <linux/errno.h> /* error codes */
|
||||
#include <linux/export-internal.h>
|
||||
#include <linux/fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/init.h>
|
||||
@@ -48,6 +44,15 @@
|
||||
#include <linux/uaccess.h> /* copy_*_user */
|
||||
#include <linux/vermagic.h>
|
||||
#include <linux/version.h>
|
||||
/* 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 <asm/uaccess.h>
|
||||
#include <linux/atomic.h>
|
||||
|
||||
/* 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");
|
||||
|
||||
Reference in New Issue
Block a user