From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id A94FC5A026B; Thu, 16 Feb 2023 02:08:19 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta() Date: Thu, 16 Feb 2023 02:08:19 +0100 Message-Id: <20230216010819.2224243-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EVS2BGL5TW4A7MZ7YJ725QF6PB6PRX65 X-Message-ID-Hash: EVS2BGL5TW4A7MZ7YJ725QF6PB6PRX65 X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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--; } } } -- 2.35.1