[PATCH v3 2/9] net: cs8900: do not read past the receive buffer

Sascha Hauer s.hauer at pengutronix.de
Tue May 28 01:57:59 PDT 2024


the hardware may report a packet longer than our receive buffer. Instead
of reading past the read buffer, discard too long packets.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/cs8900.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c
index afb0f3e26e..bce26d4def 100644
--- a/drivers/net/cs8900.c
+++ b/drivers/net/cs8900.c
@@ -295,10 +295,14 @@ static int cs8900_recv(struct eth_device *dev)
 	status = readw(priv->regs + CS8900_RTDATA0);
 	len = readw(priv->regs + CS8900_RTDATA0);
 
-	for (addr = (u16 *)priv->rx_buf, i = (len + 1) >> 1; i > 0; i--)
-		*addr++ = readw(priv->regs + CS8900_RTDATA0);
-
-	net_receive(dev, priv->rx_buf, len);
+	if (len <= PKTSIZE) {
+		for (addr = (u16 *)priv->rx_buf, i = (len + 1) >> 1; i > 0; i--)
+			*addr++ = readw(priv->regs + CS8900_RTDATA0);
+		net_receive(dev, priv->rx_buf, len);
+	} else {
+		for (addr = (u16 *)priv->rx_buf, i = (len + 1) >> 1; i > 0; i--)
+			(void)readw(priv->regs + CS8900_RTDATA0);
+	}
 
 	return len;
 }
-- 
2.39.2




More information about the barebox mailing list