Skip to content

Commit c012968

Browse files
Yuan Canjonmason
authored andcommitted
ntb: idt: Fix error handling in idt_pci_driver_init()
A problem about ntb_hw_idt create debugfs failed is triggered with the following log given: [ 1236.637636] IDT PCI-E Non-Transparent Bridge Driver 2.0 [ 1236.639292] debugfs: Directory 'ntb_hw_idt' with parent '/' already present! The reason is that idt_pci_driver_init() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without destroy the newly created debugfs, resulting the debugfs of ntb_hw_idt can never be created later. idt_pci_driver_init() debugfs_create_dir() # create debugfs directory pci_register_driver() driver_register() bus_add_driver() priv = kzalloc(...) # OOM happened # return without destroy debugfs directory Fix by removing debugfs when pci_register_driver() returns error. Fixes: bf2a952 ("NTB: Add IDT 89HPESxNTx PCIe-switches support") Signed-off-by: Yuan Can <yuancan@huawei.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent 6995e2d commit c012968

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/ntb/hw/idt/ntb_hw_idt.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,14 +2891,19 @@ static struct pci_driver idt_pci_driver = {
28912891

28922892
static int __init idt_pci_driver_init(void)
28932893
{
2894+
int ret;
28942895
pr_info("%s %s\n", NTB_DESC, NTB_VER);
28952896

28962897
/* Create the top DebugFS directory if the FS is initialized */
28972898
if (debugfs_initialized())
28982899
dbgfs_topdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
28992900

29002901
/* Register the NTB hardware driver to handle the PCI device */
2901-
return pci_register_driver(&idt_pci_driver);
2902+
ret = pci_register_driver(&idt_pci_driver);
2903+
if (ret)
2904+
debugfs_remove_recursive(dbgfs_topdir);
2905+
2906+
return ret;
29022907
}
29032908
module_init(idt_pci_driver_init);
29042909

0 commit comments

Comments
 (0)