Message ID | 20221107141638.3790965-25-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2079566wru; Mon, 7 Nov 2022 06:22:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM7dDV4jHhNe3sT07gncM1i7/oOXf+VRjr4+gZgcNbsDu0l2a41cczjEramV1y2lYBK8CSRv X-Received: by 2002:a17:907:62a7:b0:789:48ea:ddb0 with SMTP id nd39-20020a17090762a700b0078948eaddb0mr46327692ejc.575.1667830951853; Mon, 07 Nov 2022 06:22:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830951; cv=none; d=google.com; s=arc-20160816; b=EY6yVKeWzFxJepBB1SKegK5QrPn2m07rWqHV5co8LCSGqxczOTLTChVxrQO2nZNpoW 4mwe0UBypFwwZ5jdzc6fGhWYi7Mdepf8M4d+1saYU2OMoKNNsCXwKdqKGQJG+wr0vV3s shd+QEjrkJ2iEdSicoutSzwm8a+000Hh8HAyNSvJ2iPWpZy7PmR8oK/yOIaZ/ND1Pqhd RVUsFzNpRT6vFRVirnS04Xg9WrPIugbgjoLnFiX8n+iTcGYGw3PbWTDqUxN9xxFywx+7 aovRzXQl3n0msQd+pb+9qxhbOvS3L3Nkd0WIIo/zeA2C2w6zyPgk2/YDgE0CPLmCsjOk DBlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=Cza9sFRKk8n5akjgJ2mmJdkQ9ugpKUuXfPju9qgUElhc6VgNX2o7MUD9NNfWqny6LO 5Ou18uauMtRV+/V+/VCMG9Xgyp7DOGblUCZkMG9aVitHoN8cWCwp6Vk7ZXvqwqxkmduu hyaoMpjpSYxBOzDIqIeveufdLdorVkpOdgZIFPXP1JqS5gzLMFeXrYiUCVFiAclR5QoH FSM/oMNB5nqA6hK0fbAKVhahRLrSTfsGUpOKV8iBIhskHymy2PmC1lLmK5mdS7iLfJvJ alttulEaHoh4swDcfqjMA+hng9a7mTc5GKnxtuZQcGZqWfa8deMUAUxAQOvLGa42t+3C nmcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vQeoLKWE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb6-20020a0564020d0600b0046453c39abdsi11312007edb.104.2022.11.07.06.22.06; Mon, 07 Nov 2022 06:22:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vQeoLKWE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiKGOSr (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 09:18:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232202AbiKGOQx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 09:16:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 943D71D0E0 for <linux-kernel@vger.kernel.org>; Mon, 7 Nov 2022 06:16:52 -0800 (PST) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=vQeoLKWE1k4R6O3nMnBfOLEHIpwhVsbvXcVbHBj6NMymPvMJgyWKk8a+SWMhfut8ws1okf Rqf9Cz5bLPDfyH+IyWepofmoKnEQOGvQ1iHo3uNlukZnoFRP/pK5Sn5O02G21xpmFqMb+u hlTpVg1FSFH8SZ5WJyjH7IZ6QWr3b0vra6/IicriLiXUPXoi2kY+4Ry5gxKoUarCzr9z0L Jn/x7yIxlwj3fKZG/3gv9EsOyIpQRYwIlQqQP0/vFXqq5R1VhYgWlvhKaj+E2sPNiXxMoP PRI0wvXScmB0NbnXYTOF9ujFHajDe8JAN/lBQ8WvjFv+BmWum45rO42CvDc0XA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hTh+Y7bD13JCVuc3SV32h+lY6g8QzK5tRTIXwcqSGfI=; b=T64AeLS2skGi+8SZjeqwwtVGih9S8IofM6v6ACJ2ABibEKOmMbg6PouGq2vD32FeJ/mS4n /VBpHt26tQKzOUBw== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, Geert Uytterhoeven <geert@linux-m68k.org>, linux-m68k@lists.linux-m68k.org Subject: [PATCH printk v3 24/40] tty: nfcon: use console_is_registered() Date: Mon, 7 Nov 2022 15:22:22 +0106 Message-Id: <20221107141638.3790965-25-john.ogness@linutronix.de> In-Reply-To: <20221107141638.3790965-1-john.ogness@linutronix.de> References: <20221107141638.3790965-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748847508141054346?= X-GMAIL-MSGID: =?utf-8?q?1748847508141054346?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 7, 2022, 2:16 p.m. UTC
Currently CON_ENABLED is being (mis)used to identify if the console
has been registered. This is not reliable because it can be set even
though registration failed or it can be unset, even though the console
is registered.
Instead, use console_is_registered().
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
arch/m68k/emu/nfcon.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
Comments
Hi John, On Mon, Nov 7, 2022 at 3:16 PM John Ogness <john.ogness@linutronix.de> wrote: > Currently CON_ENABLED is being (mis)used to identify if the console > has been registered. This is not reliable because it can be set even > though registration failed or it can be unset, even though the console > is registered. > > Instead, use console_is_registered(). > > Signed-off-by: John Ogness <john.ogness@linutronix.de> Thanks for your patch! LGTM, so Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On Mon 2022-11-07 15:22:22, John Ogness wrote: > Currently CON_ENABLED is being (mis)used to identify if the console > has been registered. This is not reliable because it can be set even > though registration failed or it can be unset, even though the console > is registered. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > arch/m68k/emu/nfcon.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c > index 557d60867f98..292669fa480f 100644 > --- a/arch/m68k/emu/nfcon.c > +++ b/arch/m68k/emu/nfcon.c > @@ -49,14 +49,14 @@ static void nfcon_write(struct console *con, const char *str, > static struct tty_driver *nfcon_device(struct console *con, int *index) > { > *index = 0; > - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; > + return console_is_registered(con) ? nfcon_tty_driver : NULL; > } > > static struct console nf_console = { > .name = "nfcon", > .write = nfcon_write, > .device = nfcon_device, > - .flags = CON_PRINTBUFFER, > + .flags = CON_PRINTBUFFER | CON_ENABLED, This causes that register_console() will always put the console into console_list. It causes regression, see below. > .index = -1, > }; > > @@ -106,10 +106,8 @@ static int __init nf_debug_setup(char *arg) > return 0; > > stderr_id = nf_get_id("NF_STDERR"); > - if (stderr_id) { > - nf_console.flags |= CON_ENABLED; > + if (stderr_id) > register_console(&nf_console); My understanding is that this should enable the console when debug=nfcon kernel parameter is used. It is a non-standard way. This is why CON_ENABLED flag has to be explicitly set. > - } > > return 0; > } > @@ -151,7 +149,7 @@ static int __init nfcon_init(void) > > nfcon_tty_driver = driver; > > - if (!(nf_console.flags & CON_ENABLED)) > + if (!console_is_registered(&nf_console)) > register_console(&nf_console); This calls register_console() when it was not already registered by the debug=nfcon early parameter. It is the standard way. It should enable the console only when console=nfcon is defined on the commandline. Or when there is no preferred console and no console enabled by default yet. We should not pre-set CON_ENABLED in this case. Best Regards, Petr
On 2022-11-10, Petr Mladek <pmladek@suse.com> wrote: >> diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c >> index 557d60867f98..292669fa480f 100644 >> --- a/arch/m68k/emu/nfcon.c >> +++ b/arch/m68k/emu/nfcon.c >> @@ -49,14 +49,14 @@ static void nfcon_write(struct console *con, const char *str, >> static struct tty_driver *nfcon_device(struct console *con, int *index) >> { >> *index = 0; >> - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; >> + return console_is_registered(con) ? nfcon_tty_driver : NULL; >> } >> >> static struct console nf_console = { >> .name = "nfcon", >> .write = nfcon_write, >> .device = nfcon_device, >> - .flags = CON_PRINTBUFFER, >> + .flags = CON_PRINTBUFFER | CON_ENABLED, > > This causes that register_console() will always put the console into > console_list. It causes regression, see below. Agreed. Nice catch. I will remove initializing with CON_ENABLED. >> .index = -1, >> }; >> >> @@ -106,10 +106,8 @@ static int __init nf_debug_setup(char *arg) >> return 0; >> >> stderr_id = nf_get_id("NF_STDERR"); >> - if (stderr_id) { >> - nf_console.flags |= CON_ENABLED; >> + if (stderr_id) >> register_console(&nf_console); > > My understanding is that this should enable the console > when debug=nfcon kernel parameter is used. > > It is a non-standard way. This is why CON_ENABLED flag > has to be explicitly set. Understood. I will add a comment explaining why CON_ENABLED is set here. >> - } >> >> return 0; >> } >> @@ -151,7 +149,7 @@ static int __init nfcon_init(void) >> >> nfcon_tty_driver = driver; >> >> - if (!(nf_console.flags & CON_ENABLED)) >> + if (!console_is_registered(&nf_console)) >> register_console(&nf_console); > > This calls register_console() when it was not already > registered by the debug=nfcon early parameter. > > It is the standard way. It should enable the console only > when console=nfcon is defined on the commandline. Or when > there is no preferred console and no console enabled by default yet. > > We should not pre-set CON_ENABLED in this case. Agreed. The hunk itself is OK. John
Hi, On 10.11.2022 16.19, John Ogness wrote: > On 2022-11-10, Petr Mladek <pmladek@suse.com> wrote: ... >>> @@ -106,10 +106,8 @@ static int __init nf_debug_setup(char *arg) >>> return 0; >>> >>> stderr_id = nf_get_id("NF_STDERR"); >>> - if (stderr_id) { >>> - nf_console.flags |= CON_ENABLED; >>> + if (stderr_id) >>> register_console(&nf_console); >> >> My understanding is that this should enable the console >> when debug=nfcon kernel parameter is used. >> >> It is a non-standard way. This is why CON_ENABLED flag >> has to be explicitly set. > > Understood. I will add a comment explaining why CON_ENABLED is set here. NatFeats is emulator feature. If you want to test the resulting kernel, you can use either Aranym or Hatari emulator. Aranym NF docs are here: https://github.com/aranym/aranym/wiki/natfeats-proposal Hatari m68k linux docs are here: https://hatari.tuxfamily.org/doc/m68k-linux.txt - Eero
diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c index 557d60867f98..292669fa480f 100644 --- a/arch/m68k/emu/nfcon.c +++ b/arch/m68k/emu/nfcon.c @@ -49,14 +49,14 @@ static void nfcon_write(struct console *con, const char *str, static struct tty_driver *nfcon_device(struct console *con, int *index) { *index = 0; - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; + return console_is_registered(con) ? nfcon_tty_driver : NULL; } static struct console nf_console = { .name = "nfcon", .write = nfcon_write, .device = nfcon_device, - .flags = CON_PRINTBUFFER, + .flags = CON_PRINTBUFFER | CON_ENABLED, .index = -1, }; @@ -106,10 +106,8 @@ static int __init nf_debug_setup(char *arg) return 0; stderr_id = nf_get_id("NF_STDERR"); - if (stderr_id) { - nf_console.flags |= CON_ENABLED; + if (stderr_id) register_console(&nf_console); - } return 0; } @@ -151,7 +149,7 @@ static int __init nfcon_init(void) nfcon_tty_driver = driver; - if (!(nf_console.flags & CON_ENABLED)) + if (!console_is_registered(&nf_console)) register_console(&nf_console); return 0;