Skip to content

Instantly share code, notes, and snippets.

@adaskar
Created January 30, 2020 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adaskar/338a5bcc101454dcb748028e0bc12117 to your computer and use it in GitHub Desktop.
Save adaskar/338a5bcc101454dcb748028e0bc12117 to your computer and use it in GitHub Desktop.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#define DEVICENAME "LKMDevice"
#define bail_assert(s, label, fmt, ...) \
do { \
if (!(s)) { \
printk(KERN_ALERT DEVICENAME " " fmt "\n", ##__VA_ARGS__); \
goto label; \
} \
} while(0) \
#define kinfo(fmt, ...) \
do { \
printk(KERN_INFO DEVICENAME " " fmt "\n", ##__VA_ARGS__); \
} while(0) \
#define kalert(fmt, ...) \
do { \
printk(KERN_ALERT DEVICENAME " " fmt "\n", ##__VA_ARGS__); \
} while(0) \
static int __init lkm_init(void)
{
kinfo("inited");
return 0;
}
static void __exit lkm_exit(void)
{
kinfo("exited");
}
module_init(lkm_init);
module_exit(lkm_exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment