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

标签 c linux linux-kernel

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

相关文章:

c++ - 在多线程 HTTP 服务器中发送后如何干净地关闭套接字?

c - 返回字符数组??(C)

linux - 在yocto上构建docker

c - 了解用于处理文件描述符的linux内核数据结构

linux - 像 KVM 这样的虚拟机管理程序是否需要在 CPUID 上退出 VM?

打开文件时的 C 编程 fopen()

c++ - 一种覆盖文件中少数位置的方法

php - 如何保护您网站上的文件

ruby-on-rails - 在 Linux 机器上为 Rails 项目安装 Postgres 的技巧

linux - 关于linux程序内存布局schema的问题