Skip to content

Commit dcb8188

Browse files
Donny9xiaoxiang781216
authored andcommitted
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 <dongjiuzhu1@xiaomi.com>
1 parent ade23b9 commit dcb8188

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/spi/spi_slave_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
326326
return ret;
327327
}
328328

329-
do
329+
while (priv->rx_length == 0)
330330
{
331331
remaining_words = SPIS_CTRLR_QPOLL(priv->ctrlr);
332332
if (remaining_words == 0)
@@ -360,11 +360,11 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
360360
}
361361
}
362362
}
363-
while (priv->rx_length == 0);
364363

365364
read_bytes = MIN(buflen, priv->rx_length);
366365

367366
memcpy(buffer, priv->rx_buffer, read_bytes);
367+
priv->rx_length -= read_bytes;
368368

369369
nxmutex_unlock(&priv->lock);
370370
return (ssize_t)read_bytes;

0 commit comments

Comments
 (0)