Message ID | 20240722160745.67904-6-philmd@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | util/fifo8: Rework fifo8_pop_buf() | expand |
On 7/22/24 09:07, Philippe Mathieu-Daudé wrote: > Since fifo8_pop_buf() return a const buffer (which points > directly into the FIFO backing store), rename it using the > 'constbuf' suffix. This will help differentiate with methods > *copying* the FIFO data. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/qemu/fifo8.h | 4 ++-- > chardev/msmouse.c | 2 +- > hw/char/goldfish_tty.c | 4 ++-- > hw/net/allwinner_emac.c | 2 +- > hw/scsi/esp.c | 4 ++-- > ui/console-vc.c | 2 +- > ui/gtk.c | 2 +- > util/fifo8.c | 2 +- > 8 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h > index 79450f4583..686918a3a4 100644 > --- a/include/qemu/fifo8.h > +++ b/include/qemu/fifo8.h > @@ -63,7 +63,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); > uint8_t fifo8_pop(Fifo8 *fifo); > > /** > - * fifo8_pop_buf: > + * fifo8_pop_constbuf: > * @fifo: FIFO to pop from > * @max: maximum number of bytes to pop > * @numptr: pointer filled with number of bytes returned (can be NULL) > @@ -86,7 +86,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); > * > * Returns: A pointer to popped data. > */ > -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); > +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); > > /** > * fifo8_peek_constbuf: read upto max bytes from the fifo > diff --git a/chardev/msmouse.c b/chardev/msmouse.c > index a774c397b4..08836d92e8 100644 > --- a/chardev/msmouse.c > +++ b/chardev/msmouse.c > @@ -81,7 +81,7 @@ static void msmouse_chr_accept_input(Chardev *chr) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&mouse->outbuf, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&mouse->outbuf, MIN(len, avail), &size); > qemu_chr_be_write(chr, buf, size); > len = qemu_chr_be_can_write(chr); > avail -= size; > diff --git a/hw/char/goldfish_tty.c b/hw/char/goldfish_tty.c > index f8ff043c39..2c5004851d 100644 > --- a/hw/char/goldfish_tty.c > +++ b/hw/char/goldfish_tty.c > @@ -69,7 +69,7 @@ static uint64_t goldfish_tty_read(void *opaque, hwaddr addr, > static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) > { > uint32_t to_copy; > - uint8_t *buf; > + const uint8_t *buf; > uint8_t data_out[GOLFISH_TTY_BUFFER_SIZE]; > int len; > uint64_t ptr; > @@ -109,7 +109,7 @@ static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) > len = s->data_len; > ptr = s->data_ptr; > while (len && !fifo8_is_empty(&s->rx_fifo)) { > - buf = (uint8_t *)fifo8_pop_buf(&s->rx_fifo, len, &to_copy); > + buf = fifo8_pop_constbuf(&s->rx_fifo, len, &to_copy); > address_space_rw(&address_space_memory, ptr, > MEMTXATTRS_UNSPECIFIED, buf, to_copy, 1); > > diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c > index 989839784a..3b0a2ee07e 100644 > --- a/hw/net/allwinner_emac.c > +++ b/hw/net/allwinner_emac.c > @@ -349,7 +349,7 @@ static void aw_emac_write(void *opaque, hwaddr offset, uint64_t value, > "allwinner_emac: TX length > fifo data length\n"); > } > if (len > 0) { > - data = fifo8_pop_buf(fifo, len, &ret); > + data = fifo8_pop_constbuf(fifo, len, &ret); > qemu_send_packet(nc, data, ret); > aw_emac_tx_reset(s, chan); > /* Raise TX interrupt */ > diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c > index 526ed91bef..64384f9b0e 100644 > --- a/hw/scsi/esp.c > +++ b/hw/scsi/esp.c > @@ -208,7 +208,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) > } > > len = maxlen; > - buf = fifo8_pop_buf(fifo, len, &n); > + buf = fifo8_pop_constbuf(fifo, len, &n); > if (dest) { > memcpy(dest, buf, n); > } > @@ -217,7 +217,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) > len -= n; > len = MIN(len, fifo8_num_used(fifo)); > if (len) { > - buf = fifo8_pop_buf(fifo, len, &n2); > + buf = fifo8_pop_constbuf(fifo, len, &n2); > if (dest) { > memcpy(&dest[n], buf, n2); > } > diff --git a/ui/console-vc.c b/ui/console-vc.c > index 899fa11c94..e9906aae59 100644 > --- a/ui/console-vc.c > +++ b/ui/console-vc.c > @@ -287,7 +287,7 @@ static void kbd_send_chars(QemuTextConsole *s) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&s->out_fifo, MIN(len, avail), &size); > qemu_chr_be_write(s->chr, buf, size); > len = qemu_chr_be_can_write(s->chr); > avail -= size; > diff --git a/ui/gtk.c b/ui/gtk.c > index bc29f7a1b4..a4db90e8cb 100644 > --- a/ui/gtk.c > +++ b/ui/gtk.c > @@ -1820,7 +1820,7 @@ static void gd_vc_send_chars(VirtualConsole *vc) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&vc->vte.out_fifo, MIN(len, avail), &size); > qemu_chr_be_write(vc->vte.chr, buf, size); > len = qemu_chr_be_can_write(vc->vte.chr); > avail -= size; > diff --git a/util/fifo8.c b/util/fifo8.c > index 21943c6032..31f0d34c0c 100644 > --- a/util/fifo8.c > +++ b/util/fifo8.c > @@ -97,7 +97,7 @@ const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > return fifo8_peekpop_buf(fifo, max, numptr, false); > } > > -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > { > return fifo8_peekpop_buf(fifo, max, numptr, true); > } Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
On 22/07/2024 17:07, Philippe Mathieu-Daudé wrote: > Since fifo8_pop_buf() return a const buffer (which points > directly into the FIFO backing store), rename it using the > 'constbuf' suffix. This will help differentiate with methods > *copying* the FIFO data. Similar comment re: fifo8_pop_bufptr() as before, but still: Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> ATB, Mark. > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/qemu/fifo8.h | 4 ++-- > chardev/msmouse.c | 2 +- > hw/char/goldfish_tty.c | 4 ++-- > hw/net/allwinner_emac.c | 2 +- > hw/scsi/esp.c | 4 ++-- > ui/console-vc.c | 2 +- > ui/gtk.c | 2 +- > util/fifo8.c | 2 +- > 8 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h > index 79450f4583..686918a3a4 100644 > --- a/include/qemu/fifo8.h > +++ b/include/qemu/fifo8.h > @@ -63,7 +63,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); > uint8_t fifo8_pop(Fifo8 *fifo); > > /** > - * fifo8_pop_buf: > + * fifo8_pop_constbuf: > * @fifo: FIFO to pop from > * @max: maximum number of bytes to pop > * @numptr: pointer filled with number of bytes returned (can be NULL) > @@ -86,7 +86,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); > * > * Returns: A pointer to popped data. > */ > -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); > +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); > > /** > * fifo8_peek_constbuf: read upto max bytes from the fifo > diff --git a/chardev/msmouse.c b/chardev/msmouse.c > index a774c397b4..08836d92e8 100644 > --- a/chardev/msmouse.c > +++ b/chardev/msmouse.c > @@ -81,7 +81,7 @@ static void msmouse_chr_accept_input(Chardev *chr) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&mouse->outbuf, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&mouse->outbuf, MIN(len, avail), &size); > qemu_chr_be_write(chr, buf, size); > len = qemu_chr_be_can_write(chr); > avail -= size; > diff --git a/hw/char/goldfish_tty.c b/hw/char/goldfish_tty.c > index f8ff043c39..2c5004851d 100644 > --- a/hw/char/goldfish_tty.c > +++ b/hw/char/goldfish_tty.c > @@ -69,7 +69,7 @@ static uint64_t goldfish_tty_read(void *opaque, hwaddr addr, > static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) > { > uint32_t to_copy; > - uint8_t *buf; > + const uint8_t *buf; > uint8_t data_out[GOLFISH_TTY_BUFFER_SIZE]; > int len; > uint64_t ptr; > @@ -109,7 +109,7 @@ static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) > len = s->data_len; > ptr = s->data_ptr; > while (len && !fifo8_is_empty(&s->rx_fifo)) { > - buf = (uint8_t *)fifo8_pop_buf(&s->rx_fifo, len, &to_copy); > + buf = fifo8_pop_constbuf(&s->rx_fifo, len, &to_copy); > address_space_rw(&address_space_memory, ptr, > MEMTXATTRS_UNSPECIFIED, buf, to_copy, 1); > > diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c > index 989839784a..3b0a2ee07e 100644 > --- a/hw/net/allwinner_emac.c > +++ b/hw/net/allwinner_emac.c > @@ -349,7 +349,7 @@ static void aw_emac_write(void *opaque, hwaddr offset, uint64_t value, > "allwinner_emac: TX length > fifo data length\n"); > } > if (len > 0) { > - data = fifo8_pop_buf(fifo, len, &ret); > + data = fifo8_pop_constbuf(fifo, len, &ret); > qemu_send_packet(nc, data, ret); > aw_emac_tx_reset(s, chan); > /* Raise TX interrupt */ > diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c > index 526ed91bef..64384f9b0e 100644 > --- a/hw/scsi/esp.c > +++ b/hw/scsi/esp.c > @@ -208,7 +208,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) > } > > len = maxlen; > - buf = fifo8_pop_buf(fifo, len, &n); > + buf = fifo8_pop_constbuf(fifo, len, &n); > if (dest) { > memcpy(dest, buf, n); > } > @@ -217,7 +217,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) > len -= n; > len = MIN(len, fifo8_num_used(fifo)); > if (len) { > - buf = fifo8_pop_buf(fifo, len, &n2); > + buf = fifo8_pop_constbuf(fifo, len, &n2); > if (dest) { > memcpy(&dest[n], buf, n2); > } > diff --git a/ui/console-vc.c b/ui/console-vc.c > index 899fa11c94..e9906aae59 100644 > --- a/ui/console-vc.c > +++ b/ui/console-vc.c > @@ -287,7 +287,7 @@ static void kbd_send_chars(QemuTextConsole *s) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&s->out_fifo, MIN(len, avail), &size); > qemu_chr_be_write(s->chr, buf, size); > len = qemu_chr_be_can_write(s->chr); > avail -= size; > diff --git a/ui/gtk.c b/ui/gtk.c > index bc29f7a1b4..a4db90e8cb 100644 > --- a/ui/gtk.c > +++ b/ui/gtk.c > @@ -1820,7 +1820,7 @@ static void gd_vc_send_chars(VirtualConsole *vc) > const uint8_t *buf; > uint32_t size; > > - buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size); > + buf = fifo8_pop_constbuf(&vc->vte.out_fifo, MIN(len, avail), &size); > qemu_chr_be_write(vc->vte.chr, buf, size); > len = qemu_chr_be_can_write(vc->vte.chr); > avail -= size; > diff --git a/util/fifo8.c b/util/fifo8.c > index 21943c6032..31f0d34c0c 100644 > --- a/util/fifo8.c > +++ b/util/fifo8.c > @@ -97,7 +97,7 @@ const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > return fifo8_peekpop_buf(fifo, max, numptr, false); > } > > -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) > { > return fifo8_peekpop_buf(fifo, max, numptr, true); > }
diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 79450f4583..686918a3a4 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -63,7 +63,7 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num); uint8_t fifo8_pop(Fifo8 *fifo); /** - * fifo8_pop_buf: + * fifo8_pop_constbuf: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop * @numptr: pointer filled with number of bytes returned (can be NULL) @@ -86,7 +86,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * * Returns: A pointer to popped data. */ -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** * fifo8_peek_constbuf: read upto max bytes from the fifo diff --git a/chardev/msmouse.c b/chardev/msmouse.c index a774c397b4..08836d92e8 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -81,7 +81,7 @@ static void msmouse_chr_accept_input(Chardev *chr) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&mouse->outbuf, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&mouse->outbuf, MIN(len, avail), &size); qemu_chr_be_write(chr, buf, size); len = qemu_chr_be_can_write(chr); avail -= size; diff --git a/hw/char/goldfish_tty.c b/hw/char/goldfish_tty.c index f8ff043c39..2c5004851d 100644 --- a/hw/char/goldfish_tty.c +++ b/hw/char/goldfish_tty.c @@ -69,7 +69,7 @@ static uint64_t goldfish_tty_read(void *opaque, hwaddr addr, static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) { uint32_t to_copy; - uint8_t *buf; + const uint8_t *buf; uint8_t data_out[GOLFISH_TTY_BUFFER_SIZE]; int len; uint64_t ptr; @@ -109,7 +109,7 @@ static void goldfish_tty_cmd(GoldfishTTYState *s, uint32_t cmd) len = s->data_len; ptr = s->data_ptr; while (len && !fifo8_is_empty(&s->rx_fifo)) { - buf = (uint8_t *)fifo8_pop_buf(&s->rx_fifo, len, &to_copy); + buf = fifo8_pop_constbuf(&s->rx_fifo, len, &to_copy); address_space_rw(&address_space_memory, ptr, MEMTXATTRS_UNSPECIFIED, buf, to_copy, 1); diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c index 989839784a..3b0a2ee07e 100644 --- a/hw/net/allwinner_emac.c +++ b/hw/net/allwinner_emac.c @@ -349,7 +349,7 @@ static void aw_emac_write(void *opaque, hwaddr offset, uint64_t value, "allwinner_emac: TX length > fifo data length\n"); } if (len > 0) { - data = fifo8_pop_buf(fifo, len, &ret); + data = fifo8_pop_constbuf(fifo, len, &ret); qemu_send_packet(nc, data, ret); aw_emac_tx_reset(s, chan); /* Raise TX interrupt */ diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 526ed91bef..64384f9b0e 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -208,7 +208,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) } len = maxlen; - buf = fifo8_pop_buf(fifo, len, &n); + buf = fifo8_pop_constbuf(fifo, len, &n); if (dest) { memcpy(dest, buf, n); } @@ -217,7 +217,7 @@ static uint32_t esp_fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen) len -= n; len = MIN(len, fifo8_num_used(fifo)); if (len) { - buf = fifo8_pop_buf(fifo, len, &n2); + buf = fifo8_pop_constbuf(fifo, len, &n2); if (dest) { memcpy(&dest[n], buf, n2); } diff --git a/ui/console-vc.c b/ui/console-vc.c index 899fa11c94..e9906aae59 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -287,7 +287,7 @@ static void kbd_send_chars(QemuTextConsole *s) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&s->out_fifo, MIN(len, avail), &size); qemu_chr_be_write(s->chr, buf, size); len = qemu_chr_be_can_write(s->chr); avail -= size; diff --git a/ui/gtk.c b/ui/gtk.c index bc29f7a1b4..a4db90e8cb 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1820,7 +1820,7 @@ static void gd_vc_send_chars(VirtualConsole *vc) const uint8_t *buf; uint32_t size; - buf = fifo8_pop_buf(&vc->vte.out_fifo, MIN(len, avail), &size); + buf = fifo8_pop_constbuf(&vc->vte.out_fifo, MIN(len, avail), &size); qemu_chr_be_write(vc->vte.chr, buf, size); len = qemu_chr_be_can_write(vc->vte.chr); avail -= size; diff --git a/util/fifo8.c b/util/fifo8.c index 21943c6032..31f0d34c0c 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -97,7 +97,7 @@ const uint8_t *fifo8_peek_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) return fifo8_peekpop_buf(fifo, max, numptr, false); } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +const uint8_t *fifo8_pop_constbuf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { return fifo8_peekpop_buf(fifo, max, numptr, true); }
Since fifo8_pop_buf() return a const buffer (which points directly into the FIFO backing store), rename it using the 'constbuf' suffix. This will help differentiate with methods *copying* the FIFO data. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/qemu/fifo8.h | 4 ++-- chardev/msmouse.c | 2 +- hw/char/goldfish_tty.c | 4 ++-- hw/net/allwinner_emac.c | 2 +- hw/scsi/esp.c | 4 ++-- ui/console-vc.c | 2 +- ui/gtk.c | 2 +- util/fifo8.c | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-)