From patchwork Thu Nov 8 01:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10673355 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 95B8013A4 for ; Thu, 8 Nov 2018 01:56:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8700C2C945 for ; Thu, 8 Nov 2018 01:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B3922CAFB; Thu, 8 Nov 2018 01:56:26 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 17B082CAA9 for ; Thu, 8 Nov 2018 01:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbeKHL3a (ORCPT ); Thu, 8 Nov 2018 06:29:30 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:39004 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728435AbeKHL3a (ORCPT ); Thu, 8 Nov 2018 06:29:30 -0500 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id 0B8DA24E03F1; Wed, 7 Nov 2018 17:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1541642185; bh=HcDWNQrD3qN9zHYdWMobhfE4c+paZoQiSlQ4yFhuPQM=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=RAS+fvm+pUJQRqcVZx6Z9QG5m8Hb8c4//EZdFrYoeVsQhXyZimyIqu3UK175DYPn5 XdXKnZ1A5i8cnp7izvCv0f+UTltOVo/bX0uM8M08AaVL2FNlmLvcL2xMGqXiBuaGsy wzel+3i/y1obnqC9Klrpgp8az4fYDCiniQvZg+hnbHC4TudHZkqiKbs31TgGDYeer/ gd3WKhXxW98TRCFzE6zBpWNfnJCV8IcVxM+Q/Sp8mTfm2Ygza+j71ikzLHMBQl0dmt SPXmn35wR68MGviR213IL1bQGW3SuWp5dVIJNyB0nsRQwmWSWeWDics/NiVQsvMBVw HWwpzB3Yjoy7w== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id EA1C35B0C; Wed, 7 Nov 2018 17:56:24 -0800 (PST) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 7 Nov 2018 17:56:24 -0800 Received: from te-lab16 (10.13.184.20) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 7 Nov 2018 17:56:23 -0800 Received: by te-lab16 (sSMTP sendmail emulation); Wed, 07 Nov 2018 17:56:23 -0800 Date: Wed, 7 Nov 2018 17:56:23 -0800 Message-ID: <728638068ab01fe72104912ec09caf872b806685.1541641164.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 5/5] usb: dwc3: debugfs: Print/set link state for peripheral mode To: Felipe Balbi , Thinh Nguyen , CC: John Youn MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current implementation only prints/sets the link state for peripheral mode only. Check and prevent printing bogus link state if the current mode of operation is not peripheral. Signed-off-by: Thinh Nguyen --- Change in v2: - New patch, no previous change drivers/usb/dwc3/debugfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index e613a61ae58a..1c792710348f 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -542,6 +542,13 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) u8 speed; spin_lock_irqsave(&dwc->lock, flags); + reg = dwc3_readl(dwc->regs, DWC3_GSTS); + if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { + seq_puts(s, "Not available\n"); + spin_unlock_irqrestore(&dwc->lock, flags); + return 0; + } + reg = dwc3_readl(dwc->regs, DWC3_DSTS); state = DWC3_DSTS_USBLNKST(reg); speed = reg & DWC3_DSTS_CONNECTSPD; @@ -589,6 +596,12 @@ static ssize_t dwc3_link_state_write(struct file *file, return -EINVAL; spin_lock_irqsave(&dwc->lock, flags); + reg = dwc3_readl(dwc->regs, DWC3_GSTS); + if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { + spin_unlock_irqrestore(&dwc->lock, flags); + return -EINVAL; + } + reg = dwc3_readl(dwc->regs, DWC3_DSTS); speed = reg & DWC3_DSTS_CONNECTSPD;