x86/platform/intel/iosf_mbi: Fix error handling in iosf_mbi_init()
Subsystems (2)
PATCH 1/1 x86/platform/intel/iosf_mbi: Fix error handling in iosf_mbi_init()
A problem about modprobe iosf_mbi failed is triggered with the following log given:
debugfs: Directory 'iosf_sb' with parent '/' already present!
The reason is that iosf_mbi_init() returns pci_register_driver() directly without checking its return value, if pci_register_driver() failed, it returns without removing debugfs, resulting the debugfs of iosf_sb can never be created later.
iosf_mbi_init()
iosf_mbi_dbg_init() # create debugfs
pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without remove debugfs and destroy workqueue
Fix by remove debugfs and iosf_mbi_pm_qos when pci_register_driver() returns error.
--- arch/x86/platform/intel/iosf_mbi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/platform/intel/iosf_mbi.c +9 -1
@@ -545,11 +545,19 @@ static struct pci_driver iosf_mbi_pci_driver = {static int __init iosf_mbi_init (void ) { +int ret; +iosf_debugfs_init ();cpu_latency_qos_add_request (&iosf_mbi_pm_qos,PM_QOS_DEFAULT_VALUE ); -return pci_register_driver (&iosf_mbi_pci_driver); + ret =pci_register_driver (&iosf_mbi_pci_driver); +if (ret) { +cpu_latency_qos_remove_request (&iosf_mbi_pm_qos); +iosf_debugfs_remove (); + } + +return ret; } static void __exit iosf_mbi_exit(void)
Signature · 1 line
2.17.1
Quoted 17 lines · Yuan Can
A problem about modprobe
iosf_mbifailed is triggered with the following log given:debugfs: Directory '
iosf_sb' with parent '/' already present!The reason is that
iosf_mbi_init()returnspci_register_driver()directly without checking its return value, ifpci_register_driver()failed, it returns without removing debugfs, resulting the debugfs ofiosf_sbcan never be created later.
iosf_mbi_init()
iosf_mbi_dbg_init()# create debugfs
pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
Quoted 3 lines
# return without remove debugfs and destroy workqueueFix by remove debugfs and
iosf_mbi_pm_qoswhenpci_register_driver()
removing
Quoted 9 lines
returns error.
static int
__initiosf_mbi_init(void)
{arch/x86/platform/intel/iosf_mbi.c +2
-0+int ret; +iosf_debugfs_init ();cpu_latency_qos_add_request (&iosf_mbi_pm_qos,PM_QOS_DEFAULT_VALUE );
arch/x86/platform/intel/iosf_mbi.c static struct pci_driver iosf_mbi_pci_driver = { · line 561
Quoted 10 lines
arch/x86/platform/intel/iosf_mbi.c +7
-1-return pci_register_driver (&iosf_mbi_pci_driver); + ret =pci_register_driver (&iosf_mbi_pci_driver); +if (ret) { +cpu_latency_qos_remove_request (&iosf_mbi_pm_qos); +iosf_debugfs_remove (); + } + +return ret; }
Can we rewrite it as
if (ret)
goto err_remove;
return 0;
err_remove:
...
return ret;
?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 47 lines · Andy Shevchenko
Quoted 18 lines · Yuan Can
A problem about modprobe
iosf_mbifailed is triggered with the following log given:debugfs: Directory '
iosf_sb' with parent '/' already present!The reason is that
iosf_mbi_init()returnspci_register_driver()directly without checking its return value, ifpci_register_driver()failed, it returns without removing debugfs, resulting the debugfs ofiosf_sbcan never be created later.
iosf_mbi_init()
iosf_mbi_dbg_init()# create debugfspci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without remove debugfs and destroy workqueueQuoted 1 line
Fix by remove debugfs and
iosf_mbi_pm_qoswhenpci_register_driver()removing
Quoted 8 lines
returns error.
static int__initiosf_mbi_init(void)
{arch/x86/platform/intel/iosf_mbi.c +2
-0+int ret; +iosf_debugfs_init ();cpu_latency_qos_add_request (&iosf_mbi_pm_qos,PM_QOS_DEFAULT_VALUE );arch/x86/platform/intel/iosf_mbi.c static struct pci_driver iosf_mbi_pci_driver = { · line 561
Quoted 10 lines
arch/x86/platform/intel/iosf_mbi.c +7
-1-return pci_register_driver (&iosf_mbi_pci_driver); + ret =pci_register_driver (&iosf_mbi_pci_driver); +if (ret) { +cpu_latency_qos_remove_request (&iosf_mbi_pm_qos); +iosf_debugfs_remove (); + } + +return ret; }Can we rewrite it as
if (ret) goto err_remove; return 0;
Quoted 5 lines
err_remove:... return ret;?
Thanks for these suggestions! will be changed in the next version.
Signature · 2 lines
Best regards, Yuan Can