From 2808766508d8ef444e7cc4636b37534a910e5600 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 19 May 2010 10:16:07 -0400 Subject: [PATCH] Allocate device number dynamically. --- hellochar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hellochar.c b/hellochar.c index 576968b..e50ac2a 100644 --- a/hellochar.c +++ b/hellochar.c @@ -20,21 +20,21 @@ #include 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; - r = register_chrdev_region(MKDEV(major, 0), 256, "hello"); + r = alloc_chrdev_region(&devnum, 0, 256, "hello"); if (r) return r; + printk(KERN_DEBUG "Allocate major %d\n", MAJOR(devnum)); return 0; } static void __exit ch_exit(void) { - unregister_chrdev_region(MKDEV(major, 0), 256); + unregister_chrdev_region(devnum, 256); } module_init(ch_init); -- 2.20.1