Skip to content

Commit 98af0a3

Browse files
Yuan Canjonmason
authored andcommitted
NTB: amd: Fix error handling in amd_ntb_pci_driver_init()
A problem about ntb_hw_amd create debugfs failed is triggered with the following log given: [ 618.431232] AMD(R) PCI-E Non-Transparent Bridge Driver 1.0 [ 618.433284] debugfs: Directory 'ntb_hw_amd' with parent '/' already present! The reason is that amd_ntb_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_amd can never be created later. amd_ntb_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: a1b3695 ("NTB: Add support for AMD PCI-Express Non-Transparent Bridge") Signed-off-by: Yuan Can <yuancan@huawei.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent c012968 commit 98af0a3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/ntb/hw/amd/ntb_hw_amd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,12 +1338,17 @@ static struct pci_driver amd_ntb_pci_driver = {
13381338

13391339
static int __init amd_ntb_pci_driver_init(void)
13401340
{
1341+
int ret;
13411342
pr_info("%s %s\n", NTB_DESC, NTB_VER);
13421343

13431344
if (debugfs_initialized())
13441345
debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
13451346

1346-
return pci_register_driver(&amd_ntb_pci_driver);
1347+
ret = pci_register_driver(&amd_ntb_pci_driver);
1348+
if (ret)
1349+
debugfs_remove_recursive(debugfs_dir);
1350+
1351+
return ret;
13471352
}
13481353
module_init(amd_ntb_pci_driver_init);
13491354

0 commit comments

Comments
 (0)