Skip to content

Commit 780f520

Browse files
yliu80wenlingz
authored andcommitted
DM: virtio-gpio: return a valid length for GPIO request
When the backend completes a GPIO request, it returns a valid length to ensure that response correct. Tracked-On: #2512 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 8bc0e12 commit 780f520

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

devicemodel/hw/pci/virtio/virtio_gpio.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,14 @@ static struct virtio_ops virtio_gpio_ops = {
481481

482482
};
483483

484-
static void
484+
static int
485485
virtio_gpio_proc(struct virtio_gpio *gpio, struct iovec *iov, int n)
486486
{
487487
struct virtio_gpio_data *data;
488488
struct virtio_gpio_request *req;
489489
struct virtio_gpio_response *rsp;
490490
struct gpio_line *line;
491-
int i, len;
491+
int i, len, rc;
492492

493493
if (n == 1) { /* provide gpio names for front-end driver */
494494
data = iov[0].iov_base;
@@ -510,6 +510,7 @@ virtio_gpio_proc(struct virtio_gpio *gpio, struct iovec *iov, int n)
510510
strncpy(data[i].name, line->name,
511511
sizeof(data[0].name) - 1);
512512
}
513+
rc = gpio->nvline;
513514
} else if (n == 2) { /* handle gpio operations requests */
514515
req = iov[0].iov_base;
515516
len = iov[0].iov_len;
@@ -520,8 +521,13 @@ virtio_gpio_proc(struct virtio_gpio *gpio, struct iovec *iov, int n)
520521
assert(len == sizeof(*rsp));
521522

522523
gpio_request_handler(gpio, req, rsp);
523-
} else
524+
rc = sizeof(*rsp);
525+
} else {
524526
DPRINTF("virtio gpio: number of buffer error %d\n", n);
527+
rc = 0;
528+
}
529+
530+
return rc;
525531
}
526532

527533
static void
@@ -530,18 +536,18 @@ virtio_gpio_notify(void *vdev, struct virtio_vq_info *vq)
530536
struct iovec iov[2];
531537
struct virtio_gpio *gpio;
532538
uint16_t idx;
533-
int n;
539+
int n, len;
534540

535541
gpio = (struct virtio_gpio *)vdev;
536542
if (vq_has_descs(vq)) {
537543
n = vq_getchain(vq, &idx, iov, 2, NULL);
538544
assert(n < 3);
539545

540-
virtio_gpio_proc(gpio, iov, n);
546+
len = virtio_gpio_proc(gpio, iov, n);
541547
/*
542548
* Release this chain and handle more
543549
*/
544-
vq_relchain(vq, idx, 1);
550+
vq_relchain(vq, idx, len);
545551

546552
}
547553
}

0 commit comments

Comments
 (0)