mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: jianqiang wang <wjq.sec@gmail.com>
Subject: [PATCH v2 1/7] net: cs8900: simplify buffer read loop
Date: Mon, 27 May 2024 12:27:17 +0200	[thread overview]
Message-ID: <20240527102723.3504270-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240527102723.3504270-1-s.hauer@pengutronix.de>

Instead of doing an extra read after the buffer read loop when the
packet length is odd, add another iteration to the loop if necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/cs8900.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c
index 0dfd3f1303..afb0f3e26e 100644
--- a/drivers/net/cs8900.c
+++ b/drivers/net/cs8900.c
@@ -295,12 +295,9 @@ 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; i > 0; i--) {
+	for (addr = (u16 *)priv->rx_buf, i = (len + 1) >> 1; i > 0; i--)
 		*addr++ = readw(priv->regs + CS8900_RTDATA0);
-	}
-	if (len & 1) {
-		*addr++ = readw(priv->regs + CS8900_RTDATA0);
-	}
+
 	net_receive(dev, priv->rx_buf, len);
 
 	return len;
-- 
2.39.2




  reply	other threads:[~2024-05-27 10:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 10:27 [PATCH v2 0/7] net: do not read past receive buffer Sascha Hauer
2024-05-27 10:27 ` Sascha Hauer [this message]
2024-05-27 10:27 ` [PATCH v2 2/7] net: cs8900: do not read past the " Sascha Hauer
2024-05-27 10:27 ` [PATCH v2 3/7] net: ks8851_mll: " Sascha Hauer
2024-05-27 10:27 ` [PATCH v2 4/7] net: liteeth: " Sascha Hauer
2024-05-27 12:29   ` Jules Maselbas
2024-05-27 10:27 ` [PATCH v2 5/7] net: smc911x: " Sascha Hauer
2024-05-27 12:27   ` Jules Maselbas
2024-05-27 10:27 ` [PATCH v2 6/7] net: ks8851_mll: drop return value from ks8851_rx_frame() Sascha Hauer
2024-05-27 10:27 ` [PATCH v2 7/7] net: let net rx hook return void Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240527102723.3504270-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=wjq.sec@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox