[printk,v2,09/38] netconsole: use console_is_enabled()

Message ID 20221019145600.1282823-10-john.ogness@linutronix.de
State New
Headers
Series reduce console_lock scope |

Commit Message

John Ogness Oct. 19, 2022, 2:55 p.m. UTC
  Replace (console->flags & CON_ENABLED) usage with console_is_enabled().

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/net/netconsole.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Petr Mladek Oct. 21, 2022, 1:14 p.m. UTC | #1
On Wed 2022-10-19 17:01:31, John Ogness wrote:
> Replace (console->flags & CON_ENABLED) usage with console_is_enabled().
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>

The change is straightforward:

Reviewed-by: Petr Mladek <pmladek@suse.com>

The comment below is just a lamentation about the netconsole code.

> ---
>  drivers/net/netconsole.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index bdff9ac5056d..073e59a06f21 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -332,7 +332,7 @@ static ssize_t enabled_store(struct config_item *item,
>  	}
>  
>  	if (enabled) {	/* true */
> -		if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) {
> +		if (nt->extended && !console_is_enabled(&netconsole_ext)) {
>  			netconsole_ext.flags |= CON_ENABLED;
>  			register_console(&netconsole_ext);
>  		}
> @@ -915,7 +915,7 @@ static int __init init_netconsole(void)
>  	if (err)
>  		goto undonotifier;
>  
> -	if (netconsole_ext.flags & CON_ENABLED)
> +	if (console_is_enabled(&netconsole_ext))
>  		register_console(&netconsole_ext);
>  	register_console(&netconsole);
>  	pr_info("network logging started\n");

Just for record:

This looks like a (mis)use of CON_ENABLED flag. It took me some time
to understand why pre-enabled consoles are handled special way in
register_console(). I partly documented it in
try_enable_preferred_console():

	/*
	 * 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 (console_is_enabled(newcon) && (c->user_specified == user_specified))
		return 0;

In my bottom driver, I have a patch cleaning this. It is part of a bigger
clean up that is not ready for upstream :-/

Best Regards,
Petr
  
John Ogness Nov. 4, 2022, 3:12 p.m. UTC | #2
On 2022-10-21, Petr Mladek <pmladek@suse.com> wrote:
>> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
>> index bdff9ac5056d..073e59a06f21 100644
>> --- a/drivers/net/netconsole.c
>> +++ b/drivers/net/netconsole.c
>> @@ -332,7 +332,7 @@ static ssize_t enabled_store(struct config_item *item,
>>  	}
>>  
>>  	if (enabled) {	/* true */
>> -		if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) {
>> +		if (nt->extended && !console_is_enabled(&netconsole_ext)) {
>>  			netconsole_ext.flags |= CON_ENABLED;
>>  			register_console(&netconsole_ext);
>>  		}
>> @@ -915,7 +915,7 @@ static int __init init_netconsole(void)
>>  	if (err)
>>  		goto undonotifier;
>>  
>> -	if (netconsole_ext.flags & CON_ENABLED)
>> +	if (console_is_enabled(&netconsole_ext))
>>  		register_console(&netconsole_ext);
>>  	register_console(&netconsole);
>>  	pr_info("network logging started\n");
>
> This looks like a (mis)use of CON_ENABLED flag.

Yes. When @netconsole_ext is registered, CON_ENABLED is always set. So
it should be set in the static initialization. The first hunk should be
using the new console_is_registered(). The second hunk should be using a
local @extended bool variable. Also, in cleanup_netconsole() it should
check if the console is registered:

if (console_is_registered(&netconsole_ext))
        unregister_console(&netconsole_ext);

I will make all of these changes for v3. Then there will be no
checking/setting of CON_ENABLED in the driver.

John Ogness
  

Patch

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index bdff9ac5056d..073e59a06f21 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -332,7 +332,7 @@  static ssize_t enabled_store(struct config_item *item,
 	}
 
 	if (enabled) {	/* true */
-		if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) {
+		if (nt->extended && !console_is_enabled(&netconsole_ext)) {
 			netconsole_ext.flags |= CON_ENABLED;
 			register_console(&netconsole_ext);
 		}
@@ -915,7 +915,7 @@  static int __init init_netconsole(void)
 	if (err)
 		goto undonotifier;
 
-	if (netconsole_ext.flags & CON_ENABLED)
+	if (console_is_enabled(&netconsole_ext))
 		register_console(&netconsole_ext);
 	register_console(&netconsole);
 	pr_info("network logging started\n");