From patchwork Tue Sep 24 13:40:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 13810982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4CC7CF9C6F for ; Tue, 24 Sep 2024 13:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RIEd/+3RUZ5FAc5/2lhcwWi5vz2ND8NO2C1zeGC37t8=; b=ksaNYr9w/MsZ+/9jzONo2nrwc1 E9qndN0aQRm45em7FN/wM+3u1duSI7zENrDXhoYrsFZyCt0cTRxp+vbmGkNeTQRX4HtU31CthdzFs +nR1hT26HEzsO8xXD1DGtEdKjj36kHf45Lt5cH541KBmnIZLPeQxVADLRYDaijlJ7oY2jQOQ0aIwN nXo7tkuiWTEW/lM/gLVdX96WgiyPg30x3NIpDlhSaY37ZDLCDVzm6Zsc8O12NTdtaZLwayGd4+/L/ cehhO8THrxZvVXS+ooMa/doHWexbjLXXXXWhhPRHcS5zNW/5ZnhY7jK4k2PlQgLj8JRtCsyxBaH7N uYO1QPFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1st5nB-00000002SVR-2num; Tue, 24 Sep 2024 13:41:25 +0000 Received: from imap5.colo.codethink.co.uk ([78.40.148.171]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1st5m3-00000002SQM-3Ipw for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 13:40:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codethink.co.uk; s=imap5-20230908; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RIEd/+3RUZ5FAc5/2lhcwWi5vz2ND8NO2C1zeGC37t8=; b=dscdQn5nW9VwStRMkAIgbD6ASW IRHhJctdQbv3K2aATWWIubCJ8QfPJFQDRrkM6dxmkYiaH1bZ3C/t81hZAaxx12FcLGJjERkNnArLZ k3PiciPhsX8UjxrRfocFnl+JfPk1NGbmYdafgSqi/nFAyc0thIzXFGabw/cwaAeVDdI6lu5bXhtDJ LrDCj6ctnnbVUIluPTRciUq/GZ50iAAhOQtNFFbrJFO9T9N+GQgrDqdjQCIW3UnJdnZOKVmiMCp7N 1k0r5hVYgmi1plBFhKXbpnefAjDYLEm42an9dzQi9ZXZ5Tpi6oQ+Xi/fH9CxZztpebqJS5VDyC2N+ ZHsmXAfA==; Received: from [63.135.74.212] (helo=rainbowdash) by imap5.colo.codethink.co.uk with esmtpsa (Exim 4.94.2 #2 (Debian)) id 1st5ly-003YDw-Tj; Tue, 24 Sep 2024 14:40:11 +0100 Received: from ben by rainbowdash with local (Exim 4.98) (envelope-from ) id 1st5ly-00000000UFR-3j6O; Tue, 24 Sep 2024 14:40:10 +0100 From: Ben Dooks To: linux-spi@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alim Akhtar , Krzysztof Kozlowski , Andi Shyti , Mark Brown , Ben Dooks Subject: [PATCH 1/2] spi: s3c64xx: fix timeout counters in flush_fifo Date: Tue, 24 Sep 2024 14:40:08 +0100 Message-Id: <20240924134009.116247-2-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.37.2.352.g3c44437643 In-Reply-To: <20240924134009.116247-1-ben.dooks@codethink.co.uk> References: <20240924134009.116247-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240924_064015_932268_04DAE9F3 X-CRM114-Status: GOOD ( 13.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the s3c64xx_flush_fifo() code, the loops counter is post-decremented in the do { } while(test && loops--) condition. This means the loops is left at the unsigned equivalent of -1 if the loop times out. The test after will never pass as if tests for loops == 0. Signed-off-by: Ben Dooks Reviewed-by: Andi Shyti --- drivers/spi/spi-s3c64xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 833c58c88e40..6ab416a33966 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -245,7 +245,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) loops = msecs_to_loops(1); do { val = readl(regs + S3C64XX_SPI_STATUS); - } while (TX_FIFO_LVL(val, sdd) && loops--); + } while (TX_FIFO_LVL(val, sdd) && --loops); if (loops == 0) dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO\n"); @@ -258,7 +258,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) readl(regs + S3C64XX_SPI_RX_DATA); else break; - } while (loops--); + } while (--loops); if (loops == 0) dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO\n"); From patchwork Tue Sep 24 13:40:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 13810983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C74F3CF9C6F for ; Tue, 24 Sep 2024 13:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=x8vVJjhSJf8ntKWMHQeF38IG4mIwV3gbUUfBMyXl/pI=; b=aRXK/mRazG1tshoXUiE6l6M3UN AIj0rO2WrEQwKq5HXFws7s+JK0W7fm73wyRlEST5i0CXltrjJypcyES5XBH3cE8d8E0u3fMZHzKqB wRghmknotGBT1Ryx0tZjnW+WWig96nNAQ0LwQzYkDh0tt2gM42jFhEL73cCpiM2jLcSN/KgxiwntG T9d3+CE3u72gw2ITxdMkvHtqXgfTOPF4lqTVRhiYH7CmN/v2+iCFSQpTHSrsCtyKGOe/gj9Sz7q2d 3qK/mZpd1mMC4gUWF46AJe3U2Xe/E+eNKNRjGm5coEEss3G9kvnIpH8bzzQxL/ggYGMdwf8ViMcGs LOjz1GdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1st5pN-00000002SpM-3PXs; Tue, 24 Sep 2024 13:43:41 +0000 Received: from imap4.hz.codethink.co.uk ([188.40.203.114]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1st5m5-00000002SQV-0QZG for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 13:40:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codethink.co.uk; s=imap4-20230908; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=x8vVJjhSJf8ntKWMHQeF38IG4mIwV3gbUUfBMyXl/pI=; b=tHbXMtq9ZXYeL0mc3IEogvuEFI M4oX9PTvyYhYU6vehYpoAMG5gCefE3LP/hUVcY66ac2gX7dSvmpO6UO0/iaK6ZZwCBYWNDz+DHzKp poFEPArAYPnDCosgO86Urq0EZkNq1RphsIoZSh48flJJXNW4GARYUareKZxL5HGQZwa3/ymeD1QIK GvAXpX4xJgw7w5YMLi2F/0o0WRvKyGp97Pvsv25TTmx7vqpvtWJLkor7lXTLC/kPDVLMV8Yu9wpxv FBiZuTJiaOg2fQX4VioRQwdPfvtrliaLOBctDpCHu2OJevgsrqIiZSV5eF3/G3tCJUPgbrZWWKVG4 7s01OWJA==; Received: from [63.135.74.212] (helo=rainbowdash) by imap4.hz.codethink.co.uk with esmtpsa (Exim 4.94.2 #2 (Debian)) id 1st5ly-002wbh-PE; Tue, 24 Sep 2024 14:40:11 +0100 Received: from ben by rainbowdash with local (Exim 4.98) (envelope-from ) id 1st5ly-00000000UFV-3uFk; Tue, 24 Sep 2024 14:40:10 +0100 From: Ben Dooks To: linux-spi@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alim Akhtar , Krzysztof Kozlowski , Andi Shyti , Mark Brown , Ben Dooks Subject: [PATCH 2/2] spi: s3c64xx: update flush_fifo timeout code Date: Tue, 24 Sep 2024 14:40:09 +0100 Message-Id: <20240924134009.116247-3-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.37.2.352.g3c44437643 In-Reply-To: <20240924134009.116247-1-ben.dooks@codethink.co.uk> References: <20240924134009.116247-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240924_064017_162523_76107AD2 X-CRM114-Status: GOOD ( 14.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The code that checks for loops in the s3c6xx_flush_fifo() checks for loops being non-zero as a timeout, however the code /could/ finish with loops being zero and the fifo being flushed... Also, it would be useful to know what is left in the fifo for this error case, so update the checks to see what is left, and then also print the number of entries. Signed-off-by: Ben Dooks --- drivers/spi/spi-s3c64xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 6ab416a33966..7b244e1fd58a 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -247,8 +247,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) val = readl(regs + S3C64XX_SPI_STATUS); } while (TX_FIFO_LVL(val, sdd) && --loops); - if (loops == 0) - dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO\n"); + if (TX_FIFO_LVL(val, sdd)) + dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO (%d left)\n", TX_FIFO_LVL(val, sdd)); /* Flush RxFIFO*/ loops = msecs_to_loops(1); @@ -260,8 +260,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) break; } while (--loops); - if (loops == 0) - dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO\n"); + if (RX_FIFO_LVL(val, sdd)) + dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO (%d left)\n", RX_FIFO_LVL(val, sdd)); val = readl(regs + S3C64XX_SPI_CH_CFG); val &= ~S3C64XX_SPI_CH_SW_RST;