From patchwork Mon Nov 7 14:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078589wru; Mon, 7 Nov 2022 06:20:48 -0800 (PST) X-Google-Smtp-Source: AMsMyM7VvCTalhhGbv+88amafQ+63Ye7/bW8pvihyQrtsjFRgHoSsx0Su1ylTr/KkapjHgaS9q/1 X-Received: by 2002:aa7:d858:0:b0:463:12ed:3f86 with SMTP id f24-20020aa7d858000000b0046312ed3f86mr47021548eds.281.1667830848023; Mon, 07 Nov 2022 06:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830848; cv=none; d=google.com; s=arc-20160816; b=aRnm0RRDTlm1pl+bn74p17fuHNkZLubGDll2gFB5UceG4SO+rPXT58EP322O3NTV1Z LsKynEWiP5eOnigO1DVm1AZ2UYw3Hm1cypZXNt08VbaMPeTdqsZq/Xx9Guu39IVkDLmg JkdBeuOL0ldaJ6EjTdqDFGnN6ooosGAy8bVCxIfDWI8qgv7mU78zZ/HJd/Wywfsd0vr5 7hDeviFG0W0Tn/RJQFmr+wYdMp3PI2/HcoWQ5hQfLoNphlz8UaKRIDDEe7aaXR8ckSUb iGTZDGO83m2X9ASSxWV5hLUET+PNueNQznlhPEdqK7V64+MzgdVQSbTDuuZ6wP2gTK9j d4xA== 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=YTUlGbaC4IbICTFrgEP8a7yLfyPtpor03FP0It9Xna7JDvnKJ85Iv/pdSFDtMddIv9 O+2fPyB4oDNuAOSB1MkSUO4tyRscd6zT3hrh1tDVYgV54Seke/lww1/8sL9CXdP5H+mH BIFamsQl7IdPsFV+T2z1pGj1CSm7HKzZgGJ+uG2jy6/IG0e7krJApRWSEuTR/E9pSVjW FKfNnrKJG+6vLGa/AmMfXPOjWfp9cDFTT68YYPdsRz+ezsiYD10nCmwUv5BchYRQjo/E BQCW1LG4JXXo1VChv5sl7Y9OuJj4GkuVOvgVN7jgNuIiNUAMJP/MRwbAkmFgpi9hgT84 lMjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=b4ql8y1C; dkim=neutral (no key) header.i=@linutronix.de; 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 j8-20020aa7c0c8000000b00458e689f41fsi7958423edp.415.2022.11.07.06.20.19; Mon, 07 Nov 2022 06:20:48 -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=b4ql8y1C; dkim=neutral (no key) header.i=@linutronix.de; 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 S232103AbiKGOTF (ORCPT + 99 others); Mon, 7 Nov 2022 09:19:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbiKGORR (ORCPT ); Mon, 7 Nov 2022 09:17:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FD7E1D31A; Mon, 7 Nov 2022 06:16:56 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830615; 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=b4ql8y1CqshqWcXCG3fY/oCmxHiTCLqFp/vC5T7L6qJ5ftrsfJggc2LiYk23/G8uF2RCo0 sQwE/M5aYJgbrztjWgKxbzTaokKE/ML8eKgCOoi7fZ6th7Q6pJlmDrboSmojAXWzxG356u 7EMylIHc0pr+wXYfxZnGu4sgYKQjAL5nNKNuNvsc+jwAC/UqM05yo6/phGUgUXGOA+FWJ+ /9BhuARU1Zk7JU3Tmkq/Qgr0KvpxrbmyGDFMZ7kTywgU+fFz1SD8KFVXYp6F4mSxtC4BLZ AU01jBfG7+/FAho/BFUkNEEwhkzUPDHfiPPbLzhTGSyAHbAH0YoxbOKx+scuNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830615; 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=rxs6+Z/gJrAzLbOcrJicwux9sfUp+1EZ2u/YGiVkJQ0=; b=NB2DL2wjGq46VY5TZjuKeyQr4jtN3KHh2TuJaQu0Gc6dPBeDZEg/LqMW4yrdBOi8ko43Bk Rtc49uN3OHpgz/BA== 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 v3 32/40] netconsole: avoid CON_ENABLED misuse to track registration Date: Mon, 7 Nov 2022 15:22:30 +0106 Message-Id: <20221107141638.3790965-33-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 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?1748847399396975342?= X-GMAIL-MSGID: =?utf-8?q?1748847399396975342?= 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);