Skip to contentSkip to conversation

serial: sunsab: Fix error handling in sunsab_init()

PATCH New Yuan Can 1 participant 1 message Nov 23, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 serial: sunsab: Fix error handling in sunsab_init()

The sunsab_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the allocated sunsab_ports is leaked.
Fix by free sunsab_ports and set it to NULL when platform_driver_register() failed.

Fixes c4d37215a824 ("[SERIAL] sunsab: Convert to of_driver framework.")
---
 drivers/tty/serial/sunsab.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/sunsab.c +7 -1
index 99608b2a2b74..7ace3aa49840 100644
@@ -1133,7 +1133,13 @@ static int __init sunsab_init(void)
 		}
 	}
 
-	return platform_driver_register(&sab_driver);
+	err = platform_driver_register(&sab_driver);
+	if (err) {
+		kfree(sunsab_ports);
+		sunsab_ports = NULL;
+	}
+
+	return err;
 }
 
 static void __exit sunsab_exit(void)
Signature · 1 line
2.17.1