From patchwork Mon Nov 7 14:16:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078903wru; Mon, 7 Nov 2022 06:21:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM5IDvzJyZQTXMw5Q7G2lcyYU4U1g10kOS5qjdaLTeJnGwj6lJ2heubda0JTPugyhRpVH73C X-Received: by 2002:a17:90b:3a88:b0:213:f069:7197 with SMTP id om8-20020a17090b3a8800b00213f0697197mr39801525pjb.181.1667830884538; Mon, 07 Nov 2022 06:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830884; cv=none; d=google.com; s=arc-20160816; b=RBEH8E+SMfU4IvsiPbHP2Tu6jp5+jKHL6yYlQDsxZ048D+f1nUOQytPM4Qrf1m7B+U uFYrfQXvJq3NHMjWuST9VnjGoeXiZdRVXQwrVxExqYJJkmzz0AbhdDZrqnOTcNAR5rra IfOYzceFZdKs1v8MCijv3S+enYJMIoVOflWApBDC3YhzxwRgmjjqDcZs4YNOJjP+d/N0 aANcOx78aDGeVZb2UsCDP407x9OvEO/BTzjows5bZzXtKv72ckNM9CG5Kmao4SJBp509 ctHAr2/ttt2lJxJrm75F9kF33ndGpqLNWoK5Hm6AGnNoRFGLWJf9nMGGrgkURSJC6Co+ l1pw== 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; 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 qe1-20020a17090b4f8100b00202b984842csi11602380pjb.35.2022.11.07.06.21.10; Mon, 07 Nov 2022 06:21:24 -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; 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 + 99 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_J=C3=A4?= =?utf-8?q?rvinen?= , 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 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?1748847437695747477?= X-GMAIL-MSGID: =?utf-8?q?1748847437695747477?= 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 | 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,