Character-device number registration in the Linux kernel documentation (source code)

= Character-device number registration in the Linux kernel documentation
{c}

Primary source: https://docs.kernel.org/core-api/kernel-api.html#char-devices

Verified locator: Char devices: register_chrdev_region reserves a requested range; alloc_chrdev_region dynamically chooses the major and returns the first assigned number; cdev_init and cdev_add associate operations and make the device live; __register_chrdev explains that the registration name is not a /dev name. unregister_chrdev_region releases the number reservation; cdev_del prevents new opens while existing file operations can remain callable.

https://docs.kernel.org/core-api/kernel-api.html#char-devices[alloc_chrdev_region returns a zero success status or negative error and writes the first assigned dev_t through its output pointer; unregister_chrdev_region releases the specified first number/count. cdev_add makes the cdev live; cdev_del prevents new opens while existing file operations may remain callable. These are separate reservation and device-object lifetime operations.]

The char-devices API entries distinguish device-number ownership from character-device publication. cdev_del prevents new opens but already-open file operations may still run. The cdev_device_add warning says callers must assume userspace could have opened the device and called its file operations even when the function returns an error; cleanup therefore also requires an appropriate object-lifetime policy. Precise locator: https://docs.kernel.org/core-api/kernel-api.html#char-devices , cdev_add, cdev_del, cdev_device_add and unregister_chrdev_region entries.