gpt4 book ai didi

c - 调用 `device_show_int()` 是 Linux 内核错误吗?

转载 作者:太空狗 更新时间:2023-10-29 11:37:31 24 4
gpt4 key购买 nike

我首先问了这个问题: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_attributedriver_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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com