cdev_device_add(9)
π NAME π
okay bestie, welcome to cdev_device_add(9) from the Kernel API Manual. The NAME section says: add a char device and it's corresponding struct device, linkink. (yes, linkink is literally right there β no cap, we're keeping it π). This is the helper that pairs up a struct cdev and a struct device.
π«Ά SYNOPSIS π«Ά
int cdev_device_add (struct cdev *cdev , struct device *dev );
πΈ ARGUMENTS πΈ
cdevβ thecdevstructure.devβ the device structure.
β¨ DESCRIPTION β¨
Okay so here's the tea. cdev_device_add adds the char device represented by cdev to the system, just as cdev_add does. Then it adds dev to the system using device_add.
The dev_t for the char device will be taken from the struct device, which needs to be initialized first. This helper function correctly takes a reference to the parent device, so the parent will not get released until all references to the cdev are released.
This helper uses dev->devt for the device number. If it is not set, it will not add the cdev and it will be equivalent to device_add.
This function should be used whenever the struct cdev and the struct device are members of the same structure whose lifetime is managed by the struct device.
π NOTE π
Callers must assume that userspace was able to open the cdev and can call cdev fops callbacks at any time, even if this function fails.
That's highkey important, fr fr β even if this function fails, callers still have to assume userspace was able to open the cdev and can call cdev fops callbacks at any time.
π SEE ALSO π
Kernel file ./fs/char_dev.c and all the friends:
register_chrdev_region(9)alloc_chrdev_region(9)__register_chrdev(9)unregister_chrdev_region(9)__unregister_chrdev(9)cdev_add(9)cdev_set_parent(9)cdev_device_del(9)cdev_del(9)cdev_alloc(9)cdev_init(9)
That's the vibe check, bestie: the footer's source/version is ./fs, and the date is October 2026. Go forth and link your cdev/device situation with main character energy π
β¨ periodt.
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms