Skip to contentSkip to conversation

serial: 8250_bcm7271: Fix error handling in brcmuart_init()

PATCH New Yuan Can 2 participants 3 messages Nov 9, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 serial: 8250_bcm7271: Fix error handling in brcmuart_init()

A problem about 8250_bcm7271 create debugfs failed is triggered with the following log given:

 [  324.516635] debugfs: Directory 'bcm7271-uart' with parent '/' already present!

The reason is that brcmuart_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without destroy the newly created debugfs, resulting the debugfs of 8250_bcm7271 can never be created later.

brcmuart_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
---
 drivers/tty/serial/8250/8250_bcm7271.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +9 -1
index fa8ccf204d86..89bfcefbea84 100644
@@ -1212,9 +1212,17 @@ static struct platform_driver brcmuart_platform_driver = {
 
 static int __init brcmuart_init(void)
 {
+	int ret;
+
 	brcmuart_debugfs_root = debugfs_create_dir(
 		brcmuart_platform_driver.driver.name, NULL);
-	return platform_driver_register(&brcmuart_platform_driver);
+	ret = platform_driver_register(&brcmuart_platform_driver);
+	if (ret) {
+		debugfs_remove_recursive(brcmuart_debugfs_root);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(brcmuart_init);
 
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/1 serial: 8250_bcm7271: Fix error handling in brcmuart_init()

A problem about 8250_bcm7271 create debugfs failed is triggered with the following log given:

 [  324.516635] debugfs: Directory 'bcm7271-uart' with parent '/' already present!

The reason is that brcmuart_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without destroy the newly created debugfs, resulting the debugfs of 8250_bcm7271 can never be created later.

brcmuart_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
---
 drivers/tty/serial/8250/8250_bcm7271.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm7271.c +9 -1
index fa8ccf204d86..89bfcefbea84 100644
@@ -1212,9 +1212,17 @@ static struct platform_driver brcmuart_platform_driver = {
 
 static int __init brcmuart_init(void)
 {
+	int ret;
+
 	brcmuart_debugfs_root = debugfs_create_dir(
 		brcmuart_platform_driver.driver.name, NULL);
-	return platform_driver_register(&brcmuart_platform_driver);
+	ret = platform_driver_register(&brcmuart_platform_driver);
+	if (ret) {
+		debugfs_remove_recursive(brcmuart_debugfs_root);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(brcmuart_init);
 
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#2 lore raw
Quoted 18 lines · Yuan Can' via BCM-KERNEL-FEEDBACK-LIST,PDL

A problem about 8250_bcm7271 create debugfs failed is triggered with the following log given:

  [  324.516635] debugfs: Directory 'bcm7271-uart' with parent '/' already present!

The reason is that brcmuart_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without destroy the newly created debugfs, resulting the debugfs of 8250_bcm7271 can never be created later.

brcmuart_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without destroy debugfs directory

Quoted 4 lines

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Signature · 1 line
Florian