Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1946462rwb; Mon, 7 Nov 2022 07:30:51 -0800 (PST) X-Google-Smtp-Source: AMsMyM786EdvK7uE8YsQ4pkq9NQ/YQs0Ew9U+PHcDLIW5ydribI3NVjJ6V7dXhQYCkf6YcB50baG X-Received: by 2002:a17:906:5a46:b0:7ad:b822:d2c2 with SMTP id my6-20020a1709065a4600b007adb822d2c2mr45816863ejc.41.1667835051512; Mon, 07 Nov 2022 07:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667835051; cv=none; d=google.com; s=arc-20160816; b=ugjc6A0Qq+e+UZstMDsTtftuBbNUVYsGCFd5hzf9r0pCBOg5VKIrlM5+PpVIwCFeBU iXj1oI1lOkzU2/KLFBr1m0c1FdYDwxMg5BdJlWc9Kc64bc54y/fzM+irrZKKtOJAaFFX YEbKGJBVNn+bxpSiFBZCOxohfuuF/HQboD1zQJdlv+2WZYGwUrmUCRtZm/C3KFeEoXpB vUomjnamxmcapC2gFFD88M+tOPjuma4L0SePA2rE5loeSj0SQKgahVuFVmk7nV5aQTR+ sOCR0saOzli5B8+GB90JAe/VS64BPgbjFEl8cdYuOt7R2FI2ya/EwvrXkITGpNRYSRnm S1vw== 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=PZnHcm5NbZutAYnEPreYIvmpIgElStPef/CZZp0r/mfr5BKRpfHg8dnWTLjwpWPlRO UxO8EoxGqHv0l9L5WfWmhtzgw7cu8hQDJdWTK7RwWaMGAY+TV6jCz2z2wUoIjUPyzbe3 dEtgR0B/fxBIymjHn43e7JylrEECkbk8tuScy6ADG75A0S4fsWYNuvyB+AvkvQZ3PneK RnT/5QPpO8KEWbc0MC1Ge6mmNNeCB895PhwfaNN1Mxi1lYb3SsYw8jRNrewGHMtENKLw MRTiV2JWc9DrLwpNURK7KprP2tMNkxFe4LpXhgB8gvEV1AcMbusHNwMfWZBvTqPDOepx Wwdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=L11tUFib; dkim=neutral (no key) header.i=@linutronix.de header.b=Jzuhyq4W; 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 sg9-20020a170907a40900b007ae0ea7fbb1si9473550ejc.812.2022.11.07.07.30.27; Mon, 07 Nov 2022 07:30:51 -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=L11tUFib; dkim=neutral (no key) header.i=@linutronix.de header.b=Jzuhyq4W; 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 S232022AbiKGOSV (ORCPT + 93 others); Mon, 7 Nov 2022 09:18:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232194AbiKGOQx (ORCPT ); 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 3622D1BE94; Mon, 7 Nov 2022 06:16:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830610; 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=L11tUFib1G7F6mY3RRp/5bwlb4Vu20NYOHnRQlaHISa19VU6Kx3MU5faeHGQs3/pP3A1Hv twtd3bKm/hXohF2tydjSaXRXAC46xLsn0KJHs54ZdCdqlm60KzUmbR3tAyr1ZIlPF5TrCw ksUS5iL9ZwtE8sUU4vb40iTPqmqfE3fajjjN/ZLSdODJg2RR3PBZty8oy/Y0Dt93FUdfQA JK94MG1tQfJROwIp4xVvRjI77oM43QV+Xdy+VENbkmA5yJXVUBYyS0KebOZBua4ufJcnfE MPiaak6UX5FqziJ7Ulq7BNesF5q0KQ0nx604yhWALH6YIJsoKIxAYfd4Heqvhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830610; 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=3bRXv5eLsbcExmVmXYZsW7ueqOnPYP5gSMK6Tjs5QCA=; b=Jzuhyq4WOiz8XELTHvXUgz9BZIWFKbOSmwVTT0Gs76CEl8Q2I+uYnQwlWUsGjK7sw9vEU1 FnPrlsZhC4v41xDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Geert Uytterhoeven , Tony Lindgren , Lukas Wunner , linux-serial@vger.kernel.org Subject: [PATCH printk v3 23/40] serial_core: replace uart_console_enabled() with uart_console_registered() Date: Mon, 7 Nov 2022 15:22:21 +0106 Message-Id: <20221107141638.3790965-24-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: X-Mailing-List: linux-kernel@vger.kernel.org All users of uart_console_enabled() really want to know if a console is registered. It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. A _locked() variant is provided because uart_set_options() is always called with the console_list_lock held and must check if a console is registered in order to synchronize with kgdboc. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_core.c | 2 +- drivers/tty/serial/pic32_uart.c | 2 +- drivers/tty/serial/serial_core.c | 14 +++++++------- include/linux/serial_core.h | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 94fbf0add2ce..74568292186f 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -565,7 +565,7 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) up->port.dev = dev; - if (uart_console_enabled(&up->port)) + if (uart_console_registered(&up->port)) pm_runtime_get_sync(up->port.dev); serial8250_apply_quirks(up); diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c index 2beada66c824..1183b2a26539 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -919,7 +919,7 @@ static int pic32_uart_probe(struct platform_device *pdev) } #ifdef CONFIG_SERIAL_PIC32_CONSOLE - if (uart_console_enabled(port)) { + if (uart_console_registered(port)) { /* The peripheral clock has been enabled by console_setup, * so disable it till the port is used. */ diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 179ee199df34..b9fbbee598b8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2223,11 +2223,11 @@ uart_set_options(struct uart_port *port, struct console *co, /* * Ensure that the serial-console lock is initialised early. * - * Note that the console-enabled check is needed because of kgdboc, - * which can end up calling uart_set_options() for an already enabled + * Note that the console-registered check is needed because + * kgdboc can call uart_set_options() for an already registered * console via tty_find_polling_driver() and uart_poll_init(). */ - if (!uart_console_enabled(port) && !port->console_reinit) + if (!uart_console_registered_locked(port) && !port->console_reinit) uart_port_spin_lock_init(port); memset(&termios, 0, sizeof(struct ktermios)); @@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, * successfully registered yet, try to re-register it. * It may be that the port was not available. */ - if (port->cons && !(port->cons->flags & CON_ENABLED)) + if (port->cons && !console_is_registered(port->cons)) register_console(port->cons); /* @@ -2956,7 +2956,7 @@ static ssize_t console_show(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) - console = uart_console_enabled(uport); + console = uart_console_registered(uport); mutex_unlock(&port->mutex); return sprintf(buf, "%c\n", console ? 'Y' : 'N'); @@ -2978,7 +2978,7 @@ static ssize_t console_store(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) { - oldconsole = uart_console_enabled(uport); + oldconsole = uart_console_registered(uport); if (oldconsole && !newconsole) { ret = unregister_console(uport->cons); } else if (!oldconsole && newconsole) { @@ -3086,7 +3086,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) * If this port is in use as a console then the spinlock is already * initialised. */ - if (!uart_console_enabled(uport)) + if (!uart_console_registered(uport)) uart_port_spin_lock_init(uport); if (uport->cons && uport->dev) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index d657f2a42a7b..2f910f2bbe53 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -743,9 +743,20 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED; static inline int setup_earlycon(char *buf) { return 0; } #endif -static inline bool uart_console_enabled(struct uart_port *port) +/* Variant of uart_console_registered() when the console_list_lock is held. */ +static inline bool uart_console_registered_locked(struct uart_port *port) { - return uart_console(port) && (port->cons->flags & CON_ENABLED); + return uart_console(port) && console_is_registered_locked(port->cons); +} + +static inline bool uart_console_registered(struct uart_port *port) +{ + bool ret; + + console_list_lock(); + ret = uart_console_registered_locked(port); + console_list_unlock(); + return ret; } struct uart_port *uart_get_console(struct uart_port *ports, int nr, -- 2.30.2