register_chrdev vs. cdev_add
Hi,
Testing 2.6.26 (GIT) on cris architecture shown that old style of registering char devices with register_chrdev() vs. new style with cdev_init() and cdev_add() does not produce the same results.
static unsigned int htrc110_major = 123; static unsigned int htrc110_minor = 2;
CODE:
dev = MKDEV(htrc110_major, htrc110_minor); ret = register_chrdev_region(dev, 1, mod_name); ret = register_chrdev(dev, mod_name, &htrc110_fops);
Using char driver with 123 major and 2 minor and registering it with register_chrdev() shows this in /proc/devices:
# cat /proc/devices Character devices: 1 mem 2 pty 3 ttyp 4 ttyS 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 10 misc 29 fb 90 mtd 123 carneol-htrc110 128 ptm 136 pts 180 usb 128974850 carneol-htrc110 189 usb_device 253 usb_endpoint 254 usbmon
CODE:
dev = MKDEV(htrc110_major, htrc110_minor); ret = register_chrdev_region(dev, 1, mod_name); cdev_init(&htrc110_dev->cdev, &htrc110_fops); htrc110_dev->cdev.owner = THIS_MODULE; htrc110_dev->cdev.ops = &htrc110_fops; ret = cdev_add(&htrc110_dev->cdev, dev, 1);
While using cdev_init() and cdev_add():
# cat /proc/devices Character devices: 1 mem 2 pty 3 ttyp 4 ttyS 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 10 misc 29 fb 90 mtd 123 carneol-htrc110 128 ptm 136 pts 180 usb 189 usb_device 253 usb_endpoint 254 usbmon
This is just heads up, I know that the old interface to registering char devices will be dropped, but when...
regards,
Hinko
Signature · 7 lines
ČETRTA POT, d.o.o., Kranj Planina 3 4000 Kranj Slovenia, Europe Tel. +386 (0) 4 280 66 03 E-mail: [email protected] Http: www.cetrtapot.si
Quoted 3 lines
dev =
MKDEV(htrc110_major, htrc110_minor); ret =register_chrdev_region(dev, 1, mod_name); ret =register_chrdev(dev, mod_name, &htrc110_fops);
If you want to use register_chrdev(), do not make a separate call to register_chrdev_region(). Those two are not meant to work together. register_chrdev() implicitly allocates a region of 256 minors for you.
jon