Commit c0129682 authored by Yuan Can's avatar Yuan Can Committed by Jon Mason

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: bf2a952d ("NTB: Add IDT 89HPESxNTx PCIe-switches support")
Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
Signed-off-by: default avatarJon Mason <jdmason@kudzu.us>
parent 6995e2de
...@@ -2891,6 +2891,7 @@ static struct pci_driver idt_pci_driver = { ...@@ -2891,6 +2891,7 @@ static struct pci_driver idt_pci_driver = {
static int __init idt_pci_driver_init(void) static int __init idt_pci_driver_init(void)
{ {
int ret;
pr_info("%s %s\n", NTB_DESC, NTB_VER); pr_info("%s %s\n", NTB_DESC, NTB_VER);
/* Create the top DebugFS directory if the FS is initialized */ /* Create the top DebugFS directory if the FS is initialized */
...@@ -2898,7 +2899,11 @@ static int __init idt_pci_driver_init(void) ...@@ -2898,7 +2899,11 @@ static int __init idt_pci_driver_init(void)
dbgfs_topdir = debugfs_create_dir(KBUILD_MODNAME, NULL); dbgfs_topdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
/* Register the NTB hardware driver to handle the PCI device */ /* Register the NTB hardware driver to handle the PCI device */
return pci_register_driver(&idt_pci_driver); ret = pci_register_driver(&idt_pci_driver);
if (ret)
debugfs_remove_recursive(dbgfs_topdir);
return ret;
} }
module_init(idt_pci_driver_init); module_init(idt_pci_driver_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment