Skip to content
Snippets Groups Projects
Commit 1df03d1a authored by Werner Sembach's avatar Werner Sembach
Browse files

Make use of misc_register() to clean up the code

parent d9ea7207
No related branches found
No related tags found
No related merge requests found
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <linux/device.h> #include <linux/miscdevice.h>
#include <linux/kdev_t.h>
#define ERR(...) printk(KERN_ERR __VA_ARGS__)
/* #define DEBUG */ /* #define DEBUG */
#ifdef DEBUG #ifdef DEBUG
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#define LOG(...) #define LOG(...)
#endif #endif
#define ERR(...) printk(KERN_ERR __VA_ARGS__)
/* klist functions */ /* klist functions */
#define LIST_CMD 0x1337 #define LIST_CMD 0x1337
#define LIST_ADD (LIST_CMD + 0) #define LIST_ADD (LIST_CMD + 0)
...@@ -35,8 +33,6 @@ ...@@ -35,8 +33,6 @@
/* consts */ /* consts */
#define MAX_SIZE 0x400 #define MAX_SIZE 0x400
static struct class *cl;
static long k_list[MAX_SIZE]; static long k_list[MAX_SIZE];
static unsigned long list_size; static unsigned long list_size;
...@@ -172,38 +168,26 @@ struct file_operations list_fops = { ...@@ -172,38 +168,26 @@ struct file_operations list_fops = {
unlocked_ioctl: list_ioctl, unlocked_ioctl: list_ioctl,
}; };
static struct miscdevice klist = {
.minor = MISC_DYNAMIC_MINOR,
.name = "klist",
.fops = &list_fops,
};
static int __init init_list(void) static int __init init_list(void)
{ {
int ret; int ret;
ret = register_chrdev(1337, "klist", &list_fops); ret = misc_register(&klist);
LOG("register device: %d\n", ret); LOG("register device: %d\n", ret);
list_size = 0; list_size = 0;
if (ret) {
ERR("register device failed.");
return ret;
}
//automatically populate /sys/class/ and create /dev/klist on module startup
cl = class_create(THIS_MODULE, "klist");
if (IS_ERR(cl)) {
ERR("automatic /dev/klist creation failed on class_create.");
return ret;
}
if (IS_ERR(device_create(cl, NULL, MKDEV(1337, 0), NULL, "klist"))) {
ERR("automatic /dev/klist creation failed on class_create.");
class_destroy(cl);
return ret;
}
return ret; return ret;
} }
static void __exit exit_list(void) static void __exit exit_list(void)
{ {
device_destroy(cl, MKDEV(1337, 0)); misc_deregister(&klist);
class_destroy(cl);
unregister_chrdev(1337, "klist");
LOG("exit.\n"); LOG("exit.\n");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment