lkml.org 
[lkml]   [2022]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH printk v3 08/40] printk: use console_is_enabled()
Date
Replace (console->flags & CON_ENABLED) usage with console_is_enabled()
if it involves a data race. Otherwise add comments mentioning why the
wrapper is not used.

Note that this is a preparatory change for when console_lock no longer
provides synchronization for console->flags.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 79811984da34..f243bb56a3ba 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2660,7 +2660,7 @@ static bool abandon_console_lock_in_panic(void)
*/
static inline bool console_is_usable(struct console *con)
{
- if (!(con->flags & CON_ENABLED))
+ if (!console_is_enabled(con))
return false;

if (!con->write)
@@ -2946,7 +2946,7 @@ void console_unblank(void)
console_locked = 1;
console_may_schedule = 0;
for_each_console(c)
- if ((c->flags & CON_ENABLED) && c->unblank)
+ if (console_is_enabled(c) && c->unblank)
c->unblank();
console_unlock();

@@ -3104,8 +3104,11 @@ static int try_enable_preferred_console(struct console *newcon,
* 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 chance to be called.
+ *
+ * Note that reading @flags is race-free because the console is not
+ * yet added to the console list.
*/
- if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
+ if ((newcon->flags & CON_ENABLED) && (c->user_specified == user_specified))
return 0;

return -ENOENT;
--
2.30.2
\
 
 \ /
  Last update: 2022-11-07 15:17    [W:1.011 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site