Revert "printk: Save console options for add_preferred_console_match()"

This reverts commit f03e8c1060f86c23eb49bafee99d9fcbd1c1bd77.

Let's roll back all of the serial core and printk console changes that
went into 6.10-rc1 as there still are problems with them that need to be
sorted out.

Link: https://lore.kernel.org/r/ZnpRozsdw6zbjqze@tlindgre-MOBL1
Reported-by: Petr Mladek <pmladek@suse.com>
Reported-by: Tony Lindgren <tony@atomide.com>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+4 -167
-3
include/linux/printk.h
··· 60 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT 61 #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET 62 63 - int add_preferred_console_match(const char *match, const char *name, 64 - const short idx); 65 - 66 extern int console_printk[]; 67 68 #define console_loglevel (console_printk[0])
··· 60 #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT 61 #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET 62 63 extern int console_printk[]; 64 65 #define console_loglevel (console_printk[0])
+1 -1
kernel/printk/Makefile
··· 1 # SPDX-License-Identifier: GPL-2.0-only 2 - obj-y = printk.o conopt.o 3 obj-$(CONFIG_PRINTK) += printk_safe.o nbcon.o 4 obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o 5 obj-$(CONFIG_PRINTK_INDEX) += index.o
··· 1 # SPDX-License-Identifier: GPL-2.0-only 2 + obj-y = printk.o 3 obj-$(CONFIG_PRINTK) += printk_safe.o nbcon.o 4 obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o 5 obj-$(CONFIG_PRINTK_INDEX) += index.o
-146
kernel/printk/conopt.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Kernel command line console options for hardware based addressing 4 - * 5 - * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ 6 - * Author: Tony Lindgren <tony@atomide.com> 7 - */ 8 - 9 - #include <linux/console.h> 10 - #include <linux/init.h> 11 - #include <linux/string.h> 12 - #include <linux/types.h> 13 - 14 - #include <asm/errno.h> 15 - 16 - #include "console_cmdline.h" 17 - 18 - /* 19 - * Allow longer DEVNAME:0.0 style console naming such as abcd0000.serial:0.0 20 - * in addition to the legacy ttyS0 style naming. 21 - */ 22 - #define CONSOLE_NAME_MAX 32 23 - 24 - #define CONSOLE_OPT_MAX 16 25 - #define CONSOLE_BRL_OPT_MAX 16 26 - 27 - struct console_option { 28 - char name[CONSOLE_NAME_MAX]; 29 - char opt[CONSOLE_OPT_MAX]; 30 - char brl_opt[CONSOLE_BRL_OPT_MAX]; 31 - u8 has_brl_opt:1; 32 - }; 33 - 34 - /* Updated only at console_setup() time, no locking needed */ 35 - static struct console_option conopt[MAX_CMDLINECONSOLES]; 36 - 37 - /** 38 - * console_opt_save - Saves kernel command line console option for driver use 39 - * @str: Kernel command line console name and option 40 - * @brl_opt: Braille console options 41 - * 42 - * Saves a kernel command line console option for driver subsystems to use for 43 - * adding a preferred console during init. Called from console_setup() only. 44 - * 45 - * Return: 0 on success, negative error code on failure. 46 - */ 47 - int __init console_opt_save(const char *str, const char *brl_opt) 48 - { 49 - struct console_option *con; 50 - size_t namelen, optlen; 51 - const char *opt; 52 - int i; 53 - 54 - namelen = strcspn(str, ","); 55 - if (namelen == 0 || namelen >= CONSOLE_NAME_MAX) 56 - return -EINVAL; 57 - 58 - opt = str + namelen; 59 - if (*opt == ',') 60 - opt++; 61 - 62 - optlen = strlen(opt); 63 - if (optlen >= CONSOLE_OPT_MAX) 64 - return -EINVAL; 65 - 66 - for (i = 0; i < MAX_CMDLINECONSOLES; i++) { 67 - con = &conopt[i]; 68 - 69 - if (con->name[0]) { 70 - if (!strncmp(str, con->name, namelen)) 71 - return 0; 72 - continue; 73 - } 74 - 75 - /* 76 - * The name isn't terminated, only opt is. Empty opt is fine, 77 - * but brl_opt can be either empty or NULL. For more info, see 78 - * _braille_console_setup(). 79 - */ 80 - strscpy(con->name, str, namelen + 1); 81 - strscpy(con->opt, opt, CONSOLE_OPT_MAX); 82 - if (brl_opt) { 83 - strscpy(con->brl_opt, brl_opt, CONSOLE_BRL_OPT_MAX); 84 - con->has_brl_opt = 1; 85 - } 86 - 87 - return 0; 88 - } 89 - 90 - return -ENOMEM; 91 - } 92 - 93 - static struct console_option *console_opt_find(const char *name) 94 - { 95 - struct console_option *con; 96 - int i; 97 - 98 - for (i = 0; i < MAX_CMDLINECONSOLES; i++) { 99 - con = &conopt[i]; 100 - if (!strcmp(name, con->name)) 101 - return con; 102 - } 103 - 104 - return NULL; 105 - } 106 - 107 - /** 108 - * add_preferred_console_match - Adds a preferred console if a match is found 109 - * @match: Expected console on kernel command line, such as console=DEVNAME:0.0 110 - * @name: Name of the console character device to add such as ttyS 111 - * @idx: Index for the console 112 - * 113 - * Allows driver subsystems to add a console after translating the command 114 - * line name to the character device name used for the console. Options are 115 - * added automatically based on the kernel command line. Duplicate preferred 116 - * consoles are ignored by __add_preferred_console(). 117 - * 118 - * Return: 0 on success, negative error code on failure. 119 - */ 120 - int add_preferred_console_match(const char *match, const char *name, 121 - const short idx) 122 - { 123 - struct console_option *con; 124 - char *brl_opt = NULL; 125 - 126 - if (!match || !strlen(match) || !name || !strlen(name) || 127 - idx < 0) 128 - return -EINVAL; 129 - 130 - con = console_opt_find(match); 131 - if (!con) 132 - return -ENOENT; 133 - 134 - /* 135 - * See __add_preferred_console(). It checks for NULL brl_options to set 136 - * the preferred_console flag. Empty brl_opt instead of NULL leads into 137 - * the preferred_console flag not set, and CON_CONSDEV not being set, 138 - * and the boot console won't get disabled at the end of console_setup(). 139 - */ 140 - if (con->has_brl_opt) 141 - brl_opt = con->brl_opt; 142 - 143 - console_opt_add_preferred_console(name, idx, con->opt, brl_opt); 144 - 145 - return 0; 146 - }
···
-6
kernel/printk/console_cmdline.h
··· 2 #ifndef _CONSOLE_CMDLINE_H 3 #define _CONSOLE_CMDLINE_H 4 5 - #define MAX_CMDLINECONSOLES 8 6 - 7 - int console_opt_save(const char *str, const char *brl_opt); 8 - int console_opt_add_preferred_console(const char *name, const short idx, 9 - char *options, char *brl_options); 10 - 11 struct console_cmdline 12 { 13 char name[16]; /* Name of the driver */
··· 2 #ifndef _CONSOLE_CMDLINE_H 3 #define _CONSOLE_CMDLINE_H 4 5 struct console_cmdline 6 { 7 char name[16]; /* Name of the driver */
+3 -11
kernel/printk/printk.c
··· 383 /* 384 * Array of consoles built from command line options (console=) 385 */ 386 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; 387 388 static int preferred_console = -1; ··· 2503 if (_braille_console_setup(&str, &brl_options)) 2504 return 1; 2505 2506 - /* Save the console for driver subsystem use */ 2507 - if (console_opt_save(str, brl_options)) 2508 - return 1; 2509 - 2510 /* 2511 * Decode str into name, index, options. 2512 */ ··· 2532 return 1; 2533 } 2534 __setup("console=", console_setup); 2535 - 2536 - /* Only called from add_preferred_console_match() */ 2537 - int console_opt_add_preferred_console(const char *name, const short idx, 2538 - char *options, char *brl_options) 2539 - { 2540 - return __add_preferred_console(name, idx, options, brl_options, true); 2541 - } 2542 2543 /** 2544 * add_preferred_console - add a device to the list of preferred consoles.
··· 383 /* 384 * Array of consoles built from command line options (console=) 385 */ 386 + 387 + #define MAX_CMDLINECONSOLES 8 388 + 389 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; 390 391 static int preferred_console = -1; ··· 2500 if (_braille_console_setup(&str, &brl_options)) 2501 return 1; 2502 2503 /* 2504 * Decode str into name, index, options. 2505 */ ··· 2533 return 1; 2534 } 2535 __setup("console=", console_setup); 2536 2537 /** 2538 * add_preferred_console - add a device to the list of preferred consoles.