2014-10-08 17 views
1

我正在將平臺驅動程序代碼移植到PCIe變體,我不明白爲什麼我沒有得到/dev/條目顯示。已被修改的平臺驅動程序代碼:爲什麼此device_create()調用不會創建一個/ dev/entry?

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/...所有屬性,我希望他們是。

什麼給?

回答

2

哎呦。

因爲它不應該太。代碼的過度刪除扯掉了這個必要的元素:

/* 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; 
} 
相關問題