Jam*_*mie 2 c linux linux-kernel
我首先提出这个问题:如何为平台驱动程序正确初始化属性组?
并得出结论,函数调用device_show_int()正在使用错误的函数原型.
代码问题首先struct dev_ext_attribute使用DEVICE_INT_ATTR()宏定义   结构.该[struct device_attribute][1]结构将show字段定义为指向函数的指针,该函数采用三(3)个参数:
struct device_attribute {
    struct attribute        attr;
    ssize_t (*show)(struct device *dev, struct device_attribute *attr,
                    char *buf);
    ssize_t (*store)(struct device *dev, struct device_attribute *attr,
                     const char *buf, size_t count);
};
Run Code Online (Sandbox Code Playgroud)
然而在我的调用堆栈中(请参考上面提到的问题),只使用drv_attr_show()中的两(2)个参数调用dereferenced函数:
if (drv_attr->show)
        ret = drv_attr->show(drv_priv->driver, buf);
Run Code Online (Sandbox Code Playgroud)
这看起来非常令人震惊,它是一个错误还是我以某种方式设法搞砸了内核构建?(ARM,内核3.12)
你是混乱device_attribute和driver_attribute.该函数drv_attr_show()适用于a struct driver_attribute,其定义为:
struct driver_attribute {
    struct attribute attr;
    ssize_t (*show)(struct device_driver *driver, char *buf);
    ssize_t (*store)(struct device_driver *driver, const char *buf,
                     size_t count);
};
Run Code Online (Sandbox Code Playgroud)
所以这里没有错误.