You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/24 02:35:01 UTC
[nuttx] branch master updated: driver/spi: avoid calling QPOLL to change rx_length and cause data loss
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new dcb8188f07 driver/spi: avoid calling QPOLL to change rx_length and cause data loss
dcb8188f07 is described below
commit dcb8188f07fce41879d4cf8c9a666ad7c3c867f3
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Sep 5 19:20:46 2023 +0800
driver/spi: avoid calling QPOLL to change rx_length and cause data loss
When the application calls poll and returns the POLLIN event,
QPOLL will be called again during the read operation,
causing rx_length to change and data to be lost.
Therefore, read only need to actively call qpoll to collect driver
data when rx length is 0.
Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
drivers/spi/spi_slave_driver.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi_slave_driver.c b/drivers/spi/spi_slave_driver.c
index ccc8f0dd3a..56ec300730 100644
--- a/drivers/spi/spi_slave_driver.c
+++ b/drivers/spi/spi_slave_driver.c
@@ -326,7 +326,7 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
return ret;
}
- do
+ while (priv->rx_length == 0)
{
remaining_words = SPIS_CTRLR_QPOLL(priv->ctrlr);
if (remaining_words == 0)
@@ -360,11 +360,11 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
}
}
}
- while (priv->rx_length == 0);
read_bytes = MIN(buflen, priv->rx_length);
memcpy(buffer, priv->rx_buffer, read_bytes);
+ priv->rx_length -= read_bytes;
nxmutex_unlock(&priv->lock);
return (ssize_t)read_bytes;