From: Thadeu Lima de Souza Cascardo Date: Wed, 19 May 2010 14:16:07 +0000 (-0400) Subject: Allocate device number dynamically. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fkernel%2Fsamples%2Fchar2%2F.git;a=commitdiff_plain;h=2808766508d8ef444e7cc4636b37534a910e5600 Allocate device number dynamically. --- 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);