registering a character driver without cdev_init()/cdev_add()

Robert P. J. Day rpjday at crashcourse.ca
Wed May 4 07:48:42 EDT 2011


On Wed, 4 May 2011, Daniel Baluta wrote:

> >  so rather than the canonical combination of cdev_init() and
> > cdev_add(), this appears to register the pre-defined DSP56K major
> > number, then goes straight to registering the driver with sysfs.
> >
>
> Check register_chrdev code. [1]
> As you can see register_chrdev does cdev_alloc + cdev_add.
>
> >  is this now an alternative way of registering character drivers, if
> > you want to register them with sysfs as well?  as i read it,
> > device_create() will create the /dev file so is this just a newer way
> > to register character drivers?
>
> Yes, it is an alternative way of registering chrdev, but it doesn't have
> anything to do with sysfs layer.
>
> * device_create
>   * creates a device object and link it into sysfs tree.
>   * generates an event -> udev  creates /dev/ file in userspace.
> * register_chrdev - reserves major/minor and sets up char device
> file operations.
> >
> >  i don't think i've run across any other drivers that have this
> > structure but, then again, i haven't been looking that hard.  yet.
>
> thanks,
> Daniel.
>
> [1] http://lxr.linux.no/linux+v2.6.38/fs/char_dev.c#L264

  yes, shortly after i asked, i refreshed my memory and teased out
most of the above, nice to have it confirmed, though.  thanks.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================


More information about the Kernelnewbies mailing list