Skip to contentSkip to conversation

sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init()

PATCH Superseded Mao Wenan 2 participants 3 messages Mar 9, 2019 – Mar 11, 2019 1 message not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Mao Wenan

author
#0 lore raw

PATCH v2 1/1 sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init()

Add the missing uart_unregister_driver() and i2c_del_driver() before return from sc16is7xx_init() in the error handling case.

---
v1->v2: fix compile warning if CONFIG_SERIAL_SC16IS7XX_SPI is not exist.

 drivers/tty/serial/sc16is7xx.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/tty/serial/sc16is7xx.c +12 -2
index 268098681856..b9e5941ce767 100644
@@ -1509,7 +1509,7 @@ static int __init sc16is7xx_init(void)
 	ret = i2c_add_driver(&sc16is7xx_i2c_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx i2c --> %d\n", ret);
-		return ret;
+		goto err_i2c;
 	}
 #endif
 
@@ -1517,10 +1517,20 @@ static int __init sc16is7xx_init(void)
 	ret = spi_register_driver(&sc16is7xx_spi_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx spi --> %d\n", ret);
-		return ret;
+		goto err_spi;
 	}
 #endif
 	return ret;
+
+#ifdef CONFIG_SERIAL_SC16IS7XX_SPI
+err_spi:
+#endif
+#ifdef CONFIG_SERIAL_SC16IS7XX_I2C
+	i2c_del_driver(&sc16is7xx_i2c_uart_driver);
+err_i2c:
+#endif
+	uart_unregister_driver(&sc16is7xx_uart);
+	return ret;
 }
 module_init(sc16is7xx_init);
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 32 lines · Mao Wenan

Add the missing uart_unregister_driver() and i2c_del_driver() before return from sc16is7xx_init() in the error handling case.

---
v1->v2: fix compile warning if CONFIG_SERIAL_SC16IS7XX_SPI is not exist.

 drivers/tty/serial/sc16is7xx.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/tty/serial/sc16is7xx.c +2 -2
index 268098681856..b9e5941ce767 100644
@@ -1509,7 +1509,7 @@ static int __init sc16is7xx_init(void)
 	ret = i2c_add_driver(&sc16is7xx_i2c_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx i2c --> %d\n", ret);
-		return ret;
+		goto err_i2c;
 	}
 #endif
 
@@ -1517,10 +1517,20 @@ static int __init sc16is7xx_init(void)
 	ret = spi_register_driver(&sc16is7xx_spi_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx spi --> %d\n", ret);
-		return ret;
+		goto err_spi;
 	}
 #endif
 	return ret;

drivers/tty/serial/sc16is7xx.c static int __init sc16is7xx_init(void) · line 1533

Quoted 10 lines
drivers/tty/serial/sc16is7xx.c +10 -0
+
+#ifdef CONFIG_SERIAL_SC16IS7XX_SPI
+err_spi:
+#endif
+#ifdef CONFIG_SERIAL_SC16IS7XX_I2C
+	i2c_del_driver(&sc16is7xx_i2c_uart_driver);
+err_i2c:
+#endif
+	uart_unregister_driver(&sc16is7xx_uart);
+	return ret;

This is quite ulgy. Why not create two functions:

drivers/tty/serial/sc16is7xx.c +15 -0
index 635178cf3eed..9986cb2479ad 100644
@@ -1491,6 +1491,21 @@ static struct i2c_driver sc16is7xx_i2c_uart_driver = {
 	.id_table	= sc16is7xx_i2c_id_table,
 };
 
+static int __init register_sc16is7xx_i2c(void)
+{
+	return i2c_add_driver(&sc16is7xx_i2c_uart_driver);
+}
+
+static void __exit del_sc16is7xx_i2c(void)
+{
+	i2c_del_driver(&sc16is7xx_i2c_uart_driver);
+}
+
+#else
+
+static int __init register_sc16is7xx_i2c(void) { return 0; }
+static void __exit del_sc16is7xx_i2c(void) {}
+
 #endif
 
 static int __init sc16is7xx_init(void)

Then you can remove all the ifdefs.

regards,
dan carpenter

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 74 lines · maowenan
Quoted 71 lines · Dan Carpenter
Quoted 32 lines · Mao Wenan

Add the missing uart_unregister_driver() and i2c_del_driver() before return from sc16is7xx_init() in the error handling case.

---
v1->v2: fix compile warning if CONFIG_SERIAL_SC16IS7XX_SPI is not exist.

 drivers/tty/serial/sc16is7xx.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/tty/serial/sc16is7xx.c +2 -2
index 268098681856..b9e5941ce767 100644
@@ -1509,7 +1509,7 @@ static int __init sc16is7xx_init(void)
 	ret = i2c_add_driver(&sc16is7xx_i2c_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx i2c --> %d\n", ret);
-		return ret;
+		goto err_i2c;
 	}
 #endif
 
@@ -1517,10 +1517,20 @@ static int __init sc16is7xx_init(void)
 	ret = spi_register_driver(&sc16is7xx_spi_uart_driver);
 	if (ret < 0) {
 		pr_err("failed to init sc16is7xx spi --> %d\n", ret);
-		return ret;
+		goto err_spi;
 	}
 #endif
 	return ret;

drivers/tty/serial/sc16is7xx.c static int __init sc16is7xx_init(void) · line 1533

Quoted 10 lines
drivers/tty/serial/sc16is7xx.c +10 -0
+
+#ifdef CONFIG_SERIAL_SC16IS7XX_SPI
+err_spi:
+#endif
+#ifdef CONFIG_SERIAL_SC16IS7XX_I2C
+	i2c_del_driver(&sc16is7xx_i2c_uart_driver);
+err_i2c:
+#endif
+	uart_unregister_driver(&sc16is7xx_uart);
+	return ret;

This is quite ulgy. Why not create two functions:

drivers/tty/serial/sc16is7xx.c +15 -0
index 635178cf3eed..9986cb2479ad 100644
@@ -1491,6 +1491,21 @@ static struct i2c_driver sc16is7xx_i2c_uart_driver = {
 	.id_table	= sc16is7xx_i2c_id_table,
 };
 
+static int __init register_sc16is7xx_i2c(void)
+{
+	return i2c_add_driver(&sc16is7xx_i2c_uart_driver);
+}
+
+static void __exit del_sc16is7xx_i2c(void)
+{
+	i2c_del_driver(&sc16is7xx_i2c_uart_driver);
+}
+
+#else
+
+static int __init register_sc16is7xx_i2c(void) { return 0; }
+static void __exit del_sc16is7xx_i2c(void) {}
+
 #endif
 
Quoted 4 lines
Quoted 3 lines
drivers/tty/serial/sc16is7xx.c +0 -0
 static int __init sc16is7xx_init(void)

Then you can remove all the ifdefs.

ok, thank you, I will send v3. Do you mind Reviewed-by ?

I'll add after I review the patch. :)

regards,
dan carpenter