我首先问这个问题:How do I initialize the attribute group correctly for a platform driver?
得出的结论是,调用 device_show_int()
的函数使用了错误的函数原型(prototype)。
代码问题首先使用 DEVICE_INT_ATTR()
宏定义 struct dev_ext_attribute
结构。 [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);
};
然而,在我的调用堆栈中(请参阅上面提到的问题),仅使用 drv_attr_show() 中的两 (2) 个参数调用取消引用的函数。 :
if (drv_attr->show)
ret = drv_attr->show(drv_priv->driver, buf);
这看起来非常令人震惊,这是一个错误还是我以某种方式搞砸了内核构建?(ARM,内核 3.12)
最佳答案
您混淆了 device_attribute
和 driver_attribute
。函数 drv_attr_show()
作用于 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);
};
所以这里没有错误。
关于c - 对 `device_show_int()` 的调用是 Linux 内核错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24621955/