[PATCH 2/4] spi: dw: use "smp_mb()" to avoid sending spi data error

Ike Panhc ike.pan at canonical.com
Tue Mar 10 08:01:13 UTC 2020

From: Xinwei Kong <kong.kongxinwei at hisilicon.com>

BugLink: https://launchpad.net/bugs/1859744

Because of out-of-order execution about some CPU architecture,
In this debug stage we find Completing spi interrupt enable ->
prodrucing TXEI interrupt -> running "interrupt_transfer" function
will prior to set "dw->rx and dws->rx_end" data, so this patch add
memory barrier to enable dw->rx and dw->rx_end to be visible and
solve to send SPI data error.
it will fix to this following low possibility error in testing environment
which using SPI control to connect TPM Modules

kernel: tpm tpm0: Operation Timed out
kernel: tpm tpm0: tpm_relinquish_locality: : error -1

Signed-off-by: fengsheng <fengsheng5 at huawei.com>
Signed-off-by: Xinwei Kong <kong.kongxinwei at hisilicon.com>
Link: https://lore.kernel.org/r/1578019930-55858-1-git-send-email-kong.kongxinwei@hisilicon.com
Signed-off-by: Mark Brown <broonie at kernel.org>
(cherry picked from commit bfda044533b213985bc62bd7ca96f2b984d21b80)
Signed-off-by: Ike Panhc <ike.pan at canonical.com>
 drivers/spi/spi-dw.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 45972056ed8c..36e02f2f25c5 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -289,6 +289,9 @@ static int dw_spi_transfer_one(struct spi_controller *master,
 	dws->rx_end = dws->rx + transfer->len;
 	dws->len = transfer->len;
+	/* Ensure dw->rx and dw->rx_end are visible */
+	smp_mb();
 	spi_enable_chip(dws, 0);
 	/* Handle per transfer options for bpw and speed */

More information about the kernel-team mailing list