Skip to contentSkip to conversation

x86/platform/intel/iosf_mbi: Fix error handling in iosf_mbi_init()

PATCH In review Yuan Can 2 participants 2 messages Nov 15, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH v2 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 removing debugfs and iosf_mbi_pm_qos when pci_register_driver() returns error.

Fixes 8dc12f933c9d ("x86/iosf: Add debugfs support")
Fixes e09db3d241f8 ("x86: baytrail/cherrytrail: Rework and move P-Unit PMIC bus semaphore code")

---
Changes in v2:
- fix typos in commit msg
- change to the suggested error handling style

 arch/x86/platform/intel/iosf_mbi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
arch/x86/platform/intel/iosf_mbi.c +13 -1
index fdd49d70b437..2d64985c53f9 100644
@@ -545,11 +545,23 @@ 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)
+		goto err_remove;
+
+	return 0;
+
+err_remove:
+	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
Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 16 lines · Yuan Can

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

Quoted 8 lines
   # return without remove debugfs and destroy workqueue

Fix by removing debugfs and iosf_mbi_pm_qos when pci_register_driver() returns error.

Fixes 8dc12f933c9d ("x86/iosf: Add debugfs support")
Fixes e09db3d241f8 ("x86: baytrail/cherrytrail: Rework and move P-Unit PMIC bus semaphore code")

Thanks, patch looks good to me:

Regards,

Hans

Quoted 36 lines

---
Changes in v2:
- fix typos in commit msg
- change to the suggested error handling style

 arch/x86/platform/intel/iosf_mbi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
arch/x86/platform/intel/iosf_mbi.c +13 -1
index fdd49d70b437..2d64985c53f9 100644
@@ -545,11 +545,23 @@ 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)
+		goto err_remove;
+
+	return 0;
+
+err_remove:
+	cpu_latency_qos_remove_request(&iosf_mbi_pm_qos);
+	iosf_debugfs_remove();
+
+	return ret;
 }
 
 static void __exit iosf_mbi_exit(void)