Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kgdboc: Disable all the early code when kgdboc is a module

When kgdboc is compiled as a module all of the "ekgdboc" and
"kgdb_earlycon" code isn't useful and, in fact, breaks compilation.
This is because early_param() isn't defined for modules and that's how
this code gets configured.

It turns out that this was broken by commit eae3e19ca930 ("kgdboc:
Remove useless #ifdef CONFIG_KGDB_SERIAL_CONSOLE in kgdboc") and then
made worse by commit 220995622da5 ("kgdboc: Add kgdboc_earlycon to
support early kgdb using boot consoles"). I guess the #ifdef wasn't
so useless, even if it wasn't obvious why it was useful. When kgdboc
was compiled as a module only "CONFIG_KGDB_SERIAL_CONSOLE_MODULE" was
defined, not "CONFIG_KGDB_SERIAL_CONSOLE". That meant that the old
module.

Let's basically do the same thing that the old code (pre-removal of
the #ifdef) did but use "IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE)" to
make it more obvious what the point of the check is. We'll fix
kgdboc_earlycon in a similar way.

Fixes: 220995622da5 ("kgdboc: Add kgdboc_earlycon to support early kgdb using boot consoles")
Fixes: eae3e19ca930 ("kgdboc: Remove useless #ifdef CONFIG_KGDB_SERIAL_CONSOLE in kgdboc")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20200519084345.1.I91670accc8a5ddabab227eb63bb4ad3e2e9d2b58@changeid
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>

authored by

Douglas Anderson and committed by
Daniel Thompson
1feb48ba 22099562

+14 -1
+14 -1
drivers/tty/serial/kgdboc.c
··· 43 43 44 44 static struct platform_device *kgdboc_pdev; 45 45 46 + #if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) 46 47 static struct kgdb_io kgdboc_earlycon_io_ops; 47 48 static struct console *earlycon; 48 49 static int (*earlycon_orig_exit)(struct console *con); 50 + #endif /* IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */ 49 51 50 52 #ifdef CONFIG_KDB_KEYBOARD 51 53 static int kgdboc_reset_connect(struct input_handler *handler, ··· 142 140 #define kgdboc_restore_input() 143 141 #endif /* ! CONFIG_KDB_KEYBOARD */ 144 142 145 - static void cleanup_kgdboc(void) 143 + #if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) 144 + static void cleanup_earlycon(void) 146 145 { 147 146 if (earlycon) 148 147 kgdb_unregister_io_module(&kgdboc_earlycon_io_ops); 148 + } 149 + #else /* !IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */ 150 + static inline void cleanup_earlycon(void) { } 151 + #endif /* !IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */ 152 + 153 + static void cleanup_kgdboc(void) 154 + { 155 + cleanup_earlycon(); 149 156 150 157 if (configured != 1) 151 158 return; ··· 399 388 .post_exception = kgdboc_post_exp_handler, 400 389 }; 401 390 391 + #if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) 402 392 static int kgdboc_option_setup(char *opt) 403 393 { 404 394 if (!opt) { ··· 556 544 } 557 545 558 546 early_param("kgdboc_earlycon", kgdboc_earlycon_init); 547 + #endif /* IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE) */ 559 548 560 549 module_init(init_kgdboc); 561 550 module_exit(exit_kgdboc);