From patchwork Mon Sep 3 13:10:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 10585841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA47D920 for ; Mon, 3 Sep 2018 13:16:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81CA297C1 for ; Mon, 3 Sep 2018 13:16:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB027297C3; Mon, 3 Sep 2018 13:16:42 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E995E297C1 for ; Mon, 3 Sep 2018 13:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zMJOIi2zxpdSbZdPMg7TMwgbVNPj2L5SapesNfBw5DM=; b=r1rvHo+2zpSmchhtnvwzfTQdO5 UCDaiGnOAYgbG/A4fq5B5WmsCMBSQSbx4IERwy9g6hSaPzSahG7eyddM25LKCpFBnHmgQ10wkWKxv PNRGnxcWjfrHVmlw71wZRuIUrkVeFBpV3yzNS/xGoVkp8/Y+Z/svcNQLW3wGp7uMpoVhEsKvPmqYE +Xz0NopKjgtUcOqu9tBmgCnkd/HZlKLDPusXFP4143tjMX2psFEhWwiWTpeE4BIsq11JNzDjv6Uuh BSjPV2ohbrZta9Pe/KauFbLOMMe0qIfrUPNWArjM7omvYEiyEv5Eo50edoq8BVyeMXJVJzq2bboa1 vY1AnaAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fwoiT-0004R4-Ln; Mon, 03 Sep 2018 13:16:29 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fwodR-0000pR-D3 for linux-arm-kernel@lists.infradead.org; Mon, 03 Sep 2018 13:11:19 +0000 Received: by mail-wr1-x441.google.com with SMTP id a108-v6so574404wrc.13 for ; Mon, 03 Sep 2018 06:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=y8UxnDrErzxaoHSaqXHkoDRD2bv3bmlfTzwBM+V1Aq0=; b=OAmmz4f+WbkYQ1097bi5XKeyMZ3U4MNWAR5flZRi6QKa6b1GFGn/mC5L5mbYBpoovp 38hNKlzImUmyBYwPzEm3GSTCa4fVJ2cxMAlFhqhy5eu8D224b+x20T+WfaHM3clRa7yw pTiegdFxTnacsl9CMrjsRpaGMEhG0xQt4xJ6jNV829xZkPI87Lptpu40apPSfVpU6cdo 4HTbb1WafAR+yOL0gwQfbPpCsd9PnMGg4yHXNQT669+2Vjku65tJy5Jn3RiqFAFJVsCp /EnHKEBplQwxYUxskoe2PKDNXrfxs0+7f71eR2MKJgPR2Ux4e7hBUmg+AZsaR4DgH/7L VxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=y8UxnDrErzxaoHSaqXHkoDRD2bv3bmlfTzwBM+V1Aq0=; b=L7i+FqT1oBTMiH2xXN5fynvkGUkAdmJXeEkcHmXT10x9V2DWA8bihh4uQcWl87lQB/ /KizTgHjAeMpjbtBb/ygzKTZlhVCHwVq88ghEr7ApLyJV4GbP+f3D3AB2XYQ34H6Z5E+ eKcrRG+ntMXil/qToLRinl6LsU2VzDTLR/jg4s8AJqRPcPmGBM/OTeqhn5PEtHWoEpVF pkOeYdDgsiUILAgPLHHuSL5pPB56LipsLKytJV9J9JJT9wnpgx/yhf5u7EJzenRWdKsA /HTKoYFuKqfBxH4cGwrJel4/KTL9nrnOBQYKsulsOcWB48jy6WoqBHgvfGCn7+9vySzH PzQA== X-Gm-Message-State: APzg51D45xvgEM+n3N4bD7nki00ppXXSK8OAunILm8ATIwzDJyBaiWp2 GS1x7gp12YkKg1/6wguCsJ6D1Q== X-Google-Smtp-Source: ANB0Vdazt/g3oJviGvhnyg9Tzd2SJeE/irkN8Tl+e3d4uBsSn16KK2E85oNBoRtJiI1r9bAVe4lWEg== X-Received: by 2002:adf:f045:: with SMTP id t5-v6mr19094895wro.92.1535980264715; Mon, 03 Sep 2018 06:11:04 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id m68-v6sm18555465wmb.10.2018.09.03.06.11.04 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 03 Sep 2018 06:11:04 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, gnomes@lxorguk.ukuu.org.uk, Alexander Graf , shubhraj@xilinx.com, robh@kernel.org Subject: [PATCH v3 03/10] serial: uartps: Fix suspend functionality Date: Mon, 3 Sep 2018 15:10:51 +0200 Message-Id: <26804ea4d2196674a30ddd7dccc068269816b882.1535980253.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180903_061117_468508_1F6D653E X-CRM114-Status: GOOD ( 19.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Nava kishore Manne , Greg Kroah-Hartman , linux-serial@vger.kernel.org, Jiri Slaby MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nava kishore Manne 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 --- Changes in v3: - New patch - can be sent separately but there is dependency that's why sent in this series Changes in v2: None 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 9a08542cec47..fc0ecaf3615d 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1272,24 +1272,11 @@ static int cdns_uart_console_setup(struct console *co, char *options) 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); @@ -1304,7 +1291,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); } /** @@ -1318,17 +1309,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;