On Tue, 26 Aug 2014 20:48:41 -0400, John de la Garza said:
In the book Linux Device Drivers a struct cdev is setup like this:
static void scull_setup_cdev(struct scull_dev *dev, int index) { int err, devno = MKDEV(scull_major, scull_minor + index);
cdev_init(&dev->cdev, &scull_fops); dev->cdev.owner = THIS_MODULE; dev->cdev.ops = &scull_fops; ...
the code for cdev_init does this: void cdev_init(struct cdev *cdev, const struct file_operations *fops) { memset(cdev, 0, sizeof *cdev); INIT_LIST_HEAD(&cdev->list); kobject_init(&cdev->kobj, &ktype_cdev_default); cdev->ops = fops; }
Why does the code from ldd3 set dev->cdev.ops = &scull_fops again?
Probably because when ldd3 was written several years ago, cdev_init() didn't set it, so it wasn't "again"....
Doesn't cdev_init already do that?
It does *now*. Remember that ldd3 was written about 6 million lines of code ago....