cdev_device_add(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 β€” the cdev structure.
  • 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:


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