public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta()
Date: Thu, 16 Feb 2023 02:08:19 +0100	[thread overview]
Message-ID: <20230216010819.2224243-1-sbrivio@redhat.com> (raw)

David points out that using multiple counters to go over the iov
array, namely 'i' and 'iov', makes mistakes easier. We can't just use
'iov', unless we reserve an element with zero iov_len at the end,
which isn't really justified.

Simply use 'i' to iterate over the array.

Link: https://archives.passt.top/passt-dev/Y+mfenvLn3VJ7Dg5@yekko/
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tap.c b/tap.c
index 02da84d..e4c5b5b 100644
--- a/tap.c
+++ b/tap.c
@@ -316,13 +316,13 @@ static void tap_send_frames_pasta(struct ctx *c,
 {
 	size_t i;
 
-	for (i = 0; i < n; i++, iov++) {
-		if (write(c->fd_tap, (char *)iov->iov_base, iov->iov_len) < 0) {
+	for (i = 0; i < n; i++) {
+		if (write(c->fd_tap, (char *)iov[i].iov_base,
+			  iov[i].iov_len) < 0) {
 			debug("tap write: %s", strerror(errno));
 			if (errno != EAGAIN && errno != EWOULDBLOCK)
 				tap_handler(c, c->fd_tap, EPOLLERR, NULL);
 			i--;
-			iov--;
 		}
 	}
 }
-- 
@@ -316,13 +316,13 @@ static void tap_send_frames_pasta(struct ctx *c,
 {
 	size_t i;
 
-	for (i = 0; i < n; i++, iov++) {
-		if (write(c->fd_tap, (char *)iov->iov_base, iov->iov_len) < 0) {
+	for (i = 0; i < n; i++) {
+		if (write(c->fd_tap, (char *)iov[i].iov_base,
+			  iov[i].iov_len) < 0) {
 			debug("tap write: %s", strerror(errno));
 			if (errno != EAGAIN && errno != EWOULDBLOCK)
 				tap_handler(c, c->fd_tap, EPOLLERR, NULL);
 			i--;
-			iov--;
 		}
 	}
 }
-- 
2.35.1


             reply	other threads:[~2023-02-16  1:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16  1:08 Stefano Brivio [this message]
2023-02-16  3:47 ` [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta() David Gibson

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=20230216010819.2224243-1-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).