Skip to contentSkip to conversation

vhost-user-bridge: fix iov_restore_front() warning

PATCH In review Marc-André Lureau 5 participants 5 messages Jun 2, 2017 – Jun 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-user-bridge: fix iov_restore_front() warning

CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]

    for (cur = front; front != iov; cur++) {
                      ^~~~~    ~~~

1 warning generated.

Fix the loop, document the function, and fix some related assert().

In practice, the loop bug was harmless because the front sg buffer is enough to discard/restore the header size.

---
 tests/vhost-user-bridge.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +9 -2
index 8618c20d53..1e5b5ca3da 100644
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
     free(elem);
 }
 
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off
+ */
 static void
 iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
 {
     struct iovec *cur;
 
-    for (cur = front; front != iov; cur++) {
+    for (cur = front; cur != iov; cur++) {
+        assert(bytes >= cur->iov_len);
         bytes -= cur->iov_len;
     }
 
@@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
             }
             iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
             total += hdrlen;
-            assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
+            ret = iov_discard_front(&sg, &num, hdrlen);
+            assert(ret == hdrlen);
         }
 
         struct msghdr msg = {
Signature · 1 line
2.13.0.91.g00982b8dd
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · * Marc-André Lureau ([email protected]) wrote:

CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]

    for (cur = front; front != iov; cur++) {
                      ^~~~~    ~~~

1 warning generated.

Quoted 7 lines

Fix the loop, document the function, and fix some related assert().

In practice, the loop bug was harmless because the front sg buffer is enough to discard/restore the header size.

Quoted 41 lines
---
 tests/vhost-user-bridge.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +9 -2
index 8618c20d53..1e5b5ca3da 100644
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
     free(elem);
 }
 
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off
+ */
 static void
 iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
 {
     struct iovec *cur;
 
-    for (cur = front; front != iov; cur++) {
+    for (cur = front; cur != iov; cur++) {
+        assert(bytes >= cur->iov_len);
         bytes -= cur->iov_len;
     }
 
@@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
             }
             iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
             total += hdrlen;
-            assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
+            ret = iov_discard_front(&sg, &num, hdrlen);
+            assert(ret == hdrlen);
         }
 
         struct msghdr msg = {
Signature · 1 line
2.13.0.91.g00982b8dd

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Tested-by on v1 1/1
#2 lore raw
In reply to Marc-André Lureau
Quoted 29 lines · Marc-André Lureau

CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning: variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]

    for (cur = front; front != iov; cur++) {
                      ^~~~~    ~~~

1 warning generated.

Fix the loop, document the function, and fix some related assert().

In practice, the loop bug was harmless because the front sg buffer is enough to discard/restore the header size.

---
 tests/vhost-user-bridge.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +4 -0
index 8618c20d53..1e5b5ca3da 100644
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
     free(elem);
 }
 
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off

tests/vhost-user-bridge.c vubr_handle_tx(VuDev *dev, int qidx) · line 235

Quoted 10 lines
tests/vhost-user-bridge.c +3 -1
+ */
 static void
 iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
 {
     struct iovec *cur;
 
-    for (cur = front; front != iov; cur++) {
+    for (cur = front; cur != iov; cur++) {
+        assert(bytes >= cur->iov_len);
         bytes -= cur->iov_len;

This fixes a problem I saw when trying to pxe-boot
with vhost-user and vhost-user-bridge. It was running in an endless loop here. Fixed with this patch.

regards,
Jens

#3 lore raw
In reply to Marc-André Lureau

Hi, Michael, could you pick this patch?

thanks

Quoted 57 lines · Marc-André Lureau

CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning:
variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]

    for (cur = front; front != iov; cur++) {
                      ^~~~~    ~~~

1 warning generated.

Fix the loop, document the function, and fix some related assert().

In practice, the loop bug was harmless because the front sg buffer is enough to discard/restore the header size.

---
 tests/vhost-user-bridge.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +9 -3
index 8618c20d53..1e5b5ca3da 100644
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
     free(elem);
 }
 
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off
+ */
 static void
 iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
 {
     struct iovec *cur;
 
-    for (cur = front; front != iov; cur++) {
+    for (cur = front; cur != iov; cur++) {
+        assert(bytes >= cur->iov_len);
         bytes -= cur->iov_len;
     }
 
@@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
             }
             iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
             total += hdrlen;
-            assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
+            ret = iov_discard_front(&sg, &num, hdrlen);
+            assert(ret == hdrlen);
         }
 
         struct msghdr msg = {
--

2.13.0.91.g00982b8dd

Quoted 1 line

--

Marc-André Lureau

#4 lore raw
Quoted 3 lines · Marc-André Lureau

Hi, Michael, could you pick this patch?

thanks

OK. Pls cc me on patches you want me to review.

Quoted 62 lines
Quoted 57 lines · Marc-André Lureau

CC tests/vhost-user-bridge.o
/home/dgilbert/git/qemu-world3/tests/vhost-user-bridge.c:228:23: warning:
variables 'front' and 'iov' used in loop condition not modified in loop body [-Wfor-loop-analysis]

    for (cur = front; front != iov; cur++) {
                      ^~~~~    ~~~

1 warning generated.

Fix the loop, document the function, and fix some related assert().

In practice, the loop bug was harmless because the front sg buffer is enough to discard/restore the header size.

---
 tests/vhost-user-bridge.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +9 -3
index 8618c20d53..1e5b5ca3da 100644
@@ -220,12 +220,18 @@ vubr_handle_tx(VuDev *dev, int qidx)
     free(elem);
 }
 
+
+/* this function reverse the effect of iov_discard_front() it must be
+ * called with 'front' being the original struct iovec and 'bytes'
+ * being the number of bytes you shaved off
+ */
 static void
 iov_restore_front(struct iovec *front, struct iovec *iov, size_t bytes)
 {
     struct iovec *cur;
 
-    for (cur = front; front != iov; cur++) {
+    for (cur = front; cur != iov; cur++) {
+        assert(bytes >= cur->iov_len);
         bytes -= cur->iov_len;
     }
 
@@ -302,7 +308,8 @@ vubr_backend_recv_cb(int sock, void *ctx)
             }
             iov_from_buf(sg, elem->in_num, 0, &hdr, sizeof hdr);
             total += hdrlen;
-            assert(iov_discard_front(&sg, &num, hdrlen) == hdrlen);
+            ret = iov_discard_front(&sg, &num, hdrlen);
+            assert(ret == hdrlen);
         }
 
         struct msghdr msg = {
--

2.13.0.91.g00982b8dd

Quoted 1 line

--

Marc-André Lureau