c - 平台设备;为什么是 'alloc' 和 'add' ?

标签 c linux kernel linux-device-driver device-driver

我目前正在寻找 sound/soc/imx 中的机器驱动程序。 在初始化函数中有,按此顺序;

platform_driver_register(...);
...
platform_device_alloc(..., ...);
platform_set_drvdata(..., ...);
platform_device_add(...);
...

对于平台设备,为什么要先“alloc”再“add”?
platform_device_alloc() 表示“创建平台设备”platform_device_add() 表示“将平台设备添加到设备层次结构”,所以我很想知道,为什么您需要两者?

最佳答案

platform_device_alloc 函数仅执行 platform_device 结构的内存分配并使用外部参数初始化其变量。

http://lxr.free-electrons.com/source/drivers/base/platform.c#L197

platform_device_add 函数执行在设备驱动程序层次结构中注册预期设备所需的所有任务。

http://lxr.free-electrons.com/source/drivers/base/platform.c#L277

这两个功能的分离旨在允许驱动程序开发人员在需要时进行粒度级别的配置。

这两个操作结合在 platform_device_register_simple 和其他相关函数中,执行内存分配和设备注册。

关于c - 平台设备;为什么是 'alloc' 和 'add' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21011575/

相关文章:

c - 需要透明类型的好处和情况是什么?

c - 创建一个 for 循环来编辑数据结构中的列表

c++ - 贝塞尔曲线绘制例程到定点(如何重写)

c++ - 为什么ELF中有其他共享库的函数长度信息?

c - 内核模块中的 Stackoverflow

winapi - 从内核模式关闭 Windows?

c - read()如何将32位int放在缓冲区中?

java - Linux下的Arduino(RXTX)? - 适用于 Windows

php - 使用 PHP 进行数据转换和加载

c - 当我编译我的内核时,是什么导致了这个奇怪的警告?传递不兼容的指针类型,期望结构 * 但得到结构 *