ttyprintk: Fix wrong tty_unregister_driver() call in the error path
PATCH 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.
--- drivers/char/ttyprintk.c | 2 -- 1 file changed, 2 deletions(-)
drivers/char/ttyprintk.c +0 -2
@@ -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
PATCH 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.
--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/char/Kconfig +1 -1
@@ -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
@@ -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 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
Re: [PATCH 2/2] ttyprintk: Allow built as a module
Hi Takashi,
Quoted 36 lines · Takashi Iwai
The driver is well written to be used as a module, just the exit call is missing.
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)drivers/char/Kconfig +1
-1@@ -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 +1
-1@@ -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;
drivers/char/ttyprintk.c error: · line 218
Quoted 5 lines
drivers/char/ttyprintk.c +2
-0@@ -214,4 +214,15 @@ error:tty_port_destroy (&tpk_port.port);return ret; } + +static void ttyprintk_exit (void )
Could be marked __exit.
drivers/char/ttyprintk.c error: · line 228
Quoted 10 lines
drivers/char/ttyprintk.c +9
-0+{ +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" );
Other than this, this looks good, thanks for doing that.
Signature · 2 lines
Jean Delvare SUSE L3 Support
Re: [PATCH 2/2] ttyprintk: Allow built as a module
At Wed, 02 Apr 2014 14:31:46 +0200,
Quoted 61 lines · Jean Delvare
Hi Takashi,
Quoted 36 lines · Takashi Iwai
The driver is well written to be used as a module, just the exit call is missing.
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)drivers/char/Kconfig +1
-1@@ -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 +1
-1@@ -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;drivers/char/ttyprintk.c error: · line 218
Quoted 5 lines
drivers/char/ttyprintk.c +2
-0@@ -214,4 +214,15 @@ error:tty_port_destroy (&tpk_port.port);return ret; } + +static void ttyprintk_exit (void )Could be marked
__exit.drivers/char/ttyprintk.c error: · line 228
Quoted 10 lines
drivers/char/ttyprintk.c +9
-0+{ +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" );Other than this, this looks good, thanks for doing that.
Quoted 1 line
Reviewed-by Jean Delvare <[email protected]>
Thanks! I'll resubmit the fixed patch.
Takashi
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] ttyprintk: Allow built as a module
In reply to Takashi IwaiQuoted 8 lines · Takashi Iwai
The driver is well written to be used as a module, just the exit call is missing.
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
There was some reason we didn't do this back when the code was accepted, but I really can't remember why.
If you have tested this out, I don't have any objections to taking these patches, thanks.
greg k-h
Re: [PATCH 2/2] ttyprintk: Allow built as a module
At Wed, 2 Apr 2014 12:32:22 -0700,
Quoted 11 lines · Greg Kroah-Hartman
Quoted 8 lines · Takashi Iwai
The driver is well written to be used as a module, just the exit call is missing.
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
Quoted 5 lines
There was some reason we didn't do this back when the code was accepted, but I really can't remember why.
If you have tested this out, I don't have any objections to taking these patches, thanks.
The module worked fine with my quick tests (load/unload/feed something via /dev/ttyprintk), at least. But it'd be helpful if anyone remembers and clarifies.
thanks,
Takashi
Re: [PATCH 2/2] ttyprintk: Allow built as a module
Dne 03.04.2014 (čet) ob 08:13 +0200 je Takashi Iwai napisal(a):
Quoted 16 lines
At Wed, 2 Apr 2014 12:32:22 -0700,
Quoted 14 lines · Greg Kroah-Hartman
Quoted 8 lines · Takashi Iwai
The driver is well written to be used as a module, just the exit call is missing.
Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/Kconfig | 2 +- drivers/char/ttyprintk.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)There was some reason we didn't do this back when the code was accepted, but I really can't remember why.
Quoted 7 lines
Quoted 2 lines
If you have tested this out, I don't have any objections to taking these patches, thanks.
The module worked fine with my quick tests (load/unload/feed something via
/dev/ttyprintk), at least. But it'd be helpful if anyone remembers and clarifies.
My initial requirement was to be able to use this functionality as soon as possible at the beginning of user-space initialisation, so i never thought of the ttyprintk code being loaded afterwards as module. Also nobody brought modularisation subject to the table during code acceptance.
Quoted 4 lines
thanks,
Takashi
regards, Samo
Quoted 15 lines · Takashi Iwai
ttyprintk driver calls
tty_unregister_driver()wrongly in the error path oftty_register_driver(). Also, settingttyprintk_driverto NULL is utterly superfluous, so let's get rid of it, too.Reported-by Jean Delvare <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/ttyprintk.c | 2 -- 1 file changed, 2 deletions(-)drivers/char/ttyprintk.c +0
-0
drivers/char/ttyprintk.c static int __init ttyprintk_init(void) · line 217
Quoted 10 lines
drivers/char/ttyprintk.c +0
-2@@ -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 · 2 lines
Jean Delvare SUSE L3 Support
At Wed, 02 Apr 2014 14:24:33 +0200,
Quoted 19 lines · Jean Delvare
Quoted 17 lines · Takashi Iwai
ttyprintk driver calls
tty_unregister_driver()wrongly in the error path oftty_register_driver(). Also, settingttyprintk_driverto NULL is utterly superfluous, so let's get rid of it, too.Reported-by Jean Delvare <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/ttyprintk.c | 2 -- 1 file changed, 2 deletions(-)drivers/char/ttyprintk.c +0
-0@@ -210,10 +210,8 @@ static int __init ttyprintk_init(void)return 0 ;
Quoted 10 lines
drivers/char/ttyprintk.c static int __init ttyprintk_init(void) · line 217
Quoted 8 lines
drivers/char/ttyprintk.c +0
-2error: -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);Reviewed-by Jean Delvare <[email protected]>
Meanwhile, I found that tty_unregister_driver() was added intentionally in the commit f06fb543c1d0,
TTY: ttyprintk, unregister tty driver on failure
When the tty_printk driver fails to create a node in sysfs, the system
crashes. It is because the driver registers a tty driver and frees it
without deregistering it first. The fix is easy: add a call to tty_unregister_driver to the fail path.
But, I failed to see why this is needed in the current code.
Jiri, is your fix still valid at all?
thanks,
Takashi
Quoted 43 lines · Takashi Iwai
At Wed, 02 Apr 2014 14:24:33 +0200,
Quoted 19 lines · Jean Delvare
Quoted 17 lines · Takashi Iwai
ttyprintk driver calls
tty_unregister_driver()wrongly in the error path oftty_register_driver(). Also, settingttyprintk_driverto NULL is utterly superfluous, so let's get rid of it, too.Reported-by Jean Delvare <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/char/ttyprintk.c | 2 -- 1 file changed, 2 deletions(-)drivers/char/ttyprintk.c +0
-0@@ -210,10 +210,8 @@ static int __init ttyprintk_init(void)return 0 ;Quoted 10 lines
drivers/char/ttyprintk.c static int __init ttyprintk_init(void) · line 217
Quoted 8 lines
drivers/char/ttyprintk.c +0
-2error: -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);Reviewed-by Jean Delvare <[email protected]>Meanwhile, I found that
tty_unregister_driver()was added intentionally in the commitf06fb543c1d0,
TTY: ttyprintk, unregister tty driver on failureWhen the
tty_printkdriver fails to create a node in sysfs, the system
crashes. It is because the driver registers a tty driver and frees it
without deregistering it first. The fix is easy: add a call totty_unregister_driverto the fail path.
Quoted 3 lines
But, I failed to see why this is needed in the current code.
Jiri, is your fix still valid at all?
The code was different. There was also device_create after tty_register_driver. I must admit that I don't know why I didn't change 'goto error' in the tty_register_driver fail path.
ret = tty_register_driver(ttyprintk_driver);
if (ret < 0) {
printk(KERN_ERR "Couldn't register ttyprintk driver\n");
goto error;
}
/* create our unnumbered device */
rp = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 3), NULL,
ttyprintk_driver->name);
if (IS_ERR(rp)) {
printk(KERN_ERR "Couldn't create ttyprintk device\n");
ret = PTR_ERR(rp);
goto error;
}So yes, there should be no tty_unregister_driver in the fail path when device_create is gone now.
thanks,
Signature · 2 lines
js suse labs