tap: Use single counter for iov elements in tap_send_frames_pasta()

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>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2023-02-16 01:36:17 +01:00
parent 3d0de2c1d7
commit 7564b58a7f

6
tap.c
View file

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