projects
/
cascardo
/
kernel
/
samples
/
char2
/
.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allocate device number dynamically.
[cascardo/kernel/samples/char2/.git]
/
hellochar.c
diff --git
a/hellochar.c
b/hellochar.c
index
576968b
..
e50ac2a
100644
(file)
--- a/
hellochar.c
+++ b/
hellochar.c
@@
-20,21
+20,21
@@
#include <linux/fs.h>
MODULE_LICENSE("GPL");
#include <linux/fs.h>
MODULE_LICENSE("GPL");
-static int major = 10;
-module_param_named(major, major, int, S_IRUGO | S_IWUSR);
+static dev_t devnum;
static int __init ch_init(void)
{
int r;
static int __init ch_init(void)
{
int r;
- r =
register_chrdev_region(MKDEV(major, 0)
, 256, "hello");
+ r =
alloc_chrdev_region(&devnum, 0
, 256, "hello");
if (r)
return r;
if (r)
return r;
+ printk(KERN_DEBUG "Allocate major %d\n", MAJOR(devnum));
return 0;
}
static void __exit ch_exit(void)
{
return 0;
}
static void __exit ch_exit(void)
{
- unregister_chrdev_region(
MKDEV(major, 0)
, 256);
+ unregister_chrdev_region(
devnum
, 256);
}
module_init(ch_init);
}
module_init(ch_init);