- 论坛徽章:
- 0
|
在LDD3字符设备驱动程序章节中,
给出的注册字符设备的代码是这样:
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); /* A */
dev->cdev.owner = THISMODULE;
dev->cdev.ops = &scull_fops; /* B */
err = cdev_add(&dev->cdev,devno,1);
}
其中cdev_init函数原型:
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;
}
在这个函数中,已经有给cdev->ops赋值了。
为什么还要在行B中再次给它赋值呢? |
|