From patchwork Thu Sep 29 15:31:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9356577 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D2D8E600C8 for ; Thu, 29 Sep 2016 15:31:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3BDB29B5D for ; Thu, 29 Sep 2016 15:31:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B800229B61; Thu, 29 Sep 2016 15:31:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4CFA29B5D for ; Thu, 29 Sep 2016 15:31:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754778AbcI2PbF (ORCPT ); Thu, 29 Sep 2016 11:31:05 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:47119 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753791AbcI2PbF (ORCPT ); Thu, 29 Sep 2016 11:31:05 -0400 Received: from ayla.of.borg ([84.193.137.253]) by laurent.telenet-ops.be with bizsmtp id pTX01t00F5UCtCs01TX0Ar; Thu, 29 Sep 2016 17:31:03 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1bpdIa-0008SQ-J4; Thu, 29 Sep 2016 17:31:00 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1bpdIg-0005Jc-F2; Thu, 29 Sep 2016 17:31:06 +0200 From: Geert Uytterhoeven To: Greg Kroah-Hartman , Jiri Slaby , Rob Herring Cc: Takeshi Kihara , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Yoshihiro Shimoda , Laurent Pinchart , linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC] tty: serial_core: Move uart_console() check after console registration Date: Thu, 29 Sep 2016 17:31:04 +0200 Message-Id: <1475163064-20399-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The port->console flag is always false, as uart_console() is called before the serial console has been registered. Hence for a serial port used as the console, uart_tty_port_shutdown() will still be called when userspace closes the port, powering it down. This will lead to a system lock up when the serial console driver writes to the serial port's registers. To fix this, move the setting of port->console after the call to uart_configure_port(), which registers the serial console. Fixes: 761ed4a94582ab29 ("tty: serial_core: convert uart_close to use tty_port_close") Reported-by: Niklas Söderlund Reported-by: Takeshi Kihara Signed-off-by: Geert Uytterhoeven Acked-by: Rob Herring --- RFC because of the comment "If this port is a console, then the spinlock is already initialised", and the pre-existing code calling uart_console() before uart_configure_port(). Can be reproduced on Renesas boards: 1. With systemd: hangs during boot, 2. Without systemd: "telinit n" to switch to a runlevel that doesn't run a getty on ttySC0, and trigger kernel output. --- drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 6e4f63627479db8d..ce8899c13af3d97f 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2746,8 +2746,6 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) uport->cons = drv->cons; uport->minor = drv->tty_driver->minor_start + uport->line; - port->console = uart_console(uport); - /* * If this port is a console, then the spinlock is already * initialised. @@ -2761,6 +2759,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) uart_configure_port(drv, state, uport); + port->console = uart_console(uport); + num_groups = 2; if (uport->attr_group) num_groups++;