我正在将平台驱动程序代码移植到一个PCIe变体上,我不明白为什么不显示一个/dev/条目。已修改的平台驱动程序代码:
static dev_t first;
static struct class * class;
ATTRIBUTE_GROUPS(my);
static int __init my_pci_init(void)
{
    int ret;
    /* Create a class entry in sysfs */
    if ((class = class_create(THIS_MODULE, "test_driver")) == NULL) {
        pr_err("Couldn't create 'struct class' structure.");
        ret = -ENODEV;
        goto exit;
    }
    class->dev_groups = my_groups;
    /* Create the /dev/ file system entry */
    /* return value ignored: there's a 'struct class' to 'struct device' mapping */
    if (device_create(class, NULL, first, NULL, KBUILD_MODNAME) == NULL) {
        pr_err("Couldn't create entry in '/dev/' file system.");
        ret = -ENODEV;
        goto exit;
    } else {
        pr_info("Created a /dev/ entry.");
    }
    if ((ret = pci_register_driver(&pci_driver)) < 0) {
        pr_err("Couldn't register pci driver.");
    }
 exit:
    if (ret < 0) {
        my_pci_exit();
        pr_err(" ret = %d", ret);
    }
    return ret;
}
module_init(my_pci_init);如果模块名为'cz_tdm',我希望上面的代码能够创建一个条目/dev/cz_tdm。至少当我把它编译成一个平台驱动程序时,它做到了。
驱动程序枚举得很好,lspci的输出显示驱动程序已经加载,仔细阅读sysfs显示了我在/sys/devices/virtual/...中的所有属性都在我期望的位置。
怎么回事?
发布于 2014-10-08 17:06:37
哇哦。
因为这不应该太过。对代码的过度删除删除了这个必要的元素:
/* Add the char device to the system. */
cdev_init(&cdev, &fops);
if ((ret = cdev_add(&cdev, first, DEV_MINOR_NUMBER_COUNT)) < 0) {
    pr_err("Couldn't add device to system: %d", ret);
    ret = -ENODEV;
    goto exit;
}https://stackoverflow.com/questions/26262040
复制相似问题