---
name: "cdev_device_add"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/cdev_device_add"
---

# cdev\_device\_add(9)

add a char device and it's corresponding struct device, linkink

## NAME

cdev\_device\_add - add a char device and it's corresponding struct device, linkink

## SYNOPSIS

**int cdev\_device\_add(struct cdev \*** *cdev***, struct device \*** *dev***);**

## ARGUMENTS

*cdev*

the cdev structure

*dev*

the device structure

## DESCRIPTION

**cdev\_device\_add** adds the char device represented by *cdev* to the system, just as cdev\_add does. It then 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.

## COPYRIGHT
