Skip to contentSkip to conversation

console: unify return codes from ->setup() hook

PATCH In review Andy Shevchenko 8 participants 21 messages Jun 18, 2020 – Jun 25, 2020

Subsystems (5)
lore
Share & tools
lore
#1 lore raw

PATCH 1/6 mips: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc Thomas Bogendoerfer <[email protected]>
---
 arch/mips/fw/arc/arc_con.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/mips/fw/arc/arc_con.c +3 -1
index 365e3913231e..7fdce236b298 100644
@@ -28,7 +28,9 @@ static void prom_console_write(struct console *co, const char *s,
 
 static int prom_console_setup(struct console *co, char *options)
 {
-	return !(prom_flags & PROM_FLAG_USE_AS_CONSOLE);
+	if (prom_flags & PROM_FLAG_USE_AS_CONSOLE)
+		return 0;
+	return -ENODEV;
 }
 
 static struct console arc_cons = {
Signature · 1 line
2.27.0
#7 lore raw

PATCH 3/6 serial: sunzilog: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc "David S. Miller" <[email protected]>
---
 drivers/tty/serial/sunzilog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/sunzilog.c +1 -1
index 103ab8c556e7..7ea06bbc6197 100644
@@ -1221,7 +1221,7 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
 	int baud, brg;
 
 	if (up->port.type != PORT_SUNZILOG)
-		return -1;
+		return -EINVAL;
 
 	printk(KERN_INFO "Console: ttyS%d (SunZilog zs%d)\n",
 	       (sunzilog_reg.minor - 64) + con->index, con->index);
Signature · 1 line
2.27.0
#5 lore raw

PATCH 2/6 serial: sunsab: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc "David S. Miller" <[email protected]>
---
 drivers/tty/serial/sunsab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/sunsab.c +1 -1
index 1eb703c980e0..bab551f46963 100644
@@ -886,7 +886,7 @@ static int sunsab_console_setup(struct console *con, char *options)
 	 * though...
 	 */
 	if (up->port.type != PORT_SUNSAB)
-		return -1;
+		return -EINVAL;
 
 	printk("Console: ttyS%d (SAB82532)\n",
 	       (sunsab_reg.minor - 64) + con->index);
Signature · 1 line
2.27.0
#9 lore raw

PATCH 4/6 tty: hvc: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

---
 drivers/tty/hvc/hvsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/hvc/hvsi.c +1 -1
index 66f95f758be0..e8c58f9bd263 100644
@@ -1128,7 +1128,7 @@ static int __init hvsi_console_setup(struct console *console, char *options)
 	int ret;
 
 	if (console->index < 0 || console->index >= hvsi_count)
-		return -1;
+		return -EINVAL;
 	hp = &hvsi_ports[console->index];
 
 	/* give the FSP a chance to change the baud rate when we re-open */
Signature · 1 line
2.27.0
#12 lore raw

PATCH 6/6 console: Fix trivia typo 'change' -> 'chance'

In reply to Andy Shevchenko

I bet the word 'chance' has to be used in 'had a chance to be called', but, alas, I'm not native speaker...

Cc Benjamin Herrenschmidt <[email protected]>
---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
index aaea3ad182e1..6623e975675a 100644
@@ -2705,7 +2705,7 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
 	/*
 	 * Some consoles, such as pstore and netconsole, can be enabled even
 	 * without matching. Accept the pre-enabled consoles only when match()
-	 * and setup() had a change to be called.
+	 * and setup() had a chance to be called.
 	 */
 	if (newcon->flags & CON_ENABLED && c->user_specified ==	user_specified)
 		return 0;
Signature · 1 line
2.27.0
#0 lore raw

cover console: unify return codes from ->setup() hook

Some of the console providers treat error code, returned by ->setup() hook, differently. Here is the unification of the behaviour.

The drivers checked by one of the below criteria:
1/ the driver has explicit struct console .setup assignment 2/ the driver has assigned callback to the setup member

All such drivers were read in order to see if there is any problematic return codes, and fixed accordingly which is this series in the result.

Andy Shevchenko (6):
mips: Return proper error code from console ->setup() hook
serial: sunsab: Return proper error code from console ->setup() hook
serial: sunzilog: Return proper error code from console ->setup() hook
tty: hvc: Return proper error code from console ->setup() hook
console: Propagate error code from console ->setup()
console: Fix trivia typo 'change' -> 'chance'

 arch/mips/fw/arc/arc_con.c    | 4 +++-
 drivers/tty/hvc/hvsi.c        | 2 +-
 drivers/tty/serial/sunsab.c   | 2 +-
 drivers/tty/serial/sunzilog.c | 2 +-
 kernel/printk/printk.c        | 8 ++++----
 5 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.27.0
#10 lore raw

PATCH 5/6 console: Propagate error code from console ->setup()

Since console ->setup() hook returns meaningful error codes, propagate it to the caller of try_enable_new_console().

Cc Benjamin Herrenschmidt <[email protected]>
---
 kernel/printk/printk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/printk/printk.c +3 -3
index 8c14835be46c..aaea3ad182e1 100644
@@ -2668,7 +2668,7 @@ early_param("keep_bootcon", keep_bootcon_setup);
 static int try_enable_new_console(struct console *newcon, bool user_specified)
 {
 	struct console_cmdline *c;
-	int i;
+	int i, err;
 
 	for (i = 0, c = console_cmdline;
 	     i < MAX_CMDLINECONSOLES && c->name[0];
@@ -2691,8 +2691,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
 				return 0;
 
 			if (newcon->setup &&
-			    newcon->setup(newcon, c->options) != 0)
-				return -EIO;
+			    (err = newcon->setup(newcon, c->options)) != 0)
+				return err;
 		}
 		newcon->flags |= CON_ENABLED;
 		if (i == preferred_console) {
Signature · 1 line
2.27.0
#14 lore raw
In reply to Andy Shevchenko
Quoted 18 lines · Andy Shevchenko

Some of the console providers treat error code, returned by ->setup() hook, differently. Here is the unification of the behaviour.

The drivers checked by one of the below criteria:
1/ the driver has explicit struct console .setup assignment 2/ the driver has assigned callback to the setup member

All such drivers were read in order to see if there is any problematic return codes, and fixed accordingly which is this series in the result.

Andy Shevchenko (6):
mips: Return proper error code from console ->setup() hook
serial: sunsab: Return proper error code from console ->setup() hook
serial: sunzilog: Return proper error code from console ->setup() hook
tty: hvc: Return proper error code from console ->setup() hook
console: Propagate error code from console ->setup()
console: Fix trivia typo 'change' -> 'chance'

Quoted 6 lines
 arch/mips/fw/arc/arc_con.c    | 4 +++-
 drivers/tty/hvc/hvsi.c        | 2 +-
 drivers/tty/serial/sunsab.c   | 2 +-
 drivers/tty/serial/sunzilog.c | 2 +-
 kernel/printk/printk.c        | 8 ++++----
 5 files changed, 10 insertions(+), 8 deletions(-)

Looks good to me. I'd also, probably, unify the naming. I can grep 71 foo_console_setup() and only 1 foo_setup_console().

---
 drivers/tty/hvc/hvc_xen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/hvc/hvc_xen.c +2 -2
index 5ef08905fe05..2a0e51a20e34 100644
@@ -603,7 +603,7 @@ static void xen_hvm_early_write(uint32_t vtermno, const char *str, int len) { }
 #endif
 
 #ifdef CONFIG_EARLY_PRINTK
-static int __init xenboot_setup_console(struct console *console, char *string)
+static int __init xenboot_console_setup(struct console *console, char *string)
 {
 	static struct xencons_info xenboot;
 
@@ -647,7 +647,7 @@ static void xenboot_write_console(struct console *console, const char *string,
 struct console xenboot_console = {
 	.name		= "xenboot",
 	.write		= xenboot_write_console,
-	.setup		= xenboot_setup_console,
+	.setup		= xenboot_console_setup,
 	.flags		= CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
 	.index		= -1,
 };
Signature · 1 line
2.27.0
maintainer Acked-by on v1 3/6
#8 lore raw

Re: [PATCH v1 3/6] serial: sunzilog: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>
Date: Thu, 18 Jun 2020 19:47:48 +0300

Quoted 5 lines

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc "David S. Miller" <[email protected]>
maintainer Acked-by on v1 2/6
#6 lore raw

Re: [PATCH v1 2/6] serial: sunsab: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>
Date: Thu, 18 Jun 2020 19:47:47 +0300

Quoted 5 lines

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc "David S. Miller" <[email protected]>
Acked-by on v1 5/6
#11 lore raw

Re: [PATCH v1 5/6] console: Propagate error code from console ->setup()

In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

Since console ->setup() hook returns meaningful error codes, propagate it to the caller of try_enable_new_console().

Quoted 28 lines

---A

 kernel/printk/printk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/printk/printk.c +3 -3
index 8c14835be46c..aaea3ad182e1 100644
@@ -2668,7 +2668,7 @@ early_param("keep_bootcon", keep_bootcon_setup);
 static int try_enable_new_console(struct console *newcon, bool user_specified)
 {
 	struct console_cmdline *c;
-	int i;
+	int i, err;
 
 	for (i = 0, c = console_cmdline;
 	     i < MAX_CMDLINECONSOLES && c->name[0];
@@ -2691,8 +2691,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
 				return 0;
 
 			if (newcon->setup &&
-			    newcon->setup(newcon, c->options) != 0)
-				return -EIO;
+			    (err = newcon->setup(newcon, c->options)) != 0)
+				return err;
 		}
 		newcon->flags |= CON_ENABLED;
 		if (i == preferred_console) {
Acked-by on v1 6/6
#13 lore raw

Re: [PATCH v1 6/6] console: Fix trivia typo 'change' -> 'chance'

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

I bet the word 'chance' has to be used in 'had a chance to be called', but, alas, I'm not native speaker...

Yup, typo :)

Quoted 2 lines
Quoted 17 lines
---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
index aaea3ad182e1..6623e975675a 100644
@@ -2705,7 +2705,7 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
 	/*
 	 * Some consoles, such as pstore and netconsole, can be enabled even
 	 * without matching. Accept the pre-enabled consoles only when match()
-	 * and setup() had a change to be called.
+	 * and setup() had a chance to be called.
 	 */
 	if (newcon->flags & CON_ENABLED && c->user_specified ==	user_specified)
 		return 0;
maintainer Reviewed-by on the v1 series
#15 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

Some of the console providers treat error code, returned by ->setup() hook, differently. Here is the unification of the behaviour.

The drivers checked by one of the below criteria:
1/ the driver has explicit struct console .setup assignment 2/ the driver has assigned callback to the setup member

All such drivers were read in order to see if there is any problematic return codes, and fixed accordingly which is this series in the result.

Quoted 7 lines

Andy Shevchenko (6):
mips: Return proper error code from console ->setup() hook
serial: sunsab: Return proper error code from console ->setup() hook
serial: sunzilog: Return proper error code from console ->setup() hook
tty: hvc: Return proper error code from console ->setup() hook
console: Propagate error code from console ->setup()
console: Fix trivia typo 'change' -> 'chance'

For the entire patchset:

I am going to push it the following week via printk tree unless anybody complains.

Best Regards,
Petr

maintainer Acked-by on v1 1/6
#2 lore raw

Re: [PATCH v1 1/6] mips: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

For unifying console ->setup() handling, which is pure documented, return error code, rather than non-zero arbitrary number.

Cc Thomas Bogendoerfer <[email protected]>
---
 arch/mips/fw/arc/arc_con.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#16 lore raw
In reply to Petr Mladek
Quoted 19 lines · Petr Mladek
Quoted 10 lines · Andy Shevchenko

Some of the console providers treat error code, returned by ->setup() hook, differently. Here is the unification of the behaviour.

The drivers checked by one of the below criteria:
1/ the driver has explicit struct console .setup assignment 2/ the driver has assigned callback to the setup member

All such drivers were read in order to see if there is any problematic return codes, and fixed accordingly which is this series in the result.

Quoted 7 lines

Andy Shevchenko (6):
mips: Return proper error code from console ->setup() hook
serial: sunsab: Return proper error code from console ->setup() hook
serial: sunzilog: Return proper error code from console ->setup() hook
tty: hvc: Return proper error code from console ->setup() hook
console: Propagate error code from console ->setup()
console: Fix trivia typo 'change' -> 'chance'

Quoted 6 lines

For the entire patchset:

I am going to push it the following week via printk tree unless anybody complains.

Thanks, Petr, I guess you may also incorporate Sergey's patch he proposed. Sergey, are you going to submit it officially?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Petr Mladek

On Thu 2020-06-18 19:47:45, Andy Shevchenko wrote:

[..]

Quoted 5 lines
Quoted 2 lines

I am going to push it the following week via printk tree unless anybody complains.

Thanks, Petr, I guess you may also incorporate Sergey's patch he proposed. Sergey, are you going to submit it officially?

I can send a patch, unless Petr has objections.

	-ss
maintainer
#18 lore raw
Quoted 11 lines · Sergey Senozhatsky
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Petr Mladek

On Thu 2020-06-18 19:47:45, Andy Shevchenko wrote:

[..]

Quoted 5 lines
Quoted 2 lines

I am going to push it the following week via printk tree unless anybody complains.

Thanks, Petr, I guess you may also incorporate Sergey's patch he proposed. Sergey, are you going to submit it officially?

I can send a patch, unless Petr has objections.

Go ahead :-)

Best Regards,
Petr

#19 lore raw
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Sergey Senozhatsky
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Petr Mladek

On Thu 2020-06-18 19:47:45, Andy Shevchenko wrote:

[..]

Quoted 3 lines
Quoted 2 lines

I am going to push it the following week via printk tree unless anybody complains.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Thanks, Petr, I guess you may also incorporate Sergey's patch he proposed. Sergey, are you going to submit it officially?

I can send a patch, unless Petr has objections.

Go ahead :-)

Oops, I just sent it, but I forgot to specify in-reply-to message-id :(

	-ss
#3 lore raw

Re: [PATCH v1 1/6] mips: Return proper error code from console ->setup() hook

In reply to Andy Shevchenko
Quoted 1 line · Andy Shevchenko

For unifying console ->setup() handling, which is pure documented,

Did you mean s/pure/poorly/ in all the patches? Or purely? But then where?

Quoted 4 lines

return error code, rather than non-zero arbitrary number.

Cc Thomas Bogendoerfer <[email protected]>

thanks,

Signature · 2 lines
js
suse labs
#4 lore raw

Re: [PATCH v1 1/6] mips: Return proper error code from console ->setup() hook

Quoted 5 lines · Jiri Slaby
Quoted 1 line · Andy Shevchenko

For unifying console ->setup() handling, which is pure documented,

Did you mean s/pure/poorly/ in all the patches? Or purely? But then where?

Poorly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#20 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

Some of the console providers treat error code, returned by ->setup() hook, differently. Here is the unification of the behaviour.

The drivers checked by one of the below criteria:
1/ the driver has explicit struct console .setup assignment 2/ the driver has assigned callback to the setup member

All such drivers were read in order to see if there is any problematic return codes, and fixed accordingly which is this series in the result.

Quoted 7 lines

Andy Shevchenko (6):
mips: Return proper error code from console ->setup() hook
serial: sunsab: Return proper error code from console ->setup() hook
serial: sunzilog: Return proper error code from console ->setup() hook
tty: hvc: Return proper error code from console ->setup() hook
console: Propagate error code from console ->setup()
console: Fix trivia typo 'change' -> 'chance'

The entire patchset has been pushed into printk/linux.git, branch for-5.9-console-return-codes.

I have done "s/pure/poorly/" to fix the typo in commit messages reported by Jiri Slaby.

Best Regards,
Petr