在Linux设备驱动程序中,创建sysfs属性probe过于活泼 - 特别是,它遇到了与用户空间的竞争条件.建议的解决方法是将属性添加到各种默认属性组,以便在探测之前自动创建它们.对于设备驱动程序,struct device_driver包含const struct attribute_group **groups此目的.
但是,在Linux 3.11中struct attribute_group只有二进制属性的字段.对于较旧的内核(特别是3.4),设备驱动程序如何在探测之前创建sysfs二进制属性?
我是Linux内核模块编程的新手.从我到目前为止阅读的材料中,我发现用户程序有3种方式来请求服务或与Linux内核模块通信
问题:我们还有哪些其他选项可用于用户程序和Linux内核模块之间的通信?
编辑#4:
我想通了,我不应该被分配attr_groups到groups该领域driver中的场struct platform_driver结构。寻找/* WRONGO: should not be assigned here. */下面的评论。
我还没想好我应该把它分配在哪里......
由于 NULL 引用,我的平台驱动程序代码在读取 sysfs 属性时设法导致内核“OOPS”。我确定这是以下代码中的一个简单疏忽,但我看不到它:
...
static int samples_per_frame = SAMPLE_CHANNEL_COUNT;
DEVICE_INT_ATTR(samples_per_frame, S_IRUGO | S_IWUSR, samples_per_frame);
static struct attribute *attrs[] = {
&dev_attr_samples_per_frame.attr.attr, NULL,
};
static struct attribute_group attr_group = {
.attrs = attrs,
};
static const struct attribute_group *attr_groups[] = {
&attr_group, NULL,
};
static struct platform_driver platform = {
.remove = my_remove,
.probe = my_probe, …Run Code Online (Sandbox Code Playgroud)