Commit a2cb1be1 authored by Valentin Longchamp's avatar Valentin Longchamp Committed by Mark Brown

spi/fsl-espi: fix rx_buf in fsl_espi_cmd_trans()/fsl_espi_rw_trans()

By default for every espi transfer, the rx_buf is placed right after the
tx_buf. This can lead to a buffer overflow when the size of both the TX
and RX data cumulated is higher than the allocated 64K buffer for the
transfer (this is the case when sending for instance a read command and
reading 64K back, please see:
http://article.gmane.org/gmane.linux.drivers.mtd/53411 )

This gets fixed by always setting the RX buffer pointer at the begining
of the transfer buffer.

[The driver shouldn't be doing the copy in the first place and instead
sending directly from the supplied buffer but this is at least not worse
than what's there -- broonie]
Signed-off-by: default avatarValentin Longchamp <valentin.longchamp@keymile.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent d0fb47a5
...@@ -348,7 +348,7 @@ static void fsl_espi_cmd_trans(struct spi_message *m, ...@@ -348,7 +348,7 @@ static void fsl_espi_cmd_trans(struct spi_message *m,
} }
espi_trans->tx_buf = local_buf; espi_trans->tx_buf = local_buf;
espi_trans->rx_buf = local_buf + espi_trans->n_tx; espi_trans->rx_buf = local_buf;
fsl_espi_do_trans(m, espi_trans); fsl_espi_do_trans(m, espi_trans);
espi_trans->actual_length = espi_trans->len; espi_trans->actual_length = espi_trans->len;
...@@ -397,7 +397,7 @@ static void fsl_espi_rw_trans(struct spi_message *m, ...@@ -397,7 +397,7 @@ static void fsl_espi_rw_trans(struct spi_message *m,
espi_trans->n_rx = trans_len; espi_trans->n_rx = trans_len;
espi_trans->len = trans_len + n_tx; espi_trans->len = trans_len + n_tx;
espi_trans->tx_buf = local_buf; espi_trans->tx_buf = local_buf;
espi_trans->rx_buf = local_buf + n_tx; espi_trans->rx_buf = local_buf;
fsl_espi_do_trans(m, espi_trans); fsl_espi_do_trans(m, espi_trans);
memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len); memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment