diff mbox series

[v3,10/26] vhost-user: split vhost_user_read()

Message ID 20180618161729.334-11-marcandre.lureau@redhat.com
State New
Headers show
Series vhost-user for input & GPU | expand

Commit Message

Marc-André Lureau June 18, 2018, 4:17 p.m. UTC
Split vhost_user_read(), so only header can be read with
vhost_user_read_header().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/virtio/vhost-user.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

Comments

Gerd Hoffmann June 19, 2018, 6:23 a.m. UTC | #1
> @@ -237,7 +251,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>          error_report("Failed to read msg header."
>                  " Size %d exceeds the maximum %zu.", msg->hdr.size,
>                  VHOST_USER_PAYLOAD_SIZE);
> -        goto fail;
> +        return -1;

Hmm?  Looks like a pointless indirection ...

>      }
>  
>      if (msg->hdr.size) {
> @@ -247,14 +261,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>          if (r != size) {
>              error_report("Failed to read msg payload."
>                           " Read %d instead of %d.", r, msg->hdr.size);
> -            goto fail;
> +            return -1;
>          }
>      }
>  
>      return 0;
> -
> -fail:
> -    return -1;

... if there is nothing to cleanup here.

cheers,
  Gerd
Marc-André Lureau June 19, 2018, 9:01 a.m. UTC | #2
Hi

On Tue, Jun 19, 2018 at 8:23 AM, Gerd Hoffmann <kraxel@redhat.com> wrote:
>> @@ -237,7 +251,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>>          error_report("Failed to read msg header."
>>                  " Size %d exceeds the maximum %zu.", msg->hdr.size,
>>                  VHOST_USER_PAYLOAD_SIZE);
>> -        goto fail;
>> +        return -1;
>
> Hmm?  Looks like a pointless indirection ...

Isn't it removed by the patch? :)

>
>>      }
>>
>>      if (msg->hdr.size) {
>> @@ -247,14 +261,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
>>          if (r != size) {
>>              error_report("Failed to read msg payload."
>>                           " Read %d instead of %d.", r, msg->hdr.size);
>> -            goto fail;
>> +            return -1;
>>          }
>>      }
>>
>>      return 0;
>> -
>> -fail:
>> -    return -1;
>
> ... if there is nothing to cleanup here.
>
> cheers,
>   Gerd
>
>
Gerd Hoffmann June 19, 2018, 11:20 a.m. UTC | #3
On Tue, Jun 19, 2018 at 11:01:00AM +0200, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Jun 19, 2018 at 8:23 AM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >> @@ -237,7 +251,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
> >>          error_report("Failed to read msg header."
> >>                  " Size %d exceeds the maximum %zu.", msg->hdr.size,
> >>                  VHOST_USER_PAYLOAD_SIZE);
> >> -        goto fail;
> >> +        return -1;
> >
> > Hmm?  Looks like a pointless indirection ...
> 
> Isn't it removed by the patch? :)

Ah, right.  Sorry about the noise.

cheers,
  Gerd
diff mbox series

Patch

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 5b4188bc27..29f8568a13 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -210,7 +210,7 @@  static bool ioeventfd_enabled(void)
     return kvm_enabled() && kvm_eventfds_enabled();
 }
 
-static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
+static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
 {
     struct vhost_user *u = dev->opaque;
     CharBackend *chr = u->user->chr;
@@ -221,7 +221,7 @@  static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
     if (r != size) {
         error_report("Failed to read msg header. Read %d instead of %d."
                      " Original request %d.", r, size, msg->hdr.request);
-        goto fail;
+        return -1;
     }
 
     /* validate received flags */
@@ -229,7 +229,21 @@  static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         error_report("Failed to read msg header."
                 " Flags 0x%x instead of 0x%x.", msg->hdr.flags,
                 VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);
-        goto fail;
+        return -1;
+    }
+
+    return 0;
+}
+
+static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
+{
+    struct vhost_user *u = dev->opaque;
+    CharBackend *chr = u->user->chr;
+    uint8_t *p = (uint8_t *) msg;
+    int r, size;
+
+    if (vhost_user_read_header(dev, msg) < 0) {
+        return -1;
     }
 
     /* validate message size is sane */
@@ -237,7 +251,7 @@  static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         error_report("Failed to read msg header."
                 " Size %d exceeds the maximum %zu.", msg->hdr.size,
                 VHOST_USER_PAYLOAD_SIZE);
-        goto fail;
+        return -1;
     }
 
     if (msg->hdr.size) {
@@ -247,14 +261,11 @@  static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         if (r != size) {
             error_report("Failed to read msg payload."
                          " Read %d instead of %d.", r, msg->hdr.size);
-            goto fail;
+            return -1;
         }
     }
 
     return 0;
-
-fail:
-    return -1;
 }
 
 static int process_message_reply(struct vhost_dev *dev,