From patchwork Wed May 3 09:53:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 9709083 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 A847260385 for ; Wed, 3 May 2017 09:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8993828471 for ; Wed, 3 May 2017 09:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A887285BA; Wed, 3 May 2017 09:54:18 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 70E3428471 for ; Wed, 3 May 2017 09:54:17 +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: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:In-Reply-To: References:List-Owner; bh=PH87fPoThFoefoQ5SQwgHEZ1cwyb6rUEl/fivcMwj9Q=; b=JAa GIqMhOJ0o/EgR3m4h8O4kDc8LD0b1C4roVufAQWxIHaVtMom/kcRYc7V8p+GaOffCAFdkqg8g9cxG VXD728Sn0yE3I4HeR+2EJnN+beyHDegm+M/GNEgbd+gaBZkvzEXzzQuvF7ln9xMPPHWBqtDvDjPUf 2A+MEWJ4VhMXPitvG1nscaGhkF2si+3070AUUdGGO5+q6Pq213uMXAfR8ZlXIYgYO/jttcgcH/KPy SzEZyW1/3NDdffudyZxnRWd9/tGpk1zaqvc5t37JCaqZuQRn0BE7/SoxT8XjIosmg6pDFa/7jaJdv AeRphMDLec6Zr3rZaDP+H/0cJvHXi3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5qzA-0000CW-T6; Wed, 03 May 2017 09:54:16 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5qz6-0000AP-W4; Wed, 03 May 2017 09:54:15 +0000 Received: from debian01.hofrr.at (92-243-34-74.adsl.nanet.at [92.243.34.74] (may be forged)) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id v439rCwf025821; Wed, 3 May 2017 11:53:12 +0200 From: Nicholas Mc Guire To: Cyrille Pitchen Subject: [RFC PATCH] mtd: spi-nor: handle signal case as failure Date: Wed, 3 May 2017 11:53:09 +0200 Message-Id: <1493805189-25327-1-git-send-email-der.herr@hofr.at> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170503_025413_369923_0255847E X-CRM114-Status: GOOD ( 12.30 ) 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: Boris Brezillon , Alexandre Torgue , Richard Weinberger , linux-kernel@vger.kernel.org, Marek Vasut , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Nicholas Mc Guire , Brian Norris , David Woodhouse , Ludovic Barre 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 The problem is that stm32_qspi_wait_cmd() will indicate success in case of being interrupted. The if condition is incomplete here as wait_for_copletion_interruptible_timeout can return -ERESTARTSYS but this is not handled by if(!wait_for_completion_interruptible_timeout()). While somewhat unlikely it probably would be hard to figure out what went wrong if the signal case does occur. Fixes: commit 0d43d7ab277a ("mtd: spi-nor: add driver for STM32 quad spi flash controller") Signed-off-by: Nicholas Mc Guire --- Problem found by experimental coccinelle script Its not clear if its sufficient to simply treat this case as failure or if it might need some debug output to allow differentiation of signal and timeout case. Patch was compile tested with: stm32_defconfig +CONFIG_MTD=y, CONFIG_MTD_SPI_NOR=y, CONFIG_SPI_STM32_QUADSPI=m Patch is against v4.11-rc8 (localversion-next is next-20170503) drivers/mtd/spi-nor/stm32-quadspi.c | 10 ++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/stm32-quadspi.c b/drivers/mtd/spi-nor/stm32-quadspi.c index 1056e74..27147ad 100644 --- a/drivers/mtd/spi-nor/stm32-quadspi.c +++ b/drivers/mtd/spi-nor/stm32-quadspi.c @@ -159,6 +159,7 @@ static int stm32_qspi_wait_cmd(struct stm32_qspi *qspi) { u32 cr; int err = 0; + long timeout = 0; if (readl_relaxed(qspi->io_base + QUADSPI_SR) & SR_TCF) return 0; @@ -167,8 +168,13 @@ static int stm32_qspi_wait_cmd(struct stm32_qspi *qspi) cr = readl_relaxed(qspi->io_base + QUADSPI_CR); writel_relaxed(cr | CR_TCIE, qspi->io_base + QUADSPI_CR); - if (!wait_for_completion_interruptible_timeout(&qspi->cmd_completion, - msecs_to_jiffies(1000))) + timeout = wait_for_completion_interruptible_timeout( + &qspi->cmd_completion, msecs_to_jiffies(1000)); + + /* since the calling side only cares about success of failure + * returning -ETIMEDOUT even when interrupted should be ok here + */ + if (timeout == 0 || timeout == -ERESTARTSYS) err = -ETIMEDOUT; writel_relaxed(cr, qspi->io_base + QUADSPI_CR);