linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 1/7] console: Don't perform test for CON_BRL flag
@ 2020-02-03 13:31 Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 2/7] console: Drop double check for console_drivers being non-NULL Andy Shevchenko
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
v5: no change
 drivers/accessibility/braille/braille_console.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
index 1339c586bf64..a8f7c278b691 100644
--- a/drivers/accessibility/braille/braille_console.c
+++ b/drivers/accessibility/braille/braille_console.c
@@ -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;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 2/7] console: Drop double check for console_drivers being non-NULL
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 3/7] console: Use for_each_console() helper in unregister_console() Andy Shevchenko
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko

There is no need to explicitly check for console_drivers to be non-NULL
since for_each_console() does this.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
v5: no change

 kernel/printk/printk.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 815739eb8406..21b1a5d5e5b0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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)) {
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 3/7] console: Use for_each_console() helper in unregister_console()
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 2/7] console: Drop double check for console_drivers being non-NULL Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 4/7] console: Drop misleading comment Andy Shevchenko
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko

We 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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
---
v5: no change

 kernel/printk/printk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 21b1a5d5e5b0..c63338df76cf 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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;
 			}
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 4/7] console: Drop misleading comment
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 2/7] console: Drop double check for console_drivers being non-NULL Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 3/7] console: Use for_each_console() helper in unregister_console() Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 5/7] console: Avoid positive return code from unregister_console() Andy Shevchenko
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: 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.

Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v5: no change

 kernel/printk/printk.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c63338df76cf..463ed5c5474e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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",
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 5/7] console: Avoid positive return code from unregister_console()
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
                   ` (2 preceding siblings ...)
  2020-02-03 13:31 ` [PATCH v5 4/7] console: Drop misleading comment Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 6/7] console: Don't notify user space when unregister non-listed console Andy Shevchenko
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko

There 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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v5: no change

 kernel/printk/printk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 463ed5c5474e..5fdae891a4cd 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 6/7] console: Don't notify user space when unregister non-listed console
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
                   ` (3 preceding siblings ...)
  2020-02-03 13:31 ` [PATCH v5 5/7] console: Avoid positive return code from unregister_console() Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-03 13:31 ` [PATCH v5 7/7] console: Introduce ->exit() callback Andy Shevchenko
  2020-02-04  1:34 ` [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Sergey Senozhatsky
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko, Sergey Senozhatsky

If 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.

Suggested-by: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v5: new patch

 kernel/printk/printk.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5fdae891a4cd..abd9b92ae0e3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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);
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 7/7] console: Introduce ->exit() callback
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
                   ` (4 preceding siblings ...)
  2020-02-03 13:31 ` [PATCH v5 6/7] console: Don't notify user space when unregister non-listed console Andy Shevchenko
@ 2020-02-03 13:31 ` Andy Shevchenko
  2020-02-04  1:34 ` [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Sergey Senozhatsky
  6 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:31 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: Andy Shevchenko

Some 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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v5: Return error code from ->exit() (Sergey)

 include/linux/console.h | 1 +
 kernel/printk/printk.c  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/include/linux/console.h b/include/linux/console.h
index f33016b3a401..7a140f4e5d0c 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -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;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index abd9b92ae0e3..43b5cb88c607 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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:
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/7] console: Don't perform test for CON_BRL flag
  2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
                   ` (5 preceding siblings ...)
  2020-02-03 13:31 ` [PATCH v5 7/7] console: Introduce ->exit() callback Andy Shevchenko
@ 2020-02-04  1:34 ` Sergey Senozhatsky
  2020-02-11 11:32   ` Petr Mladek
  6 siblings, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2020-02-04  1:34 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt

On (20/02/03 15:31), Andy Shevchenko wrote:
> 
> 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.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Petr Mladek <pmladek@suse.com>

Looks good to me overall

Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

	-ss

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/7] console: Don't perform test for CON_BRL flag
  2020-02-04  1:34 ` [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Sergey Senozhatsky
@ 2020-02-11 11:32   ` Petr Mladek
  2020-02-11 12:54     ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Mladek @ 2020-02-11 11:32 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Andy Shevchenko, Sergey Senozhatsky, linux-kernel, Steven Rostedt

On Tue 2020-02-04 10:34:26, Sergey Senozhatsky wrote:
> On (20/02/03 15:31), Andy Shevchenko wrote:
> > 
> > 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.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Reviewed-by: Petr Mladek <pmladek@suse.com>
> 
> Looks good to me overall
> 
> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

The entire patchset has been commited into printk.git,
branch for-5.7-console-exit

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/7] console: Don't perform test for CON_BRL flag
  2020-02-11 11:32   ` Petr Mladek
@ 2020-02-11 12:54     ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-11 12:54 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Sergey Senozhatsky, linux-kernel, Steven Rostedt

On Tue, Feb 11, 2020 at 12:32:13PM +0100, Petr Mladek wrote:
> On Tue 2020-02-04 10:34:26, Sergey Senozhatsky wrote:
> > On (20/02/03 15:31), Andy Shevchenko wrote:
> > > 
> > > 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.
> > > 
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > Reviewed-by: Petr Mladek <pmladek@suse.com>
> > 
> > Looks good to me overall
> > 
> > Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> 
> The entire patchset has been commited into printk.git,
> branch for-5.7-console-exit

Thank you, Petr!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-02-11 12:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03 13:31 [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 2/7] console: Drop double check for console_drivers being non-NULL Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 3/7] console: Use for_each_console() helper in unregister_console() Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 4/7] console: Drop misleading comment Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 5/7] console: Avoid positive return code from unregister_console() Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 6/7] console: Don't notify user space when unregister non-listed console Andy Shevchenko
2020-02-03 13:31 ` [PATCH v5 7/7] console: Introduce ->exit() callback Andy Shevchenko
2020-02-04  1:34 ` [PATCH v5 1/7] console: Don't perform test for CON_BRL flag Sergey Senozhatsky
2020-02-11 11:32   ` Petr Mladek
2020-02-11 12:54     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).