Skip to contentSkip to conversation

ttyprintk: Fix wrong tty_unregister_driver() call in the error path

PATCH New Takashi Iwai 1 participant 2 messages Apr 2, 2014 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ttyprintk: Fix wrong tty_unregister_driver() call in the error path

ttyprintk driver calls tty_unregister_driver() wrongly in the error path of tty_register_driver(). Also, setting ttyprintk_driver to NULL is utterly superfluous, so let's get rid of it, too.

---
v1->v2: add review tag

 drivers/char/ttyprintk.c | 2 --
 1 file changed, 2 deletions(-)
drivers/char/ttyprintk.c +0 -2
index daea84c41743..2a39c5790364 100644
@@ -210,10 +210,8 @@ static int __init ttyprintk_init(void)
 	return 0;
 
 error:
-	tty_unregister_driver(ttyprintk_driver);
 	put_tty_driver(ttyprintk_driver);
 	tty_port_destroy(&tpk_port.port);
-	ttyprintk_driver = NULL;
 	return ret;
 }
 device_initcall(ttyprintk_init);
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 2/2 ttyprintk: Allow built as a module

The driver is well written to be used as a module, just the exit call is missing.

---
v1->v2: add missing __exit, add review tag

 drivers/char/Kconfig     |  2 +-
 drivers/char/ttyprintk.c | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/char/Kconfig +1 -1
index 1386749b48ff..97816b133c7f 100644
@@ -40,7 +40,7 @@ config SGI_MBCS
 source "drivers/tty/serial/Kconfig"
 
 config TTY_PRINTK
-	bool "TTY driver to output user messages via printk"
+	tristate "TTY driver to output user messages via printk"
 	depends on EXPERT && TTY
 	default n
 	---help---
drivers/char/ttyprintk.c +12 -1
index 2a39c5790364..73606eaaba71 100644
@@ -17,7 +17,7 @@
 #include <linux/device.h>
 #include <linux/serial.h>
 #include <linux/tty.h>
-#include <linux/export.h>
+#include <linux/module.h>
 
 struct ttyprintk_port {
 	struct tty_port port;
@@ -214,4 +214,15 @@ error:
 	tty_port_destroy(&tpk_port.port);
 	return ret;
 }
+
+static void __exit ttyprintk_exit(void)
+{
+	tty_unregister_driver(ttyprintk_driver);
+	put_tty_driver(ttyprintk_driver);
+	tty_port_destroy(&tpk_port.port);
+}
+
 device_initcall(ttyprintk_init);
+module_exit(ttyprintk_exit);
+
+MODULE_LICENSE("GPL");
Signature · 1 line
1.9.1