[PATCH] serial: pl011: Fix error handling in pl011_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When amba_driver_register failed, we need to unregister the platform
driver which have been registered, otherwise there maybe resource leak,
so we add error handlings in pl011_init() to fix it.

Fixes: 0dd1e247fd39 ("drivers: PL011: add support for the ARM SBSA generic UART")
Signed-off-by: Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>
---
 drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 6d8552506091..ef6d9941f972 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2982,11 +2982,23 @@ static struct amba_driver pl011_driver = {
 
 static int __init pl011_init(void)
 {
+	int ret;
+
 	printk(KERN_INFO "Serial: AMBA PL011 UART driver\n");
 
-	if (platform_driver_register(&arm_sbsa_uart_platform_driver))
+	ret = platform_driver_register(&arm_sbsa_uart_platform_driver);
+	if (unlikely(ret)) {
 		pr_warn("could not register SBSA UART platform driver\n");
-	return amba_driver_register(&pl011_driver);
+		return ret;
+	}
+
+	ret = amba_driver_register(&pl011_driver);
+	if (unlikely(ret)) {
+		platform_driver_unregister(&arm_sbsa_uart_platform_driver);
+		return ret;
+	}
+
+	return 0;
 }
 
 static void __exit pl011_exit(void)
-- 
2.25.1




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux