在 linux 设备驱动程序中,在 probe
中创建 sysfs 属性太活泼了——特别是,it experiences a race condition with userspace .推荐的解决方法是将您的属性添加到各种默认属性组,以便在探测之前自动创建它们。对于设备驱动程序, struct device_driver
包含 const struct attribute_group **groups
以此目的。
然而, struct attribute_group
只有一个用于二进制属性的字段 in Linux 3.11 .对于较旧的内核(特别是 3.4),设备驱动程序应该如何在探测之前创建 sysfs 二进制属性?
请您参考如下方法:
报价(强调我的)Greg Kroah-Hartman来自他的 comment to a merge request (即 was merged by Linus 作为 3.11 开发周期的一部分):
Here are some driver core patches for 3.11-rc2. They aren't really bugfixes, but a bunch of new helper macros for drivers to properly create attribute groups, which drivers and subsystems need to fix up a ton of race issues with incorrectly creating sysfs files (binary and normal) after userspace has been told that the device is present.
Also here is the ability to create binary files as attribute groups, to solve that race condition, which was impossible to do before this, so that's my fault the drivers were broken.
所以看起来在旧内核上确实没有办法解决这个问题。