[PATCH 19/19] printk: Remove CON_ENABLED flag

Marcos Paulo de Souza
2025-12-27T22:40:42Z

All remaining usages of CON_ENABLED were removed from console drivers
that were being registered without being specified on boot using console=
argument.

The usefulness of the flag was questionable since at first it meant that
the console was ready to print records. Later on, console drivers started
to set the flag when registering the console to make sure that the
console would be registered even without being specified by a kernel
argument.

With the inclusion a global state for system wide suspend/resume
in place, with console_{suspend,resume} handling CON_SUSPEND, and with
console_is_usable helper being more used, the CON_ENABLED flag can be
safely removed.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/proc/consoles.c | 1 -
include/linux/console.h | 27 ++++++++++-----------------
kernel/printk/printk.c | 15 ++-------------
3 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c
index b7cab1ad990d..b6916ed7957b 100644
--- a/fs/proc/consoles.c
+++ b/fs/proc/consoles.c
@@ -18,7 +18,6 @@ static int show_console_dev(struct seq_file *m, void *v)
short flag;
char name;
} con_flags[] = {
- { CON_ENABLED, 'E' },
{ CON_CONSDEV, 'C' },
{ CON_BOOT, 'B' },
{ CON_NBCON, 'N' },
diff --git a/include/linux/console.h b/include/linux/console.h
index 7d374a29a625..0ab02f7ba307 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -164,9 +164,6 @@ static inline void con_debug_leave(void) { }
* consoles or read by userspace via syslog() syscall.
* @CON_CONSDEV: Indicates that the console driver is backing
* /dev/console.
- * @CON_ENABLED: Indicates if a console is allowed to print records. If
- * false, the console also will not advance to later
- * records.
* @CON_BOOT: Marks the console driver as early console driver which
* is used during boot before the real driver becomes
* available. It will be automatically unregistered
@@ -192,14 +189,13 @@ static inline void con_debug_leave(void) { }
enum cons_flags {
CON_PRINTBUFFER = BIT(0),
CON_CONSDEV = BIT(1),
- CON_ENABLED = BIT(2),
- CON_BOOT = BIT(3),
- CON_ANYTIME = BIT(4),
- CON_BRL = BIT(5),
- CON_EXTENDED = BIT(6),
- CON_SUSPENDED = BIT(7),
- CON_NBCON = BIT(8),
- CON_NBCON_ATOMIC_UNSAFE = BIT(9),
+ CON_BOOT = BIT(2),
+ CON_ANYTIME = BIT(3),
+ CON_BRL = BIT(4),
+ CON_EXTENDED = BIT(5),
+ CON_SUSPENDED = BIT(6),
+ CON_NBCON = BIT(7),
+ CON_NBCON_ATOMIC_UNSAFE = BIT(8),
};

/**
@@ -522,9 +518,9 @@ extern bool consoles_suspended;
*
* Requires console_srcu_read_lock to be held, which implies that @con might
* be a registered console. The purpose of holding console_srcu_read_lock is
- * to guarantee that the console state is valid (CON_SUSPENDED/CON_ENABLED)
- * and that no exit/cleanup routines will run if the console is currently
- * undergoing unregistration.
+ * to guarantee that the console state is valid (CON_SUSPENDED) and that no
+ * exit/cleanup routines will run if the console is currently undergoing
+ * unregistration.
*
* If the caller is holding the console_list_lock or it is _certain_ that
* @con is not and will not become registered, the caller may read
@@ -706,9 +702,6 @@ static inline bool __console_is_usable(struct console *con, short flags,
if (all_suspended)
return false;

- if (!(flags & CON_ENABLED))
- return false;
-
if ((flags & CON_SUSPENDED))
return false;

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c5c05e4d0a67..9cb0911997e5 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3890,21 +3890,17 @@ static int try_enable_preferred_console(struct console *newcon,
if (err)
return err;
}
- newcon->flags |= CON_ENABLED;
if (i == preferred_console)
newcon->flags |= CON_CONSDEV;
return 0;
}

- if (force)
- newcon->flags |= CON_ENABLED;
-
/*
* 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.
*/
- if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
+ if (force && c->user_specified == user_specified)
return 0;

return -ENOENT;
@@ -3919,8 +3915,6 @@ static void try_enable_default_console(struct console *newcon)
if (console_call_setup(newcon, NULL) != 0)
return;

- newcon->flags |= CON_ENABLED;
-
if (newcon->device)
newcon->flags |= CON_CONSDEV;
}
@@ -3977,10 +3971,8 @@ static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered)
for_each_console(con) {
u64 seq;

- if (!(con->flags & CON_BOOT) ||
- !(con->flags & CON_ENABLED)) {
+ if (!(con->flags & CON_BOOT))
continue;
- }

if (con->flags & CON_NBCON)
seq = nbcon_seq_read(con);
@@ -4233,9 +4225,6 @@ static int unregister_console_locked(struct console *console)
consoles_suspended, NBCON_USE_ATOMIC))
__pr_flush(console, 1000, true);

- /* Disable it unconditionally */
- console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
-
if (res < 0)
return res;

--
2.52.0