On Sat 2025-12-27 09:16:10, Marcos Paulo de Souza wrote:
> The flags argument was also used to check if CON_NBCON was set, but their
> usage was fixed in the last commit. All current users are reading the
> variable just to call console_is_usable.
>
> By calling console_srcu_read_flags inside console_is_usable makes the
> code cleaner and removes one argument from the function.
>
> Along with it, create a variant called __console_is_usable that can be
> used under console_list_lock(), like unregister_console_locked.
>
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -656,13 +656,8 @@ extern bool nbcon_kdb_try_acquire(struct console *con,
> struct nbcon_write_context *wctxt);
> extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
>
> -/*
> - * Check if the given console is currently capable and allowed to print
> - * records. Note that this function does not consider the current context,
> - * which can also play a role in deciding if @con can be used to print
> - * records.
> - */
> -static inline bool console_is_usable(struct console *con, short flags,
> +/* Variant of console_is_usable() when the console_list_lock is held. */
Nit: The comment is a bit misleading because this function is called
also from console_is_usable() under console_srcu_read_lock().
I would say something like:
/*
* The caller must ensure that @con can't disappear either by taking
* console_list_lock() or console_srcu_read_lock(). See also
* console_is_usable().
*/
> +static inline bool __console_is_usable(struct console *con, short flags,
> enum nbcon_write_cb nwc)
> {
> if (!(flags & CON_ENABLED))
> @@ -707,6 +702,18 @@ static inline bool console_is_usable(struct console
> *con, short flags,
> return true;
> }
>
> +/*
> + * Check if the given console is currently capable and allowed to print
> + * records. Note that this function does not consider the current context,
> + * which can also play a role in deciding if @con can be used to print
> + * records.
And I would add here something like:
*
* Context: Must be called under console_srcu_read_lock().
> + */
> +static inline bool console_is_usable(struct console *con,
> + enum nbcon_write_cb nwc)
> +{
> + return __console_is_usable(con, console_srcu_read_flags(con), nwc);
> +}
> +
> #else
> static inline void nbcon_cpu_emergency_enter(void) { }
> static inline void nbcon_cpu_emergency_exit(void) { }
Otherwise, it looks good. It is a nice clean up.
Best Regards,
Petr