what is difference between cdev_alloc and cdev_init

后端 未结 3 1052
渐次进展
渐次进展 2021-01-13 06:24

I\'m creating a character device. I found two way to initialize char device

cdev_alloc

and

cdev_init

Acc

3条回答
  •  日久生厌
    2021-01-13 07:00

    According to LDD3 for using cdev_init cdev should be initialized and shouldn't be NULL, so either use struct cdev dev as suggested by kripanand or if using struct cdev *dev then allocate dev memory using kzalloc, if using kmalloc memset would be required. This is wat cdev_alloc does.

    I've now replaced cdev_alloc in my code as

    //vcar->dev=cdev_alloc;
    vcar->dev=kzalloc(sizeof(struct cdev),GFP_KERNEL);
    

提交回复
热议问题