cdev_add()¶
Purpose¶
Registers a struct cdev with the VFS so file operations can be reached through a device node.
Header¶
Prototype¶
Parameters¶
p: initializedstruct cdev.dev: first device number.count: number of device numbers handled.
Return Value¶
- Success: returns
0. - Failure: returns a negative errno value.
Minimal Example¶
cdev_init(&mydev->cdev, &mydev_fops);
mydev->cdev.owner = THIS_MODULE;
ret = cdev_add(&mydev->cdev, devt, 1);
Common Pitfalls¶
- Call
cdev_del()during cleanup. - Initialize
file_operationsbeforecdev_add(). - Do not expose the device node before the driver state is ready.