console: Don't perform test for CON_BRL flag
PATCH v5 3/7 console: Use for_each_console() helper in unregister_console()
In reply to Andy ShevchenkoWe have rather open coded single linked list manipulations where we may simple use for_each_console() helper with properly set exit conditions.
Replace open coded single-linked list handling with for_each_console() helper in use.
---
v5: no change
kernel/printk/printk.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/printk/printk.c +5 -6
@@ -2816,7 +2816,7 @@ EXPORT_SYMBOL(register_console);int unregister_console (struct console *console) { -struct console *a, *b; +struct console *con;int res; pr_info("%sconsole [%s%d] disabled\n",
@@ -2832,11 +2832,10 @@ int unregister_console(struct console *console)if (console_drivers == console) { console_drivers=console->next; res =0 ; - }else if (console_drivers) { -for (a=console_drivers->next, b=console_drivers ; - a; b=a, a=b->next) { -if (a == console) { - b->next = a->next; + }else { +for_each_console (con) { +if (con->next == console) { + con->next = console->next; res =0 ;break ; }
Signature · 1 line
2.24.1
PATCH v5 5/7 console: Avoid positive return code from unregister_console()
In reply to Andy ShevchenkoThere are only two callers that use the returned code from unregister_console():
- unregister_early_console() in arch/m68k/kernel/early_printk.c
- kgdb_unregister_nmi_console() in drivers/tty/serial/kgdb_nmi.c
They both expect to get "0" on success and a non-zero value on error. But the current behavior is confusing and buggy:
- _braille_unregister_console() returns "1" on success
- unregister_console() returns "1" on error
Fix and clean up the behavior:
- Return success when _braille_unregister_console() succeeded
- Return a meaningful error code when the console was not registered before
---
v5: no change
kernel/printk/printk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/printk/printk.c +4 -2
@@ -2823,10 +2823,12 @@ int unregister_console(struct console *console) console->name, console->index); res =_braille_unregister_console (console); -if (res) +if (res <0 )return res; +if (res >0 ) +return 0 ; - res =1 ; + res = -ENODEV ;console_lock ();if (console_drivers == console) { console_drivers=console->next;
Signature · 1 line
2.24.1
PATCH v5 4/7 console: Drop misleading comment
In reply to Andy Shevchenko/* find the last or real console */
This comment is misleading. The purpose of the loop is to check if we are trying to register boot console when one had been registered before.
---
v5: no change
kernel/printk/printk.c | 1 - 1 file changed, 1 deletion(-)
kernel/printk/printk.c +0 -1
@@ -2668,7 +2668,6 @@ void register_console(struct console *newcon)* already have a valid console */ if (newcon->flags &CON_BOOT ) { -/* find the last or real console */ for_each_console (bcon) {if (!(bcon->flags &CON_BOOT )) { pr_info("Too late to register bootconsole %s%d\n",
Signature · 1 line
2.24.1
PATCH v5 7/7 console: Introduce ->exit() callback
In reply to Andy ShevchenkoSome consoles might require special operations on unregistering. For instance, serial console, when registered in the kernel, keeps power on for entire time, until it gets unregistered. Example of use:
->setup(console): pm_runtime_get(...); ->exit(console): pm_runtime_put(...);
For such cases to have a balance we would provide ->exit() callback.
---
v5: Return error code from ->exit() (Sergey)
include/linux/console.h | 1 + kernel/printk/printk.c | 3 +++ 2 files changed, 4 insertions(+)
include/linux/console.h +1 -0
@@ -148,6 +148,7 @@ struct console {struct tty_driver *(*device)(struct console *,int *);void (*unblank)(void );int (*setup)(struct console *,char *); +int (*exit)(struct console *);int (*match)(struct console *,char *name,int idx,char *options);short flags;short index;
kernel/printk/printk.c +3 -0
@@ -2860,6 +2860,9 @@ int unregister_console(struct console *console)console_unlock ();console_sysfs_notify (); +if (console->exit) + res = console->exit (console); +return res; out_disable_unlock:
Signature · 1 line
2.24.1
PATCH v5 6/7 console: Don't notify user space when unregister non-listed console
In reply to Andy ShevchenkoIf console is not on the list then there is nothing for us to do and sysfs notify is pointless.
Note, that nr_ext_console_drivers is being changed only for listed consoles.
---
v5: new patch
kernel/printk/printk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
kernel/printk/printk.c +11 -1
@@ -2843,7 +2843,10 @@ int unregister_console(struct console *console) } } -if (!res && (console->flags &CON_EXTENDED )) +if (res) + goto out_disable_unlock; + +if (console->flags &CON_EXTENDED ) nr_ext_console_drivers--;/*
@@ -2856,6 +2859,13 @@ int unregister_console(struct console *console) console->flags &= ~CON_ENABLED ;console_unlock ();console_sysfs_notify (); + +return res; + +out_disable_unlock: + console->flags &= ~CON_ENABLED ; +console_unlock (); +return res; }EXPORT_SYMBOL (unregister_console);
Signature · 1 line
2.24.1
PATCH v5 2/7 console: Drop double check for console_drivers being non-NULL
In reply to Andy ShevchenkoThere is no need to explicitly check for console_drivers to be non-NULL since for_each_console() does this.
---
v5: no change
kernel/printk/printk.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
kernel/printk/printk.c +6 -10
@@ -1779,9 +1779,6 @@ static void call_console_drivers(const char *ext_text, size_t ext_len,trace_console_rcuidle (text, len); -if (!console_drivers) -return ; -for_each_console (con) {if (exclusive_console && con != exclusive_console)continue ;
@@ -2660,18 +2657,17 @@ void register_console(struct console *newcon)struct console_cmdline *c;static bool has_preferred; -if (console_drivers) -for_each_console (bcon) -if (WARN (bcon == newcon, -"console '%s%d' already registered\n" , - bcon->name, bcon->index)) -return ; +for_each_console (bcon) { +if (WARN (bcon == newcon,"console '%s%d' already registered\n" , + bcon->name, bcon->index)) +return ; + }/* * before we register a new CON_BOOT console, make sure we don't * already have a valid console */ -if (console_drivers && newcon->flags &CON_BOOT ) { +if (newcon->flags &CON_BOOT ) {/* find the last or real console */ for_each_console (bcon) {if (!(bcon->flags &CON_BOOT )) {
Signature · 1 line
2.24.1
PATCH v5 1/7 console: Don't perform test for CON_BRL flag
We don't call braille_register_console() without CON_BRL flag set. And the _braille_unregister_console() already tests for console to have CON_BRL flag. No need to repeat this in braille_unregister_console().
Drop the repetitive checks from Braille console driver.
---
v5: no change
drivers/accessibility/braille/braille_console.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/accessibility/braille/braille_console.c +0 -4
@@ -347,8 +347,6 @@ int braille_register_console(struct console *console, int index, {int ret; -if (!(console->flags &CON_BRL )) -return 0 ;if (!console_options)/* Only support VisioBraille for now */ console_options ="57600o8" ;
@@ -371,8 +369,6 @@ int braille_unregister_console(struct console *console) {if (braille_co != console)return -EINVAL ; -if (!(console->flags &CON_BRL )) -return 0 ;unregister_keyboard_notifier (&keyboard_notifier_block);unregister_vt_notifier (&vt_notifier_block); braille_co =NULL ;
Signature · 1 line
2.24.1
Quoted 9 lines · Andy Shevchenko
We don't call
braille_register_console()withoutCON_BRLflag set. And the_braille_unregister_console()already tests for console to haveCON_BRLflag. No need to repeat this inbraille_unregister_console().Drop the repetitive checks from Braille console driver.
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Petr Mladek <[email protected]>
Looks good to me overall
-ss
Petr Mladek
maintainerQuoted 6 lines · Sergey Senozhatsky
Quoted 5 lines · Andy Shevchenko
We don't call
braille_register_console()withoutCON_BRLflag set. And the_braille_unregister_console()already tests for console to haveCON_BRLflag. No need to repeat this inbraille_unregister_console().
Quoted 8 lines
Quoted 4 lines
Drop the repetitive checks from Braille console driver.
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Petr Mladek <[email protected]>Looks good to me overall
Reviewed-by Sergey Senozhatsky <[email protected]>
The entire patchset has been commited into printk.git, branch for-5.7-console-exit
Best Regards,
Petr
Quoted 12 lines · Petr Mladek
Quoted 11 lines · Sergey Senozhatsky
Quoted 9 lines · Andy Shevchenko
We don't call
braille_register_console()withoutCON_BRLflag set. And the_braille_unregister_console()already tests for console to haveCON_BRLflag. No need to repeat this inbraille_unregister_console().Drop the repetitive checks from Braille console driver.
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Petr Mladek <[email protected]>
Quoted 6 lines
Quoted 3 lines
Looks good to me overall
Reviewed-by Sergey Senozhatsky <[email protected]>The entire patchset has been commited into printk.git, branch for-5.7-console-exit
Thank you, Petr!
Signature · 2 lines
With Best Regards, Andy Shevchenko