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

Configure Feed

Select the types of activity you want to include in your feed.

printk: nbcon: Export console_is_usable

The helper will be used on KDB code in the next commits.

Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Link: https://patch.msgid.link/20251016-nbcon-kgdboc-v6-1-866aac60a80e@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>

authored by

Marcos Paulo de Souza and committed by
Petr Mladek
4da42aaa 48e3694a

+45 -45
+45
include/linux/console.h
··· 19 19 #include <linux/irq_work.h> 20 20 #include <linux/rculist.h> 21 21 #include <linux/rcuwait.h> 22 + #include <linux/smp.h> 22 23 #include <linux/types.h> 23 24 #include <linux/vesa.h> 24 25 ··· 606 605 extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); 607 606 extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); 608 607 extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); 608 + 609 + /* 610 + * Check if the given console is currently capable and allowed to print 611 + * records. Note that this function does not consider the current context, 612 + * which can also play a role in deciding if @con can be used to print 613 + * records. 614 + */ 615 + static inline bool console_is_usable(struct console *con, short flags, bool use_atomic) 616 + { 617 + if (!(flags & CON_ENABLED)) 618 + return false; 619 + 620 + if ((flags & CON_SUSPENDED)) 621 + return false; 622 + 623 + if (flags & CON_NBCON) { 624 + /* The write_atomic() callback is optional. */ 625 + if (use_atomic && !con->write_atomic) 626 + return false; 627 + 628 + /* 629 + * For the !use_atomic case, @printk_kthreads_running is not 630 + * checked because the write_thread() callback is also used 631 + * via the legacy loop when the printer threads are not 632 + * available. 633 + */ 634 + } else { 635 + if (!con->write) 636 + return false; 637 + } 638 + 639 + /* 640 + * Console drivers may assume that per-cpu resources have been 641 + * allocated. So unless they're explicitly marked as being able to 642 + * cope (CON_ANYTIME) don't call them until this CPU is officially up. 643 + */ 644 + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) 645 + return false; 646 + 647 + return true; 648 + } 649 + 609 650 #else 610 651 static inline void nbcon_cpu_emergency_enter(void) { } 611 652 static inline void nbcon_cpu_emergency_exit(void) { } ··· 655 612 static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) { return false; } 656 613 static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { return false; } 657 614 static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { } 615 + static inline bool console_is_usable(struct console *con, short flags, 616 + bool use_atomic) { return false; } 658 617 #endif 659 618 660 619 extern int console_set_on_cmdline;
-45
kernel/printk/internal.h
··· 3 3 * internal.h - printk internal definitions 4 4 */ 5 5 #include <linux/console.h> 6 - #include <linux/percpu.h> 7 6 #include <linux/types.h> 8 7 9 8 #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) ··· 111 112 void nbcon_kthread_stop(struct console *con); 112 113 void nbcon_kthreads_wake(void); 113 114 114 - /* 115 - * Check if the given console is currently capable and allowed to print 116 - * records. Note that this function does not consider the current context, 117 - * which can also play a role in deciding if @con can be used to print 118 - * records. 119 - */ 120 - static inline bool console_is_usable(struct console *con, short flags, bool use_atomic) 121 - { 122 - if (!(flags & CON_ENABLED)) 123 - return false; 124 - 125 - if ((flags & CON_SUSPENDED)) 126 - return false; 127 - 128 - if (flags & CON_NBCON) { 129 - /* The write_atomic() callback is optional. */ 130 - if (use_atomic && !con->write_atomic) 131 - return false; 132 - 133 - /* 134 - * For the !use_atomic case, @printk_kthreads_running is not 135 - * checked because the write_thread() callback is also used 136 - * via the legacy loop when the printer threads are not 137 - * available. 138 - */ 139 - } else { 140 - if (!con->write) 141 - return false; 142 - } 143 - 144 - /* 145 - * Console drivers may assume that per-cpu resources have been 146 - * allocated. So unless they're explicitly marked as being able to 147 - * cope (CON_ANYTIME) don't call them until this CPU is officially up. 148 - */ 149 - if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) 150 - return false; 151 - 152 - return true; 153 - } 154 - 155 115 /** 156 116 * nbcon_kthread_wake - Wake up a console printing thread 157 117 * @con: Console to operate on ··· 161 203 int cookie, bool use_atomic) { return false; } 162 204 static inline void nbcon_kthread_wake(struct console *con) { } 163 205 static inline void nbcon_kthreads_wake(void) { } 164 - 165 - static inline bool console_is_usable(struct console *con, short flags, 166 - bool use_atomic) { return false; } 167 206 168 207 #endif /* CONFIG_PRINTK */ 169 208