From patchwork Mon Nov 14 16:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238470wru; Mon, 14 Nov 2022 08:31:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4dbkqomTeh4CHsygoSUZlkBYc0CIweKtnYNCPLyNIeiYukLVjYY19j356iMUSTjjb8xxGJ X-Received: by 2002:a17:902:ab07:b0:188:cfc6:8543 with SMTP id ik7-20020a170902ab0700b00188cfc68543mr64059plb.95.1668443516787; Mon, 14 Nov 2022 08:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443516; cv=none; d=google.com; s=arc-20160816; b=Q7wiJOC6r4H9WseGMDH32s0ldN9RRWa/f706FSZOXKsET5xOaZ0aRy+awO7FA8qgaz SBy/szmvtP6G6gQObKbrbkx6Ngsfr6SFhCOw/VIzpqPZ0WBIWaovBIlrFoHD3rQUWs4n jLl4K8g5FE4Hy4XQpWd3tUBYmUd3xDFAH3+AuuMp51n4hZ5Ft5l3v2iiXLqEWegsAgfj qVwIw0rEpEGwmS63FcxvWoslgNJD44GNWKVQPPmF+Im3xB3hnrHtuR609cqIluWKBARE BvlBbFYQUiNvphYy6lvNBeFUB02iHID107dswSFGTkYFMEKnIJN6UkkC/o7fIle48RT+ BdLw== 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=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=el4NsP2T5diSCN/uYnWyaULKrAhxksCch0IR1WYUDlDcczhNTGvvSN87g4ulfjopAW K9WYN0xqmPZP8eZOs8aNk8eSguWPaF7OecG+q4Nx4oNh7IWma66cfRHycTHGB9D9ogSY q9SPhWDGhhrTbDgEr0nYQLoPP/lHI/NgKe31UhWbPnU1JFAAUj07uI/Dyb0z1cAfY+w4 wOGzhfpxhLH2luoruqf9CSe2hWCzcR4n6iAt4uDqYCiBOq86kasIbffWegEHj57Tb1Pn EbU8Z6hbnosIz9IQyyMimIFkpNfejnzHEH/0qbudX9PU12zxV4MycanLy/hCWHSrZhjw A9EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bz1sBZFQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=K28m3TtQ; 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 m16-20020a63ed50000000b0046afa55b6a5si9507115pgk.708.2022.11.14.08.31.16; Mon, 14 Nov 2022 08:31:56 -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=bz1sBZFQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=K28m3TtQ; 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 S237675AbiKNQa5 (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237610AbiKNQaP (ORCPT ); Mon, 14 Nov 2022 11:30:15 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A842B23174; Mon, 14 Nov 2022 08:29:44 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443383; 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=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=bz1sBZFQ9FlXBPXMTmtVMbJRNxqfR+mzsZ4rRAsZyfDX14X/86pQ61WXJ9xCa5X77pHzeH XMAdv3qyOC9kE/KAeG2wxvFUx0iQwF/hRVrqqWa4MGDAPzvVpIYtPiEEEd9LR5DRWjwJO4 eE8DlIljkYklMTXuFtdRXqRHXB+HmSnieQKAnKLFneeTzXuE6PqyPa0eIbk4Ke6GiYZOG1 OZcVSL6skEeLJgXgrnfHmBP/vVHJ05r7OwEAjBiT0bjBmijzVJqkB9QSBQMz3jsi7we1K6 L5kW1kn7e1gSotYXjT0OECAXNjtendtg2727NH9IJWQgI4qSHxcJRhixEvlw0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443383; 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=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=K28m3TtQEWACw5E1Ri6Wqs3FBdXDACqTkbbU+SVuLq50H9NVjXzb19t1SSArfgZLQ4Uahx bC3nejFtw9CmbNAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Lukas Wunner , Geert Uytterhoeven , linux-serial@vger.kernel.org Subject: [PATCH printk v4 21/39] serial_core: replace uart_console_enabled() with uart_console_registered() Date: Mon, 14 Nov 2022 17:35:14 +0106 Message-Id: <20221114162932.141883-22-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?1749489829120638358?= X-GMAIL-MSGID: =?utf-8?q?1749489829120638358?= 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 Reviewed-by: Petr Mladek --- 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 | 10 ++++++++-- 4 files changed, 17 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..91871464b99d 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -743,9 +743,15 @@ 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) +{ + return uart_console(port) && console_is_registered(port->cons); } struct uart_port *uart_get_console(struct uart_port *ports, int nr,