Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp178335ybc; Mon, 18 Nov 2019 22:52:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxFHhAGVUI7vCMPEZiZADe8ePrRaH40H6s6oEWKYZvw/l6KGtqDTqphUVo2uKKZP2X+U+QM X-Received: by 2002:a17:906:95c1:: with SMTP id n1mr32531402ejy.158.1574146344231; Mon, 18 Nov 2019 22:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574146344; cv=none; d=google.com; s=arc-20160816; b=zYPkQNHltTanlFBbb+tTrEmjB4yciDj4cfQ03DOb5sAisAsqMYLxoMP05mf0VFYruX UpWUizdMDGbi4uhGdWE+xPf7BPIx30+mH8DBcNiBcBzyuvzVGfUmCUNHLgtvGPlr06yJ rJ5geQ+IXlDTAATJGcm/W18LbRlczkeHrF2bPWoMo9xf7rwH4rbvQIzBW8D8EDBLAfVW 0cb+9HANBV/gWWNejo3utUboeZY5LHMfNIaYNtTYlsNDB6VzczjDRq3kIC5rY0nH60a6 Hg/UpeOmAxNE/NLFz+u1yirCKikJR+/d8pMblGgMT1uFlE7zXvw56uB/473LSuVPbKu/ fznw== 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=V6IoYwUu/v/sS0eCnsipx4zDaR/moh3jECI+nsFNexc=; b=bwkEa3yof00eBykgvP5R7XhdJ2mHOPdxTolDZ7z095lcB3vJvhTPgCCO2+nItjr2EF k2F7z9jZz8k2lvElDqlhEQjqfll96jy+5nB/HvXngeTiWCw2j/FQXlMx9vEC3w4xBNen 5DHpr3L7o3hs1+7RvKALGlFxCVffD0TjTQhR0bIGK6PCC0H83OI/5dqCNj4jFB+2jYMI tbqA+ShV35H0Dj7J4gKlF194BFdUd8jTQfriW8+/ms07DFMTez9eE1lGqs8wukf6vBTM 3vEz83MR0Zqa0f7W9HAaF+NFfnMUOuaAZaI//6Mg3C3G8/TQcKagJBxEhoiOMpYprYn3 6vVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yXGqfwLi; 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 4si18032169edc.4.2019.11.18.22.51.59; Mon, 18 Nov 2019 22:52:24 -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=yXGqfwLi; 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 S1729717AbfKSFem (ORCPT + 99 others); Tue, 19 Nov 2019 00:34:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:55442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbfKSFel (ORCPT ); Tue, 19 Nov 2019 00:34:41 -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 40A3D208C3; Tue, 19 Nov 2019 05:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574141680; bh=Skao6+giRM+BTw2RKzLY/18Rl/+xSoa8wM3mstDU30g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yXGqfwLi0EofGm3vi8/6IA9oX2xIOs7xtg8Zk9p7PQK02uMw3eP2zLhHxv1o94H6p C1H63jiNSXv2ZLxMPlX7JIeNzs1PtFA5+Y02yGG5yWQE7+K9kGjYoJX5bW9+p1tpZ3 Ew/WuQBUGygNHTgDyOxalG2dDNn0zkGHx8PUmBAI= 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.19 244/422] serial: uartps: Fix suspend functionality Date: Tue, 19 Nov 2019 06:17:21 +0100 Message-Id: <20191119051414.817459724@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191119051400.261610025@linuxfoundation.org> References: <20191119051400.261610025@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 77efa0a43fe76..66d49d5118853 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1279,24 +1279,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); @@ -1311,7 +1298,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); } /** @@ -1325,17 +1316,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