[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 12/25] xen: Let buffer_append() return the size c
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH v3 12/25] xen: Let buffer_append() return the size consumed |
Date: |
Wed, 20 Feb 2019 02:02:19 +0100 |
The buffer.size and buffer.consumed fields are only updated within the
buffer_append() body. We can simply let buffer_append() return the
difference (the buffer consumed).
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/char/xen_console.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index 083b2c8e2a..1a30014a11 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -48,7 +48,7 @@ struct XenConsole {
int backlog;
};
-static void buffer_append(struct XenConsole *con)
+static ssize_t buffer_append(struct XenConsole *con)
{
struct buffer *buffer = &con->buffer;
XENCONS_RING_IDX cons, prod, size;
@@ -59,8 +59,9 @@ static void buffer_append(struct XenConsole *con)
xen_mb();
size = prod - cons;
- if ((size == 0) || (size > sizeof(intf->out)))
- return;
+ if ((size == 0) || (size > sizeof(intf->out))) {
+ goto out;
+ }
if ((buffer->capacity - buffer->size) < size) {
buffer->capacity += (size + 1024);
@@ -89,6 +90,9 @@ static void buffer_append(struct XenConsole *con)
if (buffer->consumed > buffer->max_capacity - over)
buffer->consumed = buffer->max_capacity - over;
}
+
+ out:
+ return buffer->size - buffer->consumed;
}
static void buffer_advance(struct buffer *buffer, size_t len)
@@ -281,8 +285,7 @@ static void con_event(struct XenLegacyDevice *xendev)
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
ssize_t size;
- buffer_append(con);
- size = con->buffer.size - con->buffer.consumed;
+ size = buffer_append(con);
if (size) {
xencons_send(con, size);
}
--
2.20.1
- Re: [Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays, (continued)
- [Qemu-devel] [PATCH v3 10/25] usb-redir: Verify usbredirparser_write get called with positive count, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 15/25] spapr-vty: Let vty_putchars() use size_t, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 23/25] hw/ipmi: Assert outlen > outpos, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 12/25] xen: Let buffer_append() return the size consumed,
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH v3 14/25] virtio-serial: Let VirtIOSerialPortClass::have_data() use size_t, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 09/25] vhost-user: Express sizeof with size_t, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 07/25] gdbstub: Let put_buffer() use size_t, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [RFC PATCH v3 13/25] xen: Let buffer_append() return a size_t, Philippe Mathieu-Daudé, 2019/02/19
- [Qemu-devel] [PATCH v3 06/25] gdbstub: Use size_t to hold GDBState::last_packet_len, Philippe Mathieu-Daudé, 2019/02/19