Character-device lifetime after deletion 2026-11-05
Character-device lifetime after deletion is the interval during which a removed character device still needs valid backing state because existing users can invoke its operations. Linux
cdev_del removes the device from new-open lookup; it does not invalidate already-open file descriptors. The kernel explicitly permits their file-operation callbacks after deletion returns.[ref]Character-device number registration in the Linux kernel documentation. Char devices, cdev_del lifetime note
Consider an original event sequence. Process A opens an interface and retains a pointer to driver state. Removal calls
cdev_del; process B can no longer obtain a new open through that registration. Process A then calls read. Freeing the state immediately after deletion would make that callback access dead storage: a use-after-free. The lookup lifetime and the backing allocation lifetime are different.A useful ownership model gives the allocation one registration reference and one reference for each successful open. In a simplified reference counting design with opens, the reference count is . Removal drops the registration reference; each final close drops its open reference. With two opens, the sequence is , and storage is reclaimed only at zero. This is a model of ownership, not a complete driver implementation: taking references must itself be synchronized with removal, and asynchronous work can require additional references.
The character device may be disconnected from its hardware before its storage is reclaimed. Existing operations can observe a synchronized disconnected state and return an appropriate error while the allocation remains valid. Reference protection alone does not make removed hardware usable or serialize simultaneous operations.
For combined device objects,
cdev_device_add and cdev_device_del have their own documented pairing and parent-reference rules. The add helper can expose callbacks even when it reports failure; the delete helper distinguishes stopped sysfs callbacks from still-callable operations on existing opens.[ref]Character-device number registration in the Linux kernel documentation. cdev_device_add description and failure warning; cdev_device_del note
Therefore unwinding a failed character-device registration must follow the actual publication and ownership state. Releasing the device number reservation is separate from proving that every user of private storage has finished. Device node 2026-11-05
A device node is a special file system object through which a program accesses a device interface. In the Linux model, its inode records a device-special file type and a device number; the path supplies a name in the file-system namespace. Opening it supplies a file descriptor through which the applicable device driver handles operations. Device-special objects differ from ordinary files containing a stored byte sequence.[ref]
Device file metadata in the Linux man-pages project. inode(7), device ID and file types; mknod(2), DESCRIPTION
Two device identifiers must be distinguished. The metadata field
st_dev identifies the device containing the file system that holds the inode. For a character device or block device, st_rdev instead identifies the represented device. Its major and minor numbers belong to that represented-device identification. The inode's own number is a third identifier.[ref]Device file metadata in the Linux man-pages project. inode(7), Device where inode resides and Device ID; mknod(2), dev argument
For an original metadata example, stipulate that names
/dev/example-a and /dev/example-b reach different inodes numbered 42 and 43 in one file system. Both inodes have character-device type and represented-device numbers (240,7). They name the same device interface in this example despite being different named file-system objects. Different permissions on the nodes can still affect access. Their inode numbers alone do not identify two physical devices.A character device presents a driver-defined stream or control interface; it need not contain human-readable characters. A block device presents block-oriented storage access. The special-file type is part of the identification, so equal numerical major/minor pairs do not alone equate character and block interfaces. A video device node is a concrete Video4Linux example, whose supported functions must still be queried.
Creating a device-special file supplies a namespace entry and device identification; it does not manufacture hardware, load a guaranteed working driver or establish a supported data format. Conversely, a symbolic link pointing to a device node is an ordinary naming indirection: its target's special-file metadata determines the accessed interface.