clinux-kerneldriver

Does devm_drm_dev_alloc() treat the drm_device as a managed resource of the parent device?


When using a devm_* function, I'm aware that it allocates and manages memory for the resource of a device. I imagine devm_drm_dev_alloc() does the same, but it initializes a drm_device which is also a device (this is where my confusion stems from). So is the drm device treated as a resource for the parent device created by users?


Solution

  • Looking at calls here: devm_drm_dev_alloc calls devm_drm_dev_init(dev, driver, parent) after successful allocation, which in turn calls drm_dev_init(dev, driver, parent) , which in turn calls get_device(parent) to get a handle on the parent to store in the newly allocated device, which calls kobj_get(&dev->kobj) (dev here is the parent device) which does increment the reference counter on the parent.

    So the initialized device will contain a reference to the parent device, and the reference counter on the parent device is incremented accordingly for this new handle.