From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBA62881E; Tue, 8 Jul 2025 16:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751992283; cv=none; b=ZEOFOaECPcLlZDaY9JHUOhNPPnWOlqAFCwLWc3/wVy2mnwOiwbxbEAQCUo5WDwxq2YDbfNNswXFesAOxfI5xfuaMWueAEdRPmMttdUbJBCgkrLffTpYCReDRHbwVyxdPFYfXaBWgXlqCY6ueeWOnv+XV+lcQ42/FtFLfJaliKC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751992283; c=relaxed/simple; bh=Tu3r8+YMhuvRxIbn/DaNn/AfCQVqXHnfvTjfCOVMoJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=We/YyyWHN2JvbN/2nN0jmkrj8w0KovGYl/dxzS2jjAtlq/90M7dkOpgfq63co7fcZvdj+fkmXzxXFL5rebhKWopBSMVwkHMy7PbBoI7AgBTnIcA3Lh9S6IEpms58jmws5jzoYZqKE83pR5yjvX/NVa1Oa899l7zWaEyJg60NCZI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AMRGdwWu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="AMRGdwWu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45607C4CEED; Tue, 8 Jul 2025 16:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1751992283; bh=Tu3r8+YMhuvRxIbn/DaNn/AfCQVqXHnfvTjfCOVMoJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMRGdwWuWuoSJNtrdgFMm+P9Rzh39ScnvtnSG9/CcAIoAX9tow4hiMbt0s0qZZGN/ u6dVhK2wrVqx6ZKs0ZU7Oe3OQMO/ju4lszoa6gFvCI1z4U3rlnUh1OFCxsBKnz3yP/ h6B70+mxWRAsupcWXcEyLloMCpH05mSKCOUrAqXM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, James Clark , Frank Li , Mark Brown , Sasha Levin Subject: [PATCH 6.6 039/132] spi: spi-fsl-dspi: Clear completion counter before initiating transfer Date: Tue, 8 Jul 2025 18:22:30 +0200 Message-ID: <20250708162231.830575124@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250708162230.765762963@linuxfoundation.org> References: <20250708162230.765762963@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Clark [ Upstream commit fa60c094c19b97e103d653f528f8d9c178b6a5f5 ] In target mode, extra interrupts can be received between the end of a transfer and halting the module if the host continues sending more data. If the interrupt from this occurs after the reinit_completion() then the completion counter is left at a non-zero value. The next unrelated transfer initiated by userspace will then complete immediately without waiting for the interrupt or writing to the RX buffer. Fix it by resetting the counter before the transfer so that lingering values are cleared. This is done after clearing the FIFOs and the status register but before the transfer is initiated, so no interrupts should be received at this point resulting in other race conditions. Fixes: 4f5ee75ea171 ("spi: spi-fsl-dspi: Replace interruptible wait queue with a simple completion") Signed-off-by: James Clark Reviewed-by: Frank Li Link: https://patch.msgid.link/20250627-james-nxp-spi-dma-v4-1-178dba20c120@linaro.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-fsl-dspi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 7dd94369abb47..3206c84c6f22f 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -988,11 +988,20 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr, if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) { status = dspi_dma_xfer(dspi); } else { + /* + * Reinitialize the completion before transferring data + * to avoid the case where it might remain in the done + * state due to a spurious interrupt from a previous + * transfer. This could falsely signal that the current + * transfer has completed. + */ + if (dspi->irq) + reinit_completion(&dspi->xfer_done); + dspi_fifo_write(dspi); if (dspi->irq) { wait_for_completion(&dspi->xfer_done); - reinit_completion(&dspi->xfer_done); } else { do { status = dspi_poll(dspi); -- 2.39.5