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

Robert P. J. Day rpjday at crashcourse.ca
Wed May 4 06:55:17 EDT 2011


  continuing my perusal of various character drivers under
drivers/char/ to find good examples for an intro class, i notice
dsp56k.c, whose init routine contains the snippet:

===== start =====

        if(register_chrdev(DSP56K_MAJOR, "dsp56k", &dsp56k_fops)) {
                printk("DSP56k driver: Unable to register driver\n");
                return -ENODEV;
        }
        dsp56k_class = class_create(THIS_MODULE, "dsp56k");
        if (IS_ERR(dsp56k_class)) {
                err = PTR_ERR(dsp56k_class);
                goto out_chrdev;
        }
        device_create(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), NULL,
                      "dsp56k");

        printk(banner);
        goto out;

out_chrdev:
        unregister_chrdev(DSP56K_MAJOR, "dsp56k");
out:
        return err;
}

===== end ====

  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.

  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?

  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.

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