What is the difference between cdev_alloc and cdev_init

I am creating a personal device. I found two ways to initialize a char device

cdev_alloc

and

cdev_init

According to the book, if I embed a struct cdevdevice in my structure, I should usecdev_init

Can someone tell me what is the difference between them?

+4
source share
3 answers

According to linux 3rd edition device drivers.

cdev_alloc() . cdev . ops cdev. cdev_init . cdev ( cdev) , .

http://lwn.net/Kernel/LDD3/

3

+2

LDD3 cdev_init cdev NULL, struct cdev dev, kripanand, struct cdev * dev dev- kzalloc, kmalloc memset . cdev_alloc .

cdev_alloc

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

:

struct scull_dev {
       struct cdev my_cdev;
   } my_scull_dev;

cdev_alloc, . cdev_init(&my_scull_dev.my_cdev, &fops). my_scull_dev.my_cdev.owner = THIS_MODULE;

:

struct cdev *my_cdev_p;

cdev_alloc() . my_cdev_p->ops=&fops; my_cdev_p->owner = THIS_MODULE;

, .

0

All Articles