mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	spi: spi-fsl-dspi: Avoid reading more data than written in EOQ mode
If dspi->words_in_flight is populated with the hardware FIFO size,
then in dspi_fifo_read it will attempt to read more data at the end of a
buffer that is not a multiple of 16 bytes in length. It will probably
time out attempting to do so.
So limit the num_fifo_entries variable to the actual number of FIFO
entries that is going to be used.
Fixes: d59c90a240 ("spi: spi-fsl-dspi: Convert TCFQ users to XSPI FIFO mode")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20200318001603.9650-5-olteanv@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									a957499bd4
								
							
						
					
					
						commit
						c6c1e30a78
					
				
					 1 changed files with 5 additions and 2 deletions
				
			
		| 
						 | 
					@ -739,13 +739,16 @@ static void dspi_eoq_fifo_write(struct fsl_dspi *dspi)
 | 
				
			||||||
	int num_fifo_entries = dspi->devtype_data->fifo_size;
 | 
						int num_fifo_entries = dspi->devtype_data->fifo_size;
 | 
				
			||||||
	u16 xfer_cmd = dspi->tx_cmd;
 | 
						u16 xfer_cmd = dspi->tx_cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (num_fifo_entries * dspi->oper_word_size > dspi->len)
 | 
				
			||||||
 | 
							num_fifo_entries = dspi->len / dspi->oper_word_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dspi->words_in_flight = num_fifo_entries;
 | 
						dspi->words_in_flight = num_fifo_entries;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Fill TX FIFO with as many transfers as possible */
 | 
						/* Fill TX FIFO with as many transfers as possible */
 | 
				
			||||||
	while (dspi->len && num_fifo_entries--) {
 | 
						while (num_fifo_entries--) {
 | 
				
			||||||
		dspi->tx_cmd = xfer_cmd;
 | 
							dspi->tx_cmd = xfer_cmd;
 | 
				
			||||||
		/* Request EOQF for last transfer in FIFO */
 | 
							/* Request EOQF for last transfer in FIFO */
 | 
				
			||||||
		if (dspi->len == dspi->oper_word_size || num_fifo_entries == 0)
 | 
							if (num_fifo_entries == 0)
 | 
				
			||||||
			dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ;
 | 
								dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ;
 | 
				
			||||||
		/* Write combined TX FIFO and CMD FIFO entry */
 | 
							/* Write combined TX FIFO and CMD FIFO entry */
 | 
				
			||||||
		dspi_pushr_write(dspi);
 | 
							dspi_pushr_write(dspi);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue