[PATCH v3 4/5] console: Avoid positive return code from unregister_console()

From: Andy Shevchenko
Date: Mon Jan 27 2020 - 06:47:34 EST


There are two callers which use the returned code from unregister_console().
In some cases, i.e. successfully unregistered Braille console or when console
has not been enabled the return code is 1. This code is ambiguous and also
prevents callers to distinguish successful operation.

Replace this logic to return only negative error codes or 0 when console,
either enabled, disabled or Braille has been successfully unregistered.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
v3: no changes
kernel/printk/printk.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d40a316908da..da6a9bdf76b6 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2817,10 +2817,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;
@@ -2838,6 +2840,9 @@ int unregister_console(struct console *console)
if (!res && (console->flags & CON_EXTENDED))
nr_ext_console_drivers--;

+ if (res && !(console->flags & CON_ENABLED))
+ res = 0;
+
/*
* If this isn't the last console and it has CON_CONSDEV set, we
* need to set it on the next preferred console.
--
2.24.1