Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp134460ybc; Mon, 18 Nov 2019 21:55:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwqrg7j1/sEMkUOxsBT/RF0FEWS/AAqiC1U3qEeXlsii43/cs3e24kV9TXb9ulWteyvZgxD X-Received: by 2002:a17:906:4e53:: with SMTP id g19mr32504316ejw.286.1574142940389; Mon, 18 Nov 2019 21:55:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574142940; cv=none; d=google.com; s=arc-20160816; b=wuWyUG5lUxnBOp2q+81NnCP0O8nTV/MoUCH1JqoEVqkzJ8xm8HGaEiXBLNmST4kWOt tl7TiuWTUC0hmXjeubHAPS4bGsydTtv/K779plhvWmNmWHWmOnsxrL3ta9HXFGLgzs3z WAZET/lSgqYne7DAvCPpQct7yWDD/sEPV5yL2t0WLDctWzuNsO13Ss5A1MtbuWsauT16 MxPa2pmLWyKqvZxiW/B/7/OGt41dXePffcHcjBFpOYLIdUB3c8Rf4ri+8FT8jvJRUans iKHaaGl4gjFXbfiG7Rjqo4yN1TEkrytei2Qw83PHP0ZWMDXc/GwZm8fAksVY82ZZs121 Eraw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6A48Q4K4SfQpsAmdr453y2OgbT10j7C+OxbO+qfXQX0=; b=kgoelnI8SC7grIFKnTbzrCt0SvIljGbfSr9bPXExQYCrghxXhMrcNTLVp4FM6q+Ky2 HFsrgbXz7m1Sp9Xjc7YuLYdDldIk6MxbuKlt5DNK7aQsJmUq9Ra+NDAxJRwPLIgit6iU Nu9QgKZDecQgVLgvN9R4pZQOr6/tcrdAJat4ni6PpRsR8hwvb1zzh442L8m0wyVi4Zq6 xSV3gYyyIPdMmX7OnmZbT9p/xtxtxWzrSfFSwkYJxjqEcAKqm31C+iCLlI/0LbH5q37u b7AO7XqjhpV+Z7UgIiDAKloZsdzZa9wRPtqBaRIQ6UX3K6ft8e0CP8qoPuxvfgkbZEvK 9UxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=en3qPCVR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd8si3142904ejb.403.2019.11.18.21.55.15; Mon, 18 Nov 2019 21:55:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=en3qPCVR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731849AbfKSFvv (ORCPT + 99 others); Tue, 19 Nov 2019 00:51:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:49350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731843AbfKSFvt (ORCPT ); Tue, 19 Nov 2019 00:51:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 38EE6208C3; Tue, 19 Nov 2019 05:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574142708; bh=2Ryiu54J7RjdKSMXF03LaKQ2DIslLnR9lwAhh7kigR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=en3qPCVROYEmx0OoprYHXcbE0j+rSXkJfGg5wdHo5S9M/ixWJxl64MTYKvMs0alB5 ZXOiQ0MK8+GGrqgF2UeAJKjUeRDN+XS/vBfIhbjonBk+XvHia/KzXjc1wjrRSlzBie hbG5husIqJS6olvXgKhGyEgdDFac8k7CBepRY6WA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nava kishore Manne , Michal Simek , Sasha Levin Subject: [PATCH 4.14 132/239] serial: uartps: Fix suspend functionality Date: Tue, 19 Nov 2019 06:18:52 +0100 Message-Id: <20191119051330.773039084@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191119051255.850204959@linuxfoundation.org> References: <20191119051255.850204959@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nava kishore Manne [ Upstream commit 4b9d33c6a30688344a3e95179654ea31b07f59b7 ] The driver's suspend/resume functions were buggy. If UART node contains any child node in the DT and the child is established a communication path with the parent UART. The relevant /dev/ttyPS* node will be not available for other operations. If the driver is trying to do any operations like suspend/resume without checking the tty->dev status it leads to the kernel crash/hang. This patch fix this issue by call the device_may_wake() with the generic parameter of type struct device. in the uart suspend and resume paths. It also fixes a race condition in the uart suspend path(i.e uart_suspend_port() should be called at the end of cdns_uart_suspend API this path updates the same) Signed-off-by: Nava kishore Manne Signed-off-by: Michal Simek Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/xilinx_uartps.c | 41 +++++++++--------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index b0da63737aa19..0dbfd02e3b196 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1342,24 +1342,11 @@ static struct uart_driver cdns_uart_uart_driver = { static int cdns_uart_suspend(struct device *device) { struct uart_port *port = dev_get_drvdata(device); - struct tty_struct *tty; - struct device *tty_dev; - int may_wake = 0; - - /* Get the tty which could be NULL so don't assume it's valid */ - tty = tty_port_tty_get(&port->state->port); - if (tty) { - tty_dev = tty->dev; - may_wake = device_may_wakeup(tty_dev); - tty_kref_put(tty); - } + int may_wake; - /* - * Call the API provided in serial_core.c file which handles - * the suspend. - */ - uart_suspend_port(&cdns_uart_uart_driver, port); - if (!(console_suspend_enabled && !may_wake)) { + may_wake = device_may_wakeup(device); + + if (console_suspend_enabled && may_wake) { unsigned long flags = 0; spin_lock_irqsave(&port->lock, flags); @@ -1374,7 +1361,11 @@ static int cdns_uart_suspend(struct device *device) spin_unlock_irqrestore(&port->lock, flags); } - return 0; + /* + * Call the API provided in serial_core.c file which handles + * the suspend. + */ + return uart_suspend_port(&cdns_uart_uart_driver, port); } /** @@ -1388,17 +1379,9 @@ static int cdns_uart_resume(struct device *device) struct uart_port *port = dev_get_drvdata(device); unsigned long flags = 0; u32 ctrl_reg; - struct tty_struct *tty; - struct device *tty_dev; - int may_wake = 0; - - /* Get the tty which could be NULL so don't assume it's valid */ - tty = tty_port_tty_get(&port->state->port); - if (tty) { - tty_dev = tty->dev; - may_wake = device_may_wakeup(tty_dev); - tty_kref_put(tty); - } + int may_wake; + + may_wake = device_may_wakeup(device); if (console_suspend_enabled && !may_wake) { struct cdns_uart *cdns_uart = port->private_data; -- 2.20.1