]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ntb: idt: Fix error handling in idt_pci_driver_init()
authorYuan Can <yuancan@huawei.com>
Sat, 5 Nov 2022 09:43:01 +0000 (09:43 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Aug 2023 09:33:43 +0000 (11:33 +0200)
commit6a07d3677135010471f616a86fbc78cf5ff9d480
treeeae229ac03fe4bb6b878e8778f20c3985172a401
parent29d6adefcb913657c63e24c532fcf27fd3120aa1
ntb: idt: Fix error handling in idt_pci_driver_init()

[ Upstream commit c012968259b451dc4db407f2310fe131eaefd800 ]

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: bf2a952d31d2 ("NTB: Add IDT 89HPESxNTx PCIe-switches support")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/ntb/hw/idt/ntb_hw_idt.c