【问题标题】:Why does this device_create() call not create a /dev/ entry?为什么这个 device_create() 调用不创建 /dev/ 条目?
【发布时间】:2014-10-08 16:40:23
【问题描述】:

我正在将平台驱动程序代码移植到 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/... 中的所有属性都在我期望的位置。

什么给了?

【问题讨论】:

    标签: driver linux-device-driver pci pci-e


    【解决方案1】:

    哎呀。

    因为它也不应该。对代码的过分删除删除了这个必要的元素:

    /* 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多