printk: move @seq initialization to helper
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 16 Nov 2022 16:21:17 +0000 (17:27 +0106)
committerPetr Mladek <pmladek@suse.com>
Fri, 2 Dec 2022 10:24:59 +0000 (11:24 +0100)
The code to initialize @seq for a new console needs to consider
more factors when choosing an initial value. Move the code into
a helper function console_init_seq() "as is" so this code can
be expanded without causing register_console() to become too
long. A later commit will implement the additional code.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20221116162152.193147-6-john.ogness@linutronix.de
kernel/printk/printk.c

index 3d449dfb1ed664b3a937e05f827f6e32426b086d..31d9d1cf86820569c3744f9c6b992869afbe16fb 100644 (file)
@@ -3131,6 +3131,19 @@ static void try_enable_default_console(struct console *newcon)
               (con->flags & CON_BOOT) ? "boot" : "",   \
               con->name, con->index, ##__VA_ARGS__)
 
+static void console_init_seq(struct console *newcon)
+{
+       if (newcon->flags & CON_PRINTBUFFER) {
+               /* Get a consistent copy of @syslog_seq. */
+               mutex_lock(&syslog_lock);
+               newcon->seq = syslog_seq;
+               mutex_unlock(&syslog_lock);
+       } else {
+               /* Begin with next message. */
+               newcon->seq = prb_next_seq(prb);
+       }
+}
+
 #define console_first()                                \
        hlist_entry(console_list.first, struct console, node)
 
@@ -3222,15 +3235,7 @@ void register_console(struct console *newcon)
        }
 
        newcon->dropped = 0;
-       if (newcon->flags & CON_PRINTBUFFER) {
-               /* Get a consistent copy of @syslog_seq. */
-               mutex_lock(&syslog_lock);
-               newcon->seq = syslog_seq;
-               mutex_unlock(&syslog_lock);
-       } else {
-               /* Begin with next message. */
-               newcon->seq = prb_next_seq(prb);
-       }
+       console_init_seq(newcon);
 
        /*
         * Put this console in the list - keep the