Commit 9f201a87 authored by Max Filippov's avatar Max Filippov Committed by John W. Linville

p54spi: compensate firmware alignment bug in p54spi_rx

Firmware may insert up to 4 padding bytes after the lmac header,
but it does not amend the size of SPI data transfer.
Such packets has correct data size in header, thus referencing
past the end of allocated skb. Put extra 4 bytes to the end of the
received skb to compensate for this case.
Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
Acked-by: default avatarChristian Lamparter <chunkeey@web.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 488829f1
...@@ -395,7 +395,12 @@ static int p54spi_rx(struct p54s_priv *priv) ...@@ -395,7 +395,12 @@ static int p54spi_rx(struct p54s_priv *priv)
return 0; return 0;
} }
skb = dev_alloc_skb(len);
/* Firmware may insert up to 4 padding bytes after the lmac header,
* but it does not amend the size of SPI data transfer.
* Such packets has correct data size in header, thus referencing
* past the end of allocated skb. Reserve extra 4 bytes for this case */
skb = dev_alloc_skb(len + 4);
if (!skb) { if (!skb) {
dev_err(&priv->spi->dev, "could not alloc skb"); dev_err(&priv->spi->dev, "could not alloc skb");
return 0; return 0;
...@@ -403,6 +408,9 @@ static int p54spi_rx(struct p54s_priv *priv) ...@@ -403,6 +408,9 @@ static int p54spi_rx(struct p54s_priv *priv)
p54spi_spi_read(priv, SPI_ADRS_DMA_DATA, skb_put(skb, len), len); p54spi_spi_read(priv, SPI_ADRS_DMA_DATA, skb_put(skb, len), len);
p54spi_sleep(priv); p54spi_sleep(priv);
/* Put additional bytes to compensate for the possible
* alignment-caused truncation */
skb_put(skb, 4);
if (p54_rx(priv->hw, skb) == 0) if (p54_rx(priv->hw, skb) == 0)
dev_kfree_skb(skb); dev_kfree_skb(skb);
......
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