From patchwork Mon Nov 14 16:29:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239271wru; Mon, 14 Nov 2022 08:33:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7honBWdx31GmX1Y6oQwMJg88ESwyBeSnnSsWr+If4QMf2WvFTCSI7Lns/0w3FB4VIL2Cak X-Received: by 2002:a05:6402:1c85:b0:458:c339:4229 with SMTP id cy5-20020a0564021c8500b00458c3394229mr11642248edb.393.1668443603479; Mon, 14 Nov 2022 08:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443603; cv=none; d=google.com; s=arc-20160816; b=Ol5c53zbV344NeWkmHCRSx4ZpGIw1iwc8+Dh5nbawlYaG03zzQW6L6Tjq6V3XxFuoY KIAWKQkO0WaW9uyQY8uPTk7/eTOlYl4ntpCAWj/Bf0XX3SxnTFJWhpDCX5jerRmILYFH dc3fC3ExAfnknMt4VU5Au3wM4BjM3NntY+iyGhw2G1ubAwJX6uZkQD/Eiv4LTaorwaMW +z6yiD6LysnUuvDFvODGZQSV9OwPeoxXNOaFWu36+j4IRPM5d4PAzutnWDHZoAPrPaWO vhuSg6fWYXvnk+Adxh4obf0HijUO23q13x6pZFShtfpFMz7LOhb9n1VLBAKxT5/pRfZt NGbQ== 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=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=aZ5a5EQBj9nFALvEC01Cy7wZMEQ+YkOwGhv6npvhXY3r9BJEFmPTfw8SRyTODu3Mp9 pQu2IWVcdntjOrcL+zWZT+jmGTC/1AHwfoamZ7DqWMFhnXKgv65p/o63dR2/COC4SL4K EhPFMp8C5p7Ss3RGAaJzQlsAdcpKLHz54hcERNz7dWfrTRMkHmaA138cy6ap7NjmsNHc m+qhLwt6TcDey0QTOH3crAN5PA5VOWWYxwiud/Y/sHeGf2acCWrq5adzQCYGE61/grEW TcutjMluDS56kdH4RGaPcYggdx8k5gd147n51CoKkyjiLfqcTtNoJXHYYpIwxo/4fea1 GRTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X2nZGlkZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SFxIRrs0; 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 h11-20020a05640250cb00b0046786a5845bsi7048110edb.567.2022.11.14.08.32.24; Mon, 14 Nov 2022 08:33:23 -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=X2nZGlkZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SFxIRrs0; 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 S237825AbiKNQb2 (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237514AbiKNQaj (ORCPT ); Mon, 14 Nov 2022 11:30:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF76E2F005; Mon, 14 Nov 2022 08:29:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443387; 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=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=X2nZGlkZy8hrJxqmrFFecZCY+sQ9NUXkXt8yfVeEWVFTGthvoBAQzN5rmoP9KRNRE26w6t 9jiGJ1ON9wOdxumNo2q4ufzjYgzft3cZ0D0RQkq9tPmX5pe6xsYCWGCOwzghY2mWo0kPYB oVSq7hxOHpu9l2KcQnZhtQtSALKert3M5ENv9iyJIqM2g1ktbreAXhapRtNREBK59pA2uj plcXLIJFnoTYhySXS7zM/JuqN/YBOCCj3k1AZWEV6G6GOQJlt+bnurtPc1+/wa25Yz3NSh kUkrtnGJqdGdswSmI4u7aJZBoFIQT8mguQykB4cv+OGSYjdAtiJU0xWgg5JZpQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443387; 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=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=SFxIRrs0xCYkhUmANHStJ9PFRlamUrMYkDFOxLwsJ2Z1crrn2VCOnDK+DynOQDDQKTIYsj JUoobDFz1L4cWEBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH printk v4 30/39] netconsole: avoid CON_ENABLED misuse to track registration Date: Mon, 14 Nov 2022 17:35:23 +0106 Message-Id: <20221114162932.141883-31-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-1-john.ogness@linutronix.de> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749489919976948844?= X-GMAIL-MSGID: =?utf-8?q?1749489919976948844?= The CON_ENABLED flag is being misused to track whether or not the extended console should be or has been registered. Instead use a local variable to decide if the extended console should be registered and console_is_registered() to determine if it has been registered. Also add a check in cleanup_netconsole() to only unregister the extended console if it has been registered. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/net/netconsole.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bdff9ac5056d..4f4f79532c6c 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item, } if (enabled) { /* true */ - if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { - netconsole_ext.flags |= CON_ENABLED; + if (nt->extended && !console_is_registered(&netconsole_ext)) register_console(&netconsole_ext); - } /* * Skip netpoll_parse_options() -- all the attributes are @@ -869,7 +867,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) static struct console netconsole_ext = { .name = "netcon_ext", - .flags = CON_EXTENDED, /* starts disabled, registered on first use */ + .flags = CON_ENABLED | CON_EXTENDED, .write = write_ext_msg, }; @@ -883,6 +881,7 @@ static int __init init_netconsole(void) { int err; struct netconsole_target *nt, *tmp; + bool extended = false; unsigned long flags; char *target_config; char *input = config; @@ -895,11 +894,12 @@ static int __init init_netconsole(void) goto fail; } /* Dump existing printks when we register */ - if (nt->extended) - netconsole_ext.flags |= CON_PRINTBUFFER | - CON_ENABLED; - else + if (nt->extended) { + extended = true; + netconsole_ext.flags |= CON_PRINTBUFFER; + } else { netconsole.flags |= CON_PRINTBUFFER; + } spin_lock_irqsave(&target_list_lock, flags); list_add(&nt->list, &target_list); @@ -915,7 +915,7 @@ static int __init init_netconsole(void) if (err) goto undonotifier; - if (netconsole_ext.flags & CON_ENABLED) + if (extended) register_console(&netconsole_ext); register_console(&netconsole); pr_info("network logging started\n"); @@ -945,7 +945,8 @@ static void __exit cleanup_netconsole(void) { struct netconsole_target *nt, *tmp; - unregister_console(&netconsole_ext); + if (console_is_registered(&netconsole_ext)) + unregister_console(&netconsole_ext); unregister_console(&netconsole); dynamic_netconsole_exit(); unregister_netdevice_notifier(&netconsole_netdev_notifier);