* [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta()
@ 2023-02-16 1:08 Stefano Brivio
2023-02-16 3:47 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2023-02-16 1:08 UTC (permalink / raw)
To: passt-dev; +Cc: David Gibson
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta()
2023-02-16 1:08 [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta() Stefano Brivio
@ 2023-02-16 3:47 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2023-02-16 3:47 UTC (permalink / raw)
To: Stefano Brivio; +Cc: passt-dev
[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]
On Thu, Feb 16, 2023 at 02:08:19AM +0100, Stefano Brivio wrote:
> 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>
> ---
> 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--;
> }
> }
> }
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-16 5:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16 1:08 [PATCH] tap: Use single counter for iov elements in tap_send_frames_pasta() Stefano Brivio
2023-02-16 3:47 ` David Gibson
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).