All of lore.kernel.org
 help / color / mirror / Atom feed
* register_chrdev vs. cdev_add
@ 2008-05-14 12:31 Hinko Kočevar
  2008-05-14 14:01 ` Jonathan Corbet
  0 siblings, 1 reply; 2+ messages in thread
From: Hinko Kočevar @ 2008-05-14 12:31 UTC (permalink / raw)
  To: linux-kernel

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

-- 
ČETRTA POT, d.o.o., Kranj
Planina 3
4000 Kranj
Slovenia, Europe
Tel. +386 (0) 4 280 66 03
E-mail: hinko.kocevar@cetrtapot.si
Http: www.cetrtapot.si


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: register_chrdev vs. cdev_add
  2008-05-14 12:31 register_chrdev vs. cdev_add Hinko Kočevar
@ 2008-05-14 14:01 ` Jonathan Corbet
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Corbet @ 2008-05-14 14:01 UTC (permalink / raw)
  To: Hinko Kočevar; +Cc: linux-kernel

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-05-14 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-14 12:31 register_chrdev vs. cdev_add Hinko Kočevar
2008-05-14 14:01 ` Jonathan Corbet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.