Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp864390rwb; Wed, 16 Nov 2022 08:37:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7acTeTN54vz2AiU8eodHD6WxSjHHyjwq2ksq7wAk/WTnU/ndIal1ZwXmzjpQUvnqaqabYV X-Received: by 2002:a17:903:3255:b0:187:31da:a274 with SMTP id ji21-20020a170903325500b0018731daa274mr9729182plb.103.1668616653117; Wed, 16 Nov 2022 08:37:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616653; cv=none; d=google.com; s=arc-20160816; b=loas+2skqN82Doqx1Qhyt3j5Ten3dUS59c7/aQBJsgkH752lTe4xbB1nA8XN53F4Sh dUAAq0LlSQa3ivDCHcJYT8BskrQWsauT91uo5euv3oOH5cKNCF3bMnCkZp1wJpFf62vC BdCDoRDjZM4/kH2AlrkTjktUjabo6mvg6k5g6uKIoXP/so6dR8ctVujbyyvues8e/Bat LD5R3Kz5gU/NyzLmfOoa8QNvMRqxGboO/6XTAzW9Z4Hi4D8hYLRgBbvJlUIJRwjV1SY4 /JGmCg5v165uWKdeXz1xrsnTn13+NNbhxpYeqAoOn61Hc5HyUQvqypbm9td3am4gbm4a 56YA== 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=xwtHW9ljH5mAN1tD4TJC3RzPTNzj+Q2zm/UowkjIzcuDKtiG5hPUFCUEYwVqB5T6q2 jmD7o0lUyDp8CShPRdQplsLvVBWd/jQZP4ew+te8v1h+SgOJ+qx3thRiFiRGwfQa76/H 2tvcY+ErpZDvhaRw9AnIo02CerFTS4TJjvlDouU5jbuRZuBqbFaiwiw7UNSZg2rwN9/e BzZAIP+CKIxTNMSoxm95khGc29X2g+BzTg+0F0cfC+W0tKIBEmFhvlw0d76zMEEMx8S7 ABsC/pzHx8oBHBmsuobx6aY+LQej4i6oSDzi4rtgfd27Sj7v4LgY2LerQ+225zcCBFKt NUEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y1QeJrew; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a17090ae20a00b002008d0b0838si1996026pjz.178.2022.11.16.08.37.21; Wed, 16 Nov 2022 08:37:33 -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=Y1QeJrew; 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 S234801AbiKPQZi (ORCPT + 91 others); Wed, 16 Nov 2022 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231448AbiKPQWx (ORCPT ); Wed, 16 Nov 2022 11:22:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1F957B6D; Wed, 16 Nov 2022 08:22:13 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615732; 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=Y1QeJrew+e6r3Z7q+FGlwdWrI4cvw5D3zZSh+yYtZ1MEqsgX+54C7plSKQvhmMf4aOXQaT VB5UDGsmTAu5RiwkT/vpLkAveZNL/nhhSnKNreP1IwT1LB66fbpTXNYBLVTqTfTUInn2uZ ZtMz6nBbtfygicnQlCkMnZvKSiNfzeroIUJwCciUpSdoB3yTAViIjUm4q3Zuy9YPA0IAZZ hH9dJXCHjBzaMXXotdH2VL1Vny2M7EHH1CVH/T2z7nhLqxD22Yv43bQ+yMIO8HuFnDu9kt dij2aDJdZte4xlClhtTtLXnEduAIei5RzfkkwJbyZ3CfXdwosiQANNs1SlEaGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615732; 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=yP8+k9Y87ZNwimyqdvpkoA/iVWsPUdCLDpRYhp8K7DNK/Q2rt0iVEsSU3DDL7sxRHTzyY8 cXk/oSk+2Cr8pcBQ== 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 v5 31/40] netconsole: avoid CON_ENABLED misuse to track registration Date: Wed, 16 Nov 2022 17:27:43 +0106 Message-Id: <20221116162152.193147-32-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-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: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.30.2