My kernel module works properly on Ubuntu 22.04 and earlier version, but report the compile warning on Ubuntu 24.04. I simplified the issue as below demo:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jack");
MODULE_DESCRIPTION("A simple Hello world");
typedef struct {
uint32_t a;
uint32_t b;
uint8_t data[0];
} demo_t;
static int __init hello_start(void)
{
demo_t *demo = NULL;
uint32_t *ptr = NULL;
demo = kmalloc(1024, GFP_KERNEL);
if(!demo) { return -1;}
demo->a = 0xaaaaaaaa;
demo->b = 0xbbbbbbbb;
ptr = (uint32_t *)demo->data;
*ptr = 0xcccccccc;
ptr = (uint32_t *)(demo->data + 4);
memset(ptr, 0xdd, 128);
// other operations ...
kfree(demo);
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);
The image below is the detail compile information: