qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type
@ 2018-10-12  0:22 Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations Philippe Mathieu-Daudé
                   ` (11 more replies)
  0 siblings, 12 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit; +Cc: Philippe Mathieu-Daudé, qemu-devel

Hi Paolo,

Here are the changes you suggested in
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.html

First two simple cleanups while here,
then slowly convert backends then frontends.

Regards,

Phil.

Philippe Mathieu-Daudé (11):
  hw/ipmi: Remove unnecessary declarations
  target/xtensa: Remove unnecessary declarations
  chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
  chardev: Assert backend's chr_can_read() is positive
  chardev: Let chr_sync_read() use unsigned type
  chardev: Let chr_write use unsigned type
  chardev: Let IOReadHandler use unsigned type
  chardev: Let IOCanReadHandler use unsigned type
  chardev: Let qemu_chr_fe_* use unsigned type
  chardev: Let qemu_chr_be_* use unsigned type
  chardev: FDChardev::max_size be unsigned

 backends/rng-egd.c          |  6 +++---
 chardev/baum.c              |  2 +-
 chardev/char-fd.c           |  8 ++++----
 chardev/char-fe.c           |  8 ++++----
 chardev/char-io.c           |  4 ++--
 chardev/char-mux.c          |  6 +++---
 chardev/char-pty.c          |  6 +++---
 chardev/char-ringbuf.c      |  4 ++--
 chardev/char-socket.c       | 10 +++++-----
 chardev/char-udp.c          |  6 +++---
 chardev/char-win-stdio.c    |  2 +-
 chardev/char-win.c          |  2 +-
 chardev/char.c              | 20 ++++++++++++--------
 chardev/msmouse.c           |  2 +-
 chardev/spice.c             |  2 +-
 chardev/testdev.c           |  2 +-
 chardev/wctablet.c          |  4 ++--
 gdbstub.c                   |  6 +++---
 hw/arm/pxa2xx.c             |  4 ++--
 hw/arm/strongarm.c          |  5 +++--
 hw/bt/hci-csr.c             |  4 ++--
 hw/char/bcm2835_aux.c       |  4 ++--
 hw/char/cadence_uart.c      |  6 +++---
 hw/char/cmsdk-apb-uart.c    |  4 ++--
 hw/char/digic-uart.c        |  4 ++--
 hw/char/escc.c              |  8 ++++----
 hw/char/etraxfs_ser.c       |  4 ++--
 hw/char/exynos4210_uart.c   |  5 +++--
 hw/char/grlib_apbuart.c     |  4 ++--
 hw/char/imx_serial.c        |  4 ++--
 hw/char/ipoctal232.c        |  6 +++---
 hw/char/lm32_juart.c        |  4 ++--
 hw/char/lm32_uart.c         |  4 ++--
 hw/char/mcf_uart.c          |  4 ++--
 hw/char/milkymist-uart.c    |  4 ++--
 hw/char/parallel.c          |  2 +-
 hw/char/pl011.c             |  6 +++---
 hw/char/sclpconsole-lm.c    |  4 ++--
 hw/char/sclpconsole.c       |  6 +++---
 hw/char/serial.c            |  8 ++++----
 hw/char/sh_serial.c         |  6 +++---
 hw/char/spapr_vty.c         |  6 +++---
 hw/char/stm32f2xx_usart.c   |  5 +++--
 hw/char/terminal3270.c      |  4 ++--
 hw/char/virtio-console.c    |  4 ++--
 hw/char/xen_console.c       |  4 ++--
 hw/char/xilinx_uartlite.c   |  4 ++--
 hw/ipmi/ipmi_bmc_extern.c   |  8 ++------
 hw/misc/ivshmem.c           |  6 +++---
 hw/riscv/riscv_htif.c       |  4 ++--
 hw/riscv/sifive_uart.c      |  4 ++--
 hw/usb/ccid-card-passthru.c |  6 +++---
 hw/usb/dev-serial.c         |  4 ++--
 hw/usb/redirect.c           |  4 ++--
 include/chardev/char-fd.h   |  2 +-
 include/chardev/char-fe.h   |  6 +++---
 include/chardev/char-io.h   |  2 +-
 include/chardev/char.h      | 13 +++++++------
 include/qemu/main-loop.h    |  4 ++--
 include/sysemu/replay.h     |  8 ++++----
 monitor.c                   |  6 +++---
 net/colo-compare.c          |  6 +++---
 net/filter-mirror.c         |  4 ++--
 net/slirp.c                 |  4 ++--
 qtest.c                     |  4 ++--
 replay/replay-char.c        |  8 ++++----
 stubs/replay.c              |  8 ++++----
 target/xtensa/xtensa-semi.c |  6 ++----
 ui/console.c                |  2 +-
 ui/gtk.c                    |  2 +-
 70 files changed, 180 insertions(+), 178 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:51   ` Corey Minyard
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 02/11] target/xtensa: " Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Corey Minyard

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/ipmi/ipmi_bmc_extern.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index bf0b7ee0f5..8c78b9804b 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -85,10 +85,6 @@ typedef struct IPMIBmcExtern {
     bool send_reset;
 } IPMIBmcExtern;
 
-static int can_receive(void *opaque);
-static void receive(void *opaque, const uint8_t *buf, int size);
-static void chr_event(void *opaque, int event);
-
 static unsigned char
 ipmb_checksum(const unsigned char *data, int size, unsigned char start)
 {
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 02/11] target/xtensa: Remove unnecessary declarations
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 03/11] chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Max Filippov

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 target/xtensa/xtensa-semi.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index 2f76216276..e389069f0b 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -161,7 +161,6 @@ typedef struct XtensaSimConsole {
 
 static XtensaSimConsole *sim_console;
 
-static IOCanReadHandler sim_console_can_read;
 static int sim_console_can_read(void *opaque)
 {
     XtensaSimConsole *p = opaque;
@@ -169,7 +168,6 @@ static int sim_console_can_read(void *opaque)
     return sizeof(p->input.buffer) - p->input.offset;
 }
 
-static IOReadHandler sim_console_read;
 static void sim_console_read(void *opaque, const uint8_t *buf, int size)
 {
     XtensaSimConsole *p = opaque;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 03/11] chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 02/11] target/xtensa: " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 04/11] chardev: Assert backend's chr_can_read() is positive Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Marc-André Lureau

IOWatchPoll::fd_can_read() simply returns a boolean value.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char-fd.c         | 4 ++--
 chardev/char-io.c         | 4 ++--
 chardev/char-pty.c        | 4 ++--
 chardev/char-socket.c     | 6 +++---
 chardev/char-udp.c        | 4 ++--
 include/chardev/char-io.h | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/chardev/char-fd.c b/chardev/char-fd.c
index 2c9b2ce567..2421d8e216 100644
--- a/chardev/char-fd.c
+++ b/chardev/char-fd.c
@@ -69,13 +69,13 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
     return TRUE;
 }
 
-static int fd_chr_read_poll(void *opaque)
+static gboolean fd_chr_read_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
     FDChardev *s = FD_CHARDEV(opaque);
 
     s->max_size = qemu_chr_be_can_write(chr);
-    return s->max_size;
+    return s->max_size > 0;
 }
 
 static GSource *fd_chr_add_watch(Chardev *chr, GIOCondition cond)
diff --git a/chardev/char-io.c b/chardev/char-io.c
index 8ced184160..a264d4e7fd 100644
--- a/chardev/char-io.c
+++ b/chardev/char-io.c
@@ -30,7 +30,7 @@ typedef struct IOWatchPoll {
     QIOChannel *ioc;
     GSource *src;
 
-    IOCanReadHandler *fd_can_read;
+    GSourceFunc fd_can_read;
     GSourceFunc fd_read;
     void *opaque;
 } IOWatchPoll;
@@ -76,7 +76,7 @@ static GSourceFuncs io_watch_poll_funcs = {
 
 GSource *io_add_watch_poll(Chardev *chr,
                         QIOChannel *ioc,
-                        IOCanReadHandler *fd_can_read,
+                        GSourceFunc fd_can_read,
                         QIOChannelFunc fd_read,
                         gpointer user_data,
                         GMainContext *context)
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index e8d9a53476..626ca30cb3 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -148,13 +148,13 @@ static GSource *pty_chr_add_watch(Chardev *chr, GIOCondition cond)
     return qio_channel_create_watch(s->ioc, cond);
 }
 
-static int pty_chr_read_poll(void *opaque)
+static gboolean pty_chr_read_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
     PtyChardev *s = PTY_CHARDEV(opaque);
 
     s->read_bytes = qemu_chr_be_can_write(chr);
-    return s->read_bytes;
+    return s->read_bytes > 0;
 }
 
 static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index a75b46d9fe..76cc3c48b0 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -120,7 +120,7 @@ static void tcp_chr_accept(QIONetListener *listener,
                            QIOChannelSocket *cioc,
                            void *opaque);
 
-static int tcp_chr_read_poll(void *opaque);
+static gboolean tcp_chr_read_poll(void *opaque);
 static void tcp_chr_disconnect(Chardev *chr);
 
 /* Called with chr_write_lock held.  */
@@ -157,7 +157,7 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
     }
 }
 
-static int tcp_chr_read_poll(void *opaque)
+static gboolean tcp_chr_read_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
     SocketChardev *s = SOCKET_CHARDEV(opaque);
@@ -165,7 +165,7 @@ static int tcp_chr_read_poll(void *opaque)
         return 0;
     }
     s->max_size = qemu_chr_be_can_write(chr);
-    return s->max_size;
+    return s->max_size > 0;
 }
 
 static void tcp_chr_process_IAC_bytes(Chardev *chr,
diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index 097a2f0f42..b6e399e983 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -65,7 +65,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)
     }
 }
 
-static int udp_chr_read_poll(void *opaque)
+static gboolean udp_chr_read_poll(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
     UdpChardev *s = UDP_CHARDEV(opaque);
@@ -77,7 +77,7 @@ static int udp_chr_read_poll(void *opaque)
      */
     udp_chr_flush_buffer(s);
 
-    return s->max_size;
+    return s->max_size > 0;
 }
 
 static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
diff --git a/include/chardev/char-io.h b/include/chardev/char-io.h
index 9638da5100..a173874538 100644
--- a/include/chardev/char-io.h
+++ b/include/chardev/char-io.h
@@ -31,7 +31,7 @@
 /* Can only be used for read */
 GSource *io_add_watch_poll(Chardev *chr,
                         QIOChannel *ioc,
-                        IOCanReadHandler *fd_can_read,
+                        GSourceFunc fd_can_read,
                         QIOChannelFunc fd_read,
                         gpointer user_data,
                         GMainContext *context);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 04/11] chardev: Assert backend's chr_can_read() is positive
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 03/11] chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 05/11] chardev: Let chr_sync_read() use unsigned type Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Marc-André Lureau

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/chardev/char.c b/chardev/char.c
index e115166995..952f9c9bcc 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -159,12 +159,15 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
 int qemu_chr_be_can_write(Chardev *s)
 {
     CharBackend *be = s->be;
+    int res;
 
     if (!be || !be->chr_can_read) {
         return 0;
     }
 
-    return be->chr_can_read(be->opaque);
+    res = be->chr_can_read(be->opaque);
+    assert(res >= 0);
+    return res;
 }
 
 void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 05/11] chardev: Let chr_sync_read() use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 04/11] chardev: Assert backend's chr_can_read() is positive Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 06/11] chardev: Let chr_write " Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Marc-André Lureau

Note than tcp_chr_recv() already use size_t.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char-socket.c  | 2 +-
 include/chardev/char.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 76cc3c48b0..7e627b243e 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -494,7 +494,7 @@ static gboolean tcp_chr_hup(QIOChannel *channel,
     return G_SOURCE_REMOVE;
 }
 
-static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)
+static size_t tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, size_t len)
 {
     SocketChardev *s = SOCKET_CHARDEV(chr);
     int size;
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 7becd8c80c..ef4509bfa3 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -251,7 +251,7 @@ typedef struct ChardevClass {
                  bool *be_opened, Error **errp);
 
     int (*chr_write)(Chardev *s, const uint8_t *buf, int len);
-    int (*chr_sync_read)(Chardev *s, const uint8_t *buf, int len);
+    size_t (*chr_sync_read)(Chardev *s, const uint8_t *buf, size_t len);
     GSource *(*chr_add_watch)(Chardev *s, GIOCondition cond);
     void (*chr_update_read_handler)(Chardev *s);
     int (*chr_ioctl)(Chardev *s, int cmd, void *arg);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 06/11] chardev: Let chr_write use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 05/11] chardev: Let chr_sync_read() use unsigned type Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler " Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, Samuel Thibault, Marc-André Lureau,
	Gerd Hoffmann

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/baum.c         | 2 +-
 chardev/char-fd.c      | 2 +-
 chardev/char-mux.c     | 2 +-
 chardev/char-pty.c     | 2 +-
 chardev/char-ringbuf.c | 4 ++--
 chardev/char-socket.c  | 2 +-
 chardev/char-udp.c     | 2 +-
 chardev/char.c         | 2 +-
 chardev/msmouse.c      | 2 +-
 chardev/spice.c        | 2 +-
 chardev/testdev.c      | 2 +-
 chardev/wctablet.c     | 4 ++--
 gdbstub.c              | 2 +-
 hw/bt/hci-csr.c        | 4 ++--
 include/chardev/char.h | 2 +-
 ui/console.c           | 2 +-
 ui/gtk.c               | 2 +-
 17 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/chardev/baum.c b/chardev/baum.c
index 78b0c87625..5367d82f53 100644
--- a/chardev/baum.c
+++ b/chardev/baum.c
@@ -479,7 +479,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)
 }
 
 /* The other end is writing some data.  Store it and try to interpret */
-static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t baum_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     BaumChardev *baum = BAUM_CHARDEV(chr);
     int tocopy, cur, eaten, orig_len = len;
diff --git a/chardev/char-fd.c b/chardev/char-fd.c
index 2421d8e216..bb426fa4b1 100644
--- a/chardev/char-fd.c
+++ b/chardev/char-fd.c
@@ -32,7 +32,7 @@
 #include "chardev/char-io.h"
 
 /* Called with chr_write_lock held.  */
-static int fd_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t fd_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     FDChardev *s = FD_CHARDEV(chr);
 
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index 6055e76293..3ca732d3a8 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -33,7 +33,7 @@
 /* MUX driver for serial I/O splitting */
 
 /* Called with chr_write_lock held.  */
-static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t mux_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     MuxChardev *d = MUX_CHARDEV(chr);
     int ret;
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 626ca30cb3..a2b78b44d8 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -125,7 +125,7 @@ static void pty_chr_update_read_handler(Chardev *chr)
 }
 
 /* Called with chr_write_lock held.  */
-static int char_pty_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t char_pty_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     PtyChardev *s = PTY_CHARDEV(chr);
 
diff --git a/chardev/char-ringbuf.c b/chardev/char-ringbuf.c
index 87832e2792..b805a585e3 100644
--- a/chardev/char-ringbuf.c
+++ b/chardev/char-ringbuf.c
@@ -49,12 +49,12 @@ static size_t ringbuf_count(const Chardev *chr)
     return d->prod - d->cons;
 }
 
-static int ringbuf_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t ringbuf_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     RingBufChardev *d = RINGBUF_CHARDEV(chr);
     int i;
 
-    if (!buf || (len < 0)) {
+    if (!buf) {
         return -1;
     }
 
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 7e627b243e..7c7fb06d48 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -124,7 +124,7 @@ static gboolean tcp_chr_read_poll(void *opaque);
 static void tcp_chr_disconnect(Chardev *chr);
 
 /* Called with chr_write_lock held.  */
-static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t tcp_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     SocketChardev *s = SOCKET_CHARDEV(chr);
 
diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index b6e399e983..577d049d78 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -45,7 +45,7 @@ typedef struct {
 #define UDP_CHARDEV(obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)
 
 /* Called with chr_write_lock held.  */
-static int udp_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t udp_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     UdpChardev *s = UDP_CHARDEV(chr);
 
diff --git a/chardev/char.c b/chardev/char.c
index 952f9c9bcc..608c2569f4 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -245,7 +245,7 @@ static void char_init(Object *obj)
     qemu_mutex_init(&chr->chr_write_lock);
 }
 
-static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t null_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     return len;
 }
diff --git a/chardev/msmouse.c b/chardev/msmouse.c
index 0ffd137ce8..0aad738cae 100644
--- a/chardev/msmouse.c
+++ b/chardev/msmouse.c
@@ -133,7 +133,7 @@ static void msmouse_input_sync(DeviceState *dev)
     msmouse_chr_accept_input(chr);
 }
 
-static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len)
+static size_t msmouse_chr_write(struct Chardev *s, const uint8_t *buf, size_t len)
 {
     /* Ignore writes to mouse port */
     return len;
diff --git a/chardev/spice.c b/chardev/spice.c
index e66e3ad568..a9e7b4e374 100644
--- a/chardev/spice.c
+++ b/chardev/spice.c
@@ -193,7 +193,7 @@ static GSource *spice_chr_add_watch(Chardev *chr, GIOCondition cond)
     return (GSource *)src;
 }
 
-static int spice_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t spice_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     SpiceChardev *s = SPICE_CHARDEV(chr);
     int read_bytes;
diff --git a/chardev/testdev.c b/chardev/testdev.c
index 031e9a23e8..6ebaf5fdaf 100644
--- a/chardev/testdev.c
+++ b/chardev/testdev.c
@@ -82,7 +82,7 @@ static int testdev_eat_packet(TestdevChardev *testdev)
 }
 
 /* The other end is writing some data.  Store it and try to interpret */
-static int testdev_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t testdev_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     TestdevChardev *testdev = TESTDEV_CHARDEV(chr);
     int tocopy, eaten, orig_len = len;
diff --git a/chardev/wctablet.c b/chardev/wctablet.c
index 969d014574..52acbdb609 100644
--- a/chardev/wctablet.c
+++ b/chardev/wctablet.c
@@ -203,8 +203,8 @@ static void wctablet_chr_accept_input(Chardev *chr)
     }
 }
 
-static int wctablet_chr_write(struct Chardev *chr,
-                              const uint8_t *buf, int len)
+static size_t wctablet_chr_write(struct Chardev *chr,
+                              const uint8_t *buf, size_t len)
 {
     TabletChardev *tablet = WCTABLET_CHARDEV(chr);
     unsigned int i, clen;
diff --git a/gdbstub.c b/gdbstub.c
index c8478de8f5..bbbb1cfcc1 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1955,7 +1955,7 @@ static void gdb_monitor_output(GDBState *s, const char *msg, int len)
     put_packet(s, buf);
 }
 
-static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t gdb_monitor_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     const char *p = (const char *)buf;
     int max_sz;
diff --git a/hw/bt/hci-csr.c b/hw/bt/hci-csr.c
index 0341ded50c..21ac388675 100644
--- a/hw/bt/hci-csr.c
+++ b/hw/bt/hci-csr.c
@@ -314,8 +314,8 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s)
     s->in_hdr = INT_MAX;
 }
 
-static int csrhci_write(struct Chardev *chr,
-                const uint8_t *buf, int len)
+static size_t csrhci_write(struct Chardev *chr,
+                const uint8_t *buf, size_t len)
 {
     struct csrhci_s *s = (struct csrhci_s *)chr;
     int total = 0;
diff --git a/include/chardev/char.h b/include/chardev/char.h
index ef4509bfa3..091a514022 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -250,7 +250,7 @@ typedef struct ChardevClass {
     void (*open)(Chardev *chr, ChardevBackend *backend,
                  bool *be_opened, Error **errp);
 
-    int (*chr_write)(Chardev *s, const uint8_t *buf, int len);
+    size_t (*chr_write)(Chardev *s, const uint8_t *buf, size_t len);
     size_t (*chr_sync_read)(Chardev *s, const uint8_t *buf, size_t len);
     GSource *(*chr_add_watch)(Chardev *s, GIOCondition cond);
     void (*chr_update_read_handler)(Chardev *s);
diff --git a/ui/console.c b/ui/console.c
index 3a285bae00..5fed0504f4 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1080,7 +1080,7 @@ typedef struct VCChardev {
 #define TYPE_CHARDEV_VC "chardev-vc"
 #define VC_CHARDEV(obj) OBJECT_CHECK(VCChardev, (obj), TYPE_CHARDEV_VC)
 
-static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t vc_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     VCChardev *drv = VC_CHARDEV(chr);
     QemuConsole *s = drv->console;
diff --git a/ui/gtk.c b/ui/gtk.c
index 3ddb5fe162..7990b58833 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1842,7 +1842,7 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
     }
 }
 
-static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t gd_vc_chr_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     VCChardev *vcd = VC_CHARDEV(chr);
     VirtualConsole *vc = vcd->console;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 06/11] chardev: Let chr_write " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2021-01-22 11:26   ` Richard Purdie
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 08/11] chardev: Let IOCanReadHandler " Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, Amit Shah, Marc-André Lureau,
	Andrzej Zaborowski, Peter Maydell, Edgar E. Iglesias,
	Alistair Francis, Antony Pavlov, Igor Mitsyanko, Fabien Chouteau,
	Peter Chubb, Alberto Garcia, Michael Walle, Thomas Huth,
	Cornelia Huck, Christian Borntraeger, Alexander Graf,
	Michael S. Tsirkin, David Gibson, Stefano Stabellini,
	Anthony Perard, Corey Minyard, Michael Clark, Palmer Dabbelt,
	Sagar Karandikar, Bastian Koppelmann, Gerd Hoffmann,
	Samuel Thibault, Markus Armbruster, Dr. David Alan Gilbert,
	Zhang Chen, Li Zhijian, Jason Wang, Jan Kiszka, Laurent Vivier,
	Max Filippov, open list:PXA2XX, open list:S390 Virtio-ccw,
	open list:sPAPR, open list:X86

The number of bytes can not be negative nor zero.

Fixed 2 format string:
- hw/char/spapr_vty.c
- hw/usb/ccid-card-passthru.c

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Alberto Garcia <berto@igalia.com>
---
 backends/rng-egd.c          | 2 +-
 chardev/char-mux.c          | 2 +-
 gdbstub.c                   | 2 +-
 hw/arm/pxa2xx.c             | 2 +-
 hw/arm/strongarm.c          | 3 ++-
 hw/char/bcm2835_aux.c       | 2 +-
 hw/char/cadence_uart.c      | 2 +-
 hw/char/cmsdk-apb-uart.c    | 2 +-
 hw/char/digic-uart.c        | 2 +-
 hw/char/escc.c              | 2 +-
 hw/char/etraxfs_ser.c       | 2 +-
 hw/char/exynos4210_uart.c   | 3 ++-
 hw/char/grlib_apbuart.c     | 2 +-
 hw/char/imx_serial.c        | 2 +-
 hw/char/ipoctal232.c        | 2 +-
 hw/char/lm32_juart.c        | 2 +-
 hw/char/lm32_uart.c         | 2 +-
 hw/char/mcf_uart.c          | 2 +-
 hw/char/milkymist-uart.c    | 2 +-
 hw/char/pl011.c             | 2 +-
 hw/char/sclpconsole-lm.c    | 2 +-
 hw/char/sclpconsole.c       | 2 +-
 hw/char/serial.c            | 4 ++--
 hw/char/sh_serial.c         | 2 +-
 hw/char/spapr_vty.c         | 4 ++--
 hw/char/stm32f2xx_usart.c   | 3 ++-
 hw/char/terminal3270.c      | 2 +-
 hw/char/virtio-console.c    | 2 +-
 hw/char/xen_console.c       | 2 +-
 hw/char/xilinx_uartlite.c   | 2 +-
 hw/ipmi/ipmi_bmc_extern.c   | 2 +-
 hw/misc/ivshmem.c           | 4 ++--
 hw/riscv/riscv_htif.c       | 2 +-
 hw/riscv/sifive_uart.c      | 2 +-
 hw/usb/ccid-card-passthru.c | 4 ++--
 hw/usb/dev-serial.c         | 2 +-
 hw/usb/redirect.c           | 2 +-
 include/qemu/main-loop.h    | 2 +-
 monitor.c                   | 4 ++--
 net/colo-compare.c          | 4 ++--
 net/filter-mirror.c         | 2 +-
 net/slirp.c                 | 2 +-
 qtest.c                     | 2 +-
 target/xtensa/xtensa-semi.c | 2 +-
 44 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index d2b9ce6cbf..b51c01f664 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -61,7 +61,7 @@ static int rng_egd_chr_can_read(void *opaque)
     return size;
 }
 
-static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
+static void rng_egd_chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     RngEgd *s = RNG_EGD(opaque);
     size_t buf_offset = 0;
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index 3ca732d3a8..d8d6eaa646 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -209,7 +209,7 @@ static int mux_chr_can_read(void *opaque)
     return 0;
 }
 
-static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
+static void mux_chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     Chardev *chr = CHARDEV(opaque);
     MuxChardev *d = MUX_CHARDEV(opaque);
diff --git a/gdbstub.c b/gdbstub.c
index bbbb1cfcc1..a2fc3682ce 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1923,7 +1923,7 @@ static int gdb_chr_can_receive(void *opaque)
   return MAX_PACKET_LENGTH;
 }
 
-static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size)
+static void gdb_chr_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     int i;
 
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index f598a1c053..75b6aa2772 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -1929,7 +1929,7 @@ static int pxa2xx_fir_is_empty(void *opaque)
     return (s->rx_len < 64);
 }
 
-static void pxa2xx_fir_rx(void *opaque, const uint8_t *buf, int size)
+static void pxa2xx_fir_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     PXA2xxFIrState *s = (PXA2xxFIrState *) opaque;
     if (!(s->control[0] & (1 << 4)))			/* RXE */
diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c
index ec2627374d..40db4e5e0a 100644
--- a/hw/arm/strongarm.c
+++ b/hw/arm/strongarm.c
@@ -1072,7 +1072,8 @@ static int strongarm_uart_can_receive(void *opaque)
     return 1;
 }
 
-static void strongarm_uart_receive(void *opaque, const uint8_t *buf, int size)
+static void strongarm_uart_receive(void *opaque, const uint8_t *buf,
+                                   size_t size)
 {
     StrongARMUARTState *s = opaque;
     int i;
diff --git a/hw/char/bcm2835_aux.c b/hw/char/bcm2835_aux.c
index 0364596c55..cb26df40f8 100644
--- a/hw/char/bcm2835_aux.c
+++ b/hw/char/bcm2835_aux.c
@@ -235,7 +235,7 @@ static void bcm2835_aux_put_fifo(void *opaque, uint8_t value)
     bcm2835_aux_update(s);
 }
 
-static void bcm2835_aux_receive(void *opaque, const uint8_t *buf, int size)
+static void bcm2835_aux_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     bcm2835_aux_put_fifo(opaque, *buf);
 }
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index fbdbd463bb..eb5cc974a1 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -332,7 +332,7 @@ static void uart_write_tx_fifo(CadenceUARTState *s, const uint8_t *buf,
     cadence_uart_xmit(NULL, G_IO_OUT, s);
 }
 
-static void uart_receive(void *opaque, const uint8_t *buf, int size)
+static void uart_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     CadenceUARTState *s = opaque;
     uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
diff --git a/hw/char/cmsdk-apb-uart.c b/hw/char/cmsdk-apb-uart.c
index ddfbb25c24..774986d88d 100644
--- a/hw/char/cmsdk-apb-uart.c
+++ b/hw/char/cmsdk-apb-uart.c
@@ -119,7 +119,7 @@ static int uart_can_receive(void *opaque)
     return 0;
 }
 
-static void uart_receive(void *opaque, const uint8_t *buf, int size)
+static void uart_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     CMSDKAPBUART *s = CMSDK_APB_UART(opaque);
 
diff --git a/hw/char/digic-uart.c b/hw/char/digic-uart.c
index ccc75eaa4d..0f41a23b54 100644
--- a/hw/char/digic-uart.c
+++ b/hw/char/digic-uart.c
@@ -119,7 +119,7 @@ static int uart_can_rx(void *opaque)
     return !(s->reg_st & ST_RX_RDY);
 }
 
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
+static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     DigicUartState *s = opaque;
 
diff --git a/hw/char/escc.c b/hw/char/escc.c
index 628f5f81f7..e655b86273 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -601,7 +601,7 @@ static void serial_receive_break(ESCCChannelState *s)
     escc_update_irq(s);
 }
 
-static void serial_receive1(void *opaque, const uint8_t *buf, int size)
+static void serial_receive1(void *opaque, const uint8_t *buf, size_t size)
 {
     ESCCChannelState *s = opaque;
     serial_receive_byte(s, buf[0]);
diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index a184026410..79cd8d2dc1 100644
--- a/hw/char/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -166,7 +166,7 @@ static Property etraxfs_ser_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void serial_receive(void *opaque, const uint8_t *buf, int size)
+static void serial_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     ETRAXSerial *s = opaque;
     int i;
diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index a5a285655f..5fdf5b1f37 100644
--- a/hw/char/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -495,7 +495,8 @@ static int exynos4210_uart_can_receive(void *opaque)
 }
 
 
-static void exynos4210_uart_receive(void *opaque, const uint8_t *buf, int size)
+static void exynos4210_uart_receive(void *opaque, const uint8_t *buf,
+                                    size_t size)
 {
     Exynos4210UartState *s = (Exynos4210UartState *)opaque;
     int i;
diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index bac11bec58..d370609a52 100644
--- a/hw/char/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
@@ -137,7 +137,7 @@ static int grlib_apbuart_can_receive(void *opaque)
     return FIFO_LENGTH - uart->len;
 }
 
-static void grlib_apbuart_receive(void *opaque, const uint8_t *buf, int size)
+static void grlib_apbuart_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     UART *uart = opaque;
 
diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c
index 1e363190e3..b9fdfaeb38 100644
--- a/hw/char/imx_serial.c
+++ b/hw/char/imx_serial.c
@@ -315,7 +315,7 @@ static void imx_put_data(void *opaque, uint32_t value)
     imx_update(s);
 }
 
-static void imx_receive(void *opaque, const uint8_t *buf, int size)
+static void imx_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     imx_put_data(opaque, *buf);
 }
diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c
index 5e09caf851..08e3f9e45f 100644
--- a/hw/char/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -468,7 +468,7 @@ static int hostdev_can_receive(void *opaque)
     return ch->rx_enabled ? available_bytes : 0;
 }
 
-static void hostdev_receive(void *opaque, const uint8_t *buf, int size)
+static void hostdev_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     SCC2698Channel *ch = opaque;
     IPOctalState *dev = ch->ipoctal;
diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
index d75c835ad2..ecb61ee086 100644
--- a/hw/char/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -88,7 +88,7 @@ void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx)
     s->jrx &= ~JRX_FULL;
 }
 
-static void juart_rx(void *opaque, const uint8_t *buf, int size)
+static void juart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     LM32JuartState *s = opaque;
 
diff --git a/hw/char/lm32_uart.c b/hw/char/lm32_uart.c
index c4a3b9b275..ee0bf8e117 100644
--- a/hw/char/lm32_uart.c
+++ b/hw/char/lm32_uart.c
@@ -211,7 +211,7 @@ static const MemoryRegionOps uart_ops = {
     },
 };
 
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
+static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     LM32UartState *s = opaque;
 
diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c
index 787f985db6..e126860b46 100644
--- a/hw/char/mcf_uart.c
+++ b/hw/char/mcf_uart.c
@@ -274,7 +274,7 @@ static int mcf_uart_can_receive(void *opaque)
     return s->rx_enabled && (s->sr & MCF_UART_FFULL) == 0;
 }
 
-static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)
+static void mcf_uart_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     mcf_uart_state *s = (mcf_uart_state *)opaque;
 
diff --git a/hw/char/milkymist-uart.c b/hw/char/milkymist-uart.c
index 548ee27bca..a10c0957ff 100644
--- a/hw/char/milkymist-uart.c
+++ b/hw/char/milkymist-uart.c
@@ -158,7 +158,7 @@ static const MemoryRegionOps uart_mmio_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
+static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     MilkymistUartState *s = opaque;
 
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index 2aa277fc4f..37973c32ce 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -260,7 +260,7 @@ static void pl011_put_fifo(void *opaque, uint32_t value)
     }
 }
 
-static void pl011_receive(void *opaque, const uint8_t *buf, int size)
+static void pl011_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     pl011_put_fifo(opaque, *buf);
 }
diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
index dbc91a1e5b..a04a2a9d80 100644
--- a/hw/char/sclpconsole-lm.c
+++ b/hw/char/sclpconsole-lm.c
@@ -71,7 +71,7 @@ static int chr_can_read(void *opaque)
     return 1;
 }
 
-static void chr_read(void *opaque, const uint8_t *buf, int size)
+static void chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     SCLPConsoleLM *scon = opaque;
 
diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c
index 1fa16e9055..62395c19f4 100644
--- a/hw/char/sclpconsole.c
+++ b/hw/char/sclpconsole.c
@@ -59,7 +59,7 @@ static int chr_can_read(void *opaque)
 }
 
 /* Send data from a char device over to the guest */
-static void chr_read(void *opaque, const uint8_t *buf, int size)
+static void chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     SCLPConsole *scon = opaque;
 
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 02463e3388..69baed105b 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -105,7 +105,7 @@ do { fprintf(stderr, "serial: " fmt , ## __VA_ARGS__); } while (0)
 do {} while (0)
 #endif
 
-static void serial_receive1(void *opaque, const uint8_t *buf, int size);
+static void serial_receive1(void *opaque, const uint8_t *buf, size_t size);
 static void serial_xmit(SerialState *s);
 
 static inline void recv_fifo_put(SerialState *s, uint8_t chr)
@@ -606,7 +606,7 @@ static int serial_can_receive1(void *opaque)
     return serial_can_receive(s);
 }
 
-static void serial_receive1(void *opaque, const uint8_t *buf, int size)
+static void serial_receive1(void *opaque, const uint8_t *buf, size_t size)
 {
     SerialState *s = opaque;
 
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c
index 12831561a6..04fdcee328 100644
--- a/hw/char/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -327,7 +327,7 @@ static void sh_serial_timeout_int(void *opaque)
     }
 }
 
-static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)
+static void sh_serial_receive1(void *opaque, const uint8_t *buf, size_t size)
 {
     sh_serial_state *s = opaque;
 
diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
index 6748334ded..42b4b61cce 100644
--- a/hw/char/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -28,7 +28,7 @@ static int vty_can_receive(void *opaque)
     return VTERM_BUFSIZE - (dev->in - dev->out);
 }
 
-static void vty_receive(void *opaque, const uint8_t *buf, int size)
+static void vty_receive(void *opaque, const uint8_t *buf, size_t size)
 {
     VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(opaque);
     int i;
@@ -42,7 +42,7 @@ static void vty_receive(void *opaque, const uint8_t *buf, int size)
             static bool reported;
             if (!reported) {
                 error_report("VTY input buffer exhausted - characters dropped."
-                             " (input size = %i)", size);
+                             " (input size = %zu)", size);
                 reported = true;
             }
             break;
diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c
index 032b5fda13..78bf142678 100644
--- a/hw/char/stm32f2xx_usart.c
+++ b/hw/char/stm32f2xx_usart.c
@@ -49,7 +49,8 @@ static int stm32f2xx_usart_can_receive(void *opaque)
     return 0;
 }
 
-static void stm32f2xx_usart_receive(void *opaque, const uint8_t *buf, int size)
+static void stm32f2xx_usart_receive(void *opaque, const uint8_t *buf,
+                                    size_t size)
 {
     STM32F2XXUsartState *s = opaque;
 
diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c
index e9c45e55b1..076516991e 100644
--- a/hw/char/terminal3270.c
+++ b/hw/char/terminal3270.c
@@ -90,7 +90,7 @@ static gboolean send_timing_mark_cb(gpointer opaque)
  * As of now, for such case, we simply terminate the connection,
  * and we should come back here later with a better solution.
  */
-static void terminal_read(void *opaque, const uint8_t *buf, int size)
+static void terminal_read(void *opaque, const uint8_t *buf, size_t size)
 {
     Terminal3270 *t = opaque;
     CcwDevice *ccw_dev = CCW_DEVICE(t);
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 2cbe1d4ed5..e3d368b976 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -134,7 +134,7 @@ static int chr_can_read(void *opaque)
 }
 
 /* Send data from a char device over to the guest */
-static void chr_read(void *opaque, const uint8_t *buf, int size)
+static void chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     VirtConsole *vcon = opaque;
     VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index 44f7236382..ca90c5c17e 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -122,7 +122,7 @@ static int xencons_can_receive(void *opaque)
     return ring_free_bytes(con);
 }
 
-static void xencons_receive(void *opaque, const uint8_t *buf, int len)
+static void xencons_receive(void *opaque, const uint8_t *buf, size_t len)
 {
     struct XenConsole *con = opaque;
     struct xencons_interface *intf = con->sring;
diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c
index 2a8bc1e497..b1abf8b604 100644
--- a/hw/char/xilinx_uartlite.c
+++ b/hw/char/xilinx_uartlite.c
@@ -177,7 +177,7 @@ static Property xilinx_uartlite_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
+static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     XilinxUARTLite *s = opaque;
 
diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index 8c78b9804b..c52f80f771 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -312,7 +312,7 @@ static int can_receive(void *opaque)
     return 1;
 }
 
-static void receive(void *opaque, const uint8_t *buf, int size)
+static void receive(void *opaque, const uint8_t *buf, size_t size)
 {
     IPMIBmcExtern *ibe = opaque;
     int i;
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 8cb17b9dd4..f506479845 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -628,14 +628,14 @@ static int ivshmem_can_receive(void *opaque)
     return sizeof(s->msg_buf) - s->msg_buffered_bytes;
 }
 
-static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
+static void ivshmem_read(void *opaque, const uint8_t *buf, size_t size)
 {
     IVShmemState *s = opaque;
     Error *err = NULL;
     int fd;
     int64_t msg;
 
-    assert(size >= 0 && s->msg_buffered_bytes + size <= sizeof(s->msg_buf));
+    assert(s->msg_buffered_bytes + size <= sizeof(s->msg_buf));
     memcpy((unsigned char *)&s->msg_buf + s->msg_buffered_bytes, buf, size);
     s->msg_buffered_bytes += size;
     if (s->msg_buffered_bytes < sizeof(s->msg_buf)) {
diff --git a/hw/riscv/riscv_htif.c b/hw/riscv/riscv_htif.c
index 4f7b11dc37..2625f5e9e8 100644
--- a/hw/riscv/riscv_htif.c
+++ b/hw/riscv/riscv_htif.c
@@ -74,7 +74,7 @@ static int htif_can_recv(void *opaque)
  * Called by the char dev to supply input to HTIF console.
  * We assume that we will receive one character at a time.
  */
-static void htif_recv(void *opaque, const uint8_t *buf, int size)
+static void htif_recv(void *opaque, const uint8_t *buf, size_t size)
 {
     HTIFState *htifstate = opaque;
 
diff --git a/hw/riscv/sifive_uart.c b/hw/riscv/sifive_uart.c
index b0c3798cf2..d4cbf91b9f 100644
--- a/hw/riscv/sifive_uart.c
+++ b/hw/riscv/sifive_uart.c
@@ -123,7 +123,7 @@ static const MemoryRegionOps uart_ops = {
     }
 };
 
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
+static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
 {
     SiFiveUARTState *s = opaque;
 
diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index 0a6c657228..b6fa35a4b4 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -270,13 +270,13 @@ static void ccid_card_vscard_drop_connection(PassthruState *card)
     card->vscard_in_pos = card->vscard_in_hdr = 0;
 }
 
-static void ccid_card_vscard_read(void *opaque, const uint8_t *buf, int size)
+static void ccid_card_vscard_read(void *opaque, const uint8_t *buf, size_t size)
 {
     PassthruState *card = opaque;
     VSCMsgHeader *hdr;
 
     if (card->vscard_in_pos + size > VSCARD_IN_SIZE) {
-        error_report("no room for data: pos %u +  size %d > %" PRId64 "."
+        error_report("no room for data: pos %u +  size %zu > %" PRId64 "."
                      " dropping connection.",
                      card->vscard_in_pos, size, VSCARD_IN_SIZE);
         ccid_card_vscard_drop_connection(card);
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 98d1ca3c91..efaeab484d 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -431,7 +431,7 @@ static int usb_serial_can_read(void *opaque)
     return RECV_BUF - s->recv_used;
 }
 
-static void usb_serial_read(void *opaque, const uint8_t *buf, int size)
+static void usb_serial_read(void *opaque, const uint8_t *buf, size_t size)
 {
     USBSerialState *s = opaque;
     int first_size, start;
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 99094a721e..a73076ba78 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1302,7 +1302,7 @@ static int usbredir_chardev_can_read(void *opaque)
     return 1 * MiB;
 }
 
-static void usbredir_chardev_read(void *opaque, const uint8_t *buf, int size)
+static void usbredir_chardev_read(void *opaque, const uint8_t *buf, size_t size)
 {
     USBRedirDevice *dev = opaque;
 
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index e59f9ae1e9..c5a7299266 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -167,7 +167,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
 /* async I/O support */
 
-typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
+typedef void IOReadHandler(void *opaque, const uint8_t *buf, size_t size);
 
 /**
  * IOCanReadHandler: Return the number of bytes that #IOReadHandler can accept
diff --git a/monitor.c b/monitor.c
index b9258a7438..12401ec60b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4240,14 +4240,14 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err)
     qemu_bh_schedule(qmp_dispatcher_bh);
 }
 
-static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
+static void monitor_qmp_read(void *opaque, const uint8_t *buf, size_t size)
 {
     Monitor *mon = opaque;
 
     json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size);
 }
 
-static void monitor_read(void *opaque, const uint8_t *buf, int size)
+static void monitor_read(void *opaque, const uint8_t *buf, size_t size)
 {
     Monitor *old_mon = cur_mon;
     int i;
diff --git a/net/colo-compare.c b/net/colo-compare.c
index dd745a491b..433e9ba287 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -692,7 +692,7 @@ static int compare_chr_can_read(void *opaque)
  * Called from the main thread on the primary for packets
  * arriving over the socket from the primary.
  */
-static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size)
+static void compare_pri_chr_in(void *opaque, const uint8_t *buf, size_t size)
 {
     CompareState *s = COLO_COMPARE(opaque);
     int ret;
@@ -709,7 +709,7 @@ static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size)
  * Called from the main thread on the primary for packets
  * arriving over the socket from the secondary.
  */
-static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size)
+static void compare_sec_chr_in(void *opaque, const uint8_t *buf, size_t size)
 {
     CompareState *s = COLO_COMPARE(opaque);
     int ret;
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index 3a61cf21e8..27b6e52a1d 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -119,7 +119,7 @@ static int redirector_chr_can_read(void *opaque)
     return REDIRECTOR_MAX_LEN;
 }
 
-static void redirector_chr_read(void *opaque, const uint8_t *buf, int size)
+static void redirector_chr_read(void *opaque, const uint8_t *buf, size_t size)
 {
     NetFilterState *nf = opaque;
     MirrorState *s = FILTER_REDIRECTOR(nf);
diff --git a/net/slirp.c b/net/slirp.c
index 99884de204..5e864f4a4f 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -718,7 +718,7 @@ static int guestfwd_can_read(void *opaque)
     return slirp_socket_can_recv(fwd->slirp, fwd->server, fwd->port);
 }
 
-static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
+static void guestfwd_read(void *opaque, const uint8_t *buf, size_t size)
 {
     struct GuestFwd *fwd = opaque;
     slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
diff --git a/qtest.c b/qtest.c
index 69b9e9962b..0494afdfb3 100644
--- a/qtest.c
+++ b/qtest.c
@@ -657,7 +657,7 @@ static void qtest_process_inbuf(CharBackend *chr, GString *inbuf)
     }
 }
 
-static void qtest_read(void *opaque, const uint8_t *buf, int size)
+static void qtest_read(void *opaque, const uint8_t *buf, size_t size)
 {
     CharBackend *chr = opaque;
 
diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index e389069f0b..241874ea4e 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -168,7 +168,7 @@ static int sim_console_can_read(void *opaque)
     return sizeof(p->input.buffer) - p->input.offset;
 }
 
-static void sim_console_read(void *opaque, const uint8_t *buf, int size)
+static void sim_console_read(void *opaque, const uint8_t *buf, size_t size)
 {
     XtensaSimConsole *p = opaque;
     size_t copy = sizeof(p->input.buffer) - p->input.offset;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 08/11] chardev: Let IOCanReadHandler use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 09/11] chardev: Let qemu_chr_fe_* " Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, Amit Shah, Marc-André Lureau,
	Andrzej Zaborowski, Peter Maydell, Edgar E. Iglesias,
	Alistair Francis, Antony Pavlov, Igor Mitsyanko, Fabien Chouteau,
	Peter Chubb, Alberto Garcia, Michael Walle, Thomas Huth,
	Michael S. Tsirkin, Cornelia Huck, Christian Borntraeger,
	Alexander Graf, David Gibson, Stefano Stabellini, Anthony Perard,
	Corey Minyard, Michael Clark, Palmer Dabbelt, Sagar Karandikar,
	Bastian Koppelmann, Gerd Hoffmann, Samuel Thibault,
	Dr. David Alan Gilbert, Markus Armbruster, Zhang Chen,
	Li Zhijian, Jason Wang, Jan Kiszka, Laurent Vivier, Max Filippov,
	open list:PXA2XX, open list:S390, open list:sPAPR, open list:X86

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 backends/rng-egd.c          | 4 ++--
 chardev/char-mux.c          | 2 +-
 gdbstub.c                   | 2 +-
 hw/arm/pxa2xx.c             | 2 +-
 hw/arm/strongarm.c          | 2 +-
 hw/char/bcm2835_aux.c       | 2 +-
 hw/char/cadence_uart.c      | 4 ++--
 hw/char/cmsdk-apb-uart.c    | 2 +-
 hw/char/digic-uart.c        | 2 +-
 hw/char/escc.c              | 6 +++---
 hw/char/etraxfs_ser.c       | 2 +-
 hw/char/exynos4210_uart.c   | 2 +-
 hw/char/grlib_apbuart.c     | 2 +-
 hw/char/imx_serial.c        | 2 +-
 hw/char/ipoctal232.c        | 4 ++--
 hw/char/lm32_juart.c        | 2 +-
 hw/char/lm32_uart.c         | 2 +-
 hw/char/mcf_uart.c          | 2 +-
 hw/char/milkymist-uart.c    | 2 +-
 hw/char/parallel.c          | 2 +-
 hw/char/pl011.c             | 4 ++--
 hw/char/sclpconsole-lm.c    | 2 +-
 hw/char/sclpconsole.c       | 4 ++--
 hw/char/serial.c            | 4 ++--
 hw/char/sh_serial.c         | 4 ++--
 hw/char/spapr_vty.c         | 2 +-
 hw/char/stm32f2xx_usart.c   | 2 +-
 hw/char/terminal3270.c      | 2 +-
 hw/char/virtio-console.c    | 2 +-
 hw/char/xen_console.c       | 2 +-
 hw/char/xilinx_uartlite.c   | 2 +-
 hw/ipmi/ipmi_bmc_extern.c   | 2 +-
 hw/misc/ivshmem.c           | 2 +-
 hw/riscv/riscv_htif.c       | 2 +-
 hw/riscv/sifive_uart.c      | 2 +-
 hw/usb/ccid-card-passthru.c | 2 +-
 hw/usb/dev-serial.c         | 2 +-
 hw/usb/redirect.c           | 2 +-
 include/qemu/main-loop.h    | 2 +-
 monitor.c                   | 2 +-
 net/colo-compare.c          | 2 +-
 net/filter-mirror.c         | 2 +-
 net/slirp.c                 | 2 +-
 qtest.c                     | 2 +-
 target/xtensa/xtensa-semi.c | 2 +-
 45 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index b51c01f664..4a9a92a8e7 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -48,11 +48,11 @@ static void rng_egd_request_entropy(RngBackend *b, RngRequest *req)
     }
 }
 
-static int rng_egd_chr_can_read(void *opaque)
+static size_t rng_egd_chr_can_read(void *opaque)
 {
     RngEgd *s = RNG_EGD(opaque);
     RngRequest *req;
-    int size = 0;
+    size_t size = 0;
 
     QSIMPLEQ_FOREACH(req, &s->parent.requests, next) {
         size += req->size - req->offset;
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index d8d6eaa646..98db12cf77 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -192,7 +192,7 @@ static void mux_chr_accept_input(Chardev *chr)
     }
 }
 
-static int mux_chr_can_read(void *opaque)
+static size_t mux_chr_can_read(void *opaque)
 {
     MuxChardev *d = MUX_CHARDEV(opaque);
     int m = d->focus;
diff --git a/gdbstub.c b/gdbstub.c
index a2fc3682ce..86d1fa62f8 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1916,7 +1916,7 @@ void gdbserver_fork(CPUState *cpu)
     cpu_watchpoint_remove_all(cpu, BP_GDB);
 }
 #else
-static int gdb_chr_can_receive(void *opaque)
+static size_t gdb_chr_can_receive(void *opaque)
 {
   /* We can handle an arbitrarily large amount of data.
    Pick the maximum packet size, which is as good as anything.  */
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index 75b6aa2772..a72d9bd4fe 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -1923,7 +1923,7 @@ static const MemoryRegionOps pxa2xx_fir_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int pxa2xx_fir_is_empty(void *opaque)
+static size_t pxa2xx_fir_is_empty(void *opaque)
 {
     PXA2xxFIrState *s = (PXA2xxFIrState *) opaque;
     return (s->rx_len < 64);
diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c
index 40db4e5e0a..6fdd4da3d0 100644
--- a/hw/arm/strongarm.c
+++ b/hw/arm/strongarm.c
@@ -1058,7 +1058,7 @@ static void strongarm_uart_rx_push(StrongARMUARTState *s, uint16_t c)
         s->rx_fifo[(s->rx_start + 11) % 12] |= RX_FIFO_ROR;
 }
 
-static int strongarm_uart_can_receive(void *opaque)
+static size_t strongarm_uart_can_receive(void *opaque)
 {
     StrongARMUARTState *s = opaque;
 
diff --git a/hw/char/bcm2835_aux.c b/hw/char/bcm2835_aux.c
index cb26df40f8..5dd1b652c0 100644
--- a/hw/char/bcm2835_aux.c
+++ b/hw/char/bcm2835_aux.c
@@ -211,7 +211,7 @@ static void bcm2835_aux_write(void *opaque, hwaddr offset, uint64_t value,
     bcm2835_aux_update(s);
 }
 
-static int bcm2835_aux_can_receive(void *opaque)
+static size_t bcm2835_aux_can_receive(void *opaque)
 {
     BCM2835AuxState *s = opaque;
 
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index eb5cc974a1..5835362038 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -216,10 +216,10 @@ static void uart_parameters_setup(CadenceUARTState *s)
     qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
 }
 
-static int uart_can_receive(void *opaque)
+static size_t uart_can_receive(void *opaque)
 {
     CadenceUARTState *s = opaque;
-    int ret = MAX(CADENCE_UART_RX_FIFO_SIZE, CADENCE_UART_TX_FIFO_SIZE);
+    size_t ret = MAX(CADENCE_UART_RX_FIFO_SIZE, CADENCE_UART_TX_FIFO_SIZE);
     uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
 
     if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
diff --git a/hw/char/cmsdk-apb-uart.c b/hw/char/cmsdk-apb-uart.c
index 774986d88d..c1437674a5 100644
--- a/hw/char/cmsdk-apb-uart.c
+++ b/hw/char/cmsdk-apb-uart.c
@@ -108,7 +108,7 @@ static void cmsdk_apb_uart_update(CMSDKAPBUART *s)
     qemu_set_irq(s->uartint, !!(s->intstatus));
 }
 
-static int uart_can_receive(void *opaque)
+static size_t uart_can_receive(void *opaque)
 {
     CMSDKAPBUART *s = CMSDK_APB_UART(opaque);
 
diff --git a/hw/char/digic-uart.c b/hw/char/digic-uart.c
index 0f41a23b54..f805ee5766 100644
--- a/hw/char/digic-uart.c
+++ b/hw/char/digic-uart.c
@@ -112,7 +112,7 @@ static const MemoryRegionOps uart_mmio_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int uart_can_rx(void *opaque)
+static size_t uart_can_rx(void *opaque)
 {
     DigicUartState *s = opaque;
 
diff --git a/hw/char/escc.c b/hw/char/escc.c
index e655b86273..decc35b990 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -166,7 +166,7 @@
 #define R_EXTINT 15
 
 static void handle_kbd_command(ESCCChannelState *s, int val);
-static int serial_can_receive(void *opaque);
+static size_t serial_can_receive(void *opaque);
 static void serial_receive_byte(ESCCChannelState *s, int ch);
 
 static void clear_queue(void *opaque)
@@ -573,10 +573,10 @@ static const MemoryRegionOps escc_mem_ops = {
     },
 };
 
-static int serial_can_receive(void *opaque)
+static size_t serial_can_receive(void *opaque)
 {
     ESCCChannelState *s = opaque;
-    int ret;
+    size_t ret;
 
     if (((s->wregs[W_RXCTRL] & RXCTRL_RXEN) == 0) // Rx not enabled
         || ((s->rregs[R_STATUS] & STATUS_RXAV) == STATUS_RXAV))
diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index 79cd8d2dc1..970f6a6e90 100644
--- a/hw/char/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -187,7 +187,7 @@ static void serial_receive(void *opaque, const uint8_t *buf, size_t size)
     ser_update_irq(s);
 }
 
-static int serial_can_receive(void *opaque)
+static size_t serial_can_receive(void *opaque)
 {
     ETRAXSerial *s = opaque;
 
diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index 5fdf5b1f37..b93edec08a 100644
--- a/hw/char/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -487,7 +487,7 @@ static const MemoryRegionOps exynos4210_uart_ops = {
     },
 };
 
-static int exynos4210_uart_can_receive(void *opaque)
+static size_t exynos4210_uart_can_receive(void *opaque)
 {
     Exynos4210UartState *s = (Exynos4210UartState *)opaque;
 
diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index d370609a52..7b57dce7fb 100644
--- a/hw/char/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
@@ -130,7 +130,7 @@ static void uart_add_to_fifo(UART          *uart,
     uart->len += length;
 }
 
-static int grlib_apbuart_can_receive(void *opaque)
+static size_t grlib_apbuart_can_receive(void *opaque)
 {
     UART *uart = opaque;
 
diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c
index b9fdfaeb38..abbe68571d 100644
--- a/hw/char/imx_serial.c
+++ b/hw/char/imx_serial.c
@@ -293,7 +293,7 @@ static void imx_serial_write(void *opaque, hwaddr offset,
     }
 }
 
-static int imx_can_receive(void *opaque)
+static size_t imx_can_receive(void *opaque)
 {
     IMXSerialState *s = (IMXSerialState *)opaque;
     return !(s->usr1 & USR1_RRDY);
diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c
index 08e3f9e45f..be21303dcd 100644
--- a/hw/char/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -461,10 +461,10 @@ static void mem_write8(IPackDevice *ip, uint32_t addr, uint8_t val)
     }
 }
 
-static int hostdev_can_receive(void *opaque)
+static size_t hostdev_can_receive(void *opaque)
 {
     SCC2698Channel *ch = opaque;
-    int available_bytes = RX_FIFO_SIZE - ch->rx_pending;
+    size_t available_bytes = RX_FIFO_SIZE - ch->rx_pending;
     return ch->rx_enabled ? available_bytes : 0;
 }
 
diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
index ecb61ee086..51e598c570 100644
--- a/hw/char/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -95,7 +95,7 @@ static void juart_rx(void *opaque, const uint8_t *buf, size_t size)
     s->jrx = *buf | JRX_FULL;
 }
 
-static int juart_can_rx(void *opaque)
+static size_t juart_can_rx(void *opaque)
 {
     LM32JuartState *s = opaque;
 
diff --git a/hw/char/lm32_uart.c b/hw/char/lm32_uart.c
index ee0bf8e117..2593434f8f 100644
--- a/hw/char/lm32_uart.c
+++ b/hw/char/lm32_uart.c
@@ -225,7 +225,7 @@ static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
     uart_update_irq(s);
 }
 
-static int uart_can_rx(void *opaque)
+static size_t uart_can_rx(void *opaque)
 {
     LM32UartState *s = opaque;
 
diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c
index e126860b46..cd9c499a51 100644
--- a/hw/char/mcf_uart.c
+++ b/hw/char/mcf_uart.c
@@ -267,7 +267,7 @@ static void mcf_uart_event(void *opaque, int event)
     }
 }
 
-static int mcf_uart_can_receive(void *opaque)
+static size_t mcf_uart_can_receive(void *opaque)
 {
     mcf_uart_state *s = (mcf_uart_state *)opaque;
 
diff --git a/hw/char/milkymist-uart.c b/hw/char/milkymist-uart.c
index a10c0957ff..0efcd829ce 100644
--- a/hw/char/milkymist-uart.c
+++ b/hw/char/milkymist-uart.c
@@ -170,7 +170,7 @@ static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
     uart_update_irq(s);
 }
 
-static int uart_can_rx(void *opaque)
+static size_t uart_can_rx(void *opaque)
 {
     MilkymistUartState *s = opaque;
 
diff --git a/hw/char/parallel.c b/hw/char/parallel.c
index a80da47ecf..fe0e5c8756 100644
--- a/hw/char/parallel.c
+++ b/hw/char/parallel.c
@@ -513,7 +513,7 @@ static const VMStateDescription vmstate_parallel_isa = {
     }
 };
 
-static int parallel_can_receive(void *opaque)
+static size_t parallel_can_receive(void *opaque)
 {
      return 1;
 }
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index 37973c32ce..10195679b4 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -224,10 +224,10 @@ static void pl011_write(void *opaque, hwaddr offset,
     }
 }
 
-static int pl011_can_receive(void *opaque)
+static size_t pl011_can_receive(void *opaque)
 {
     PL011State *s = (PL011State *)opaque;
-    int r;
+    size_t r;
 
     if (s->lcr & 0x10) {
         r = s->read_count < 16;
diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
index a04a2a9d80..ad5f791227 100644
--- a/hw/char/sclpconsole-lm.c
+++ b/hw/char/sclpconsole-lm.c
@@ -61,7 +61,7 @@ typedef struct SCLPConsoleLM {
  * truncated to the guest in case it doesn't fit into the SCCB.
  */
 
-static int chr_can_read(void *opaque)
+static size_t chr_can_read(void *opaque)
 {
     SCLPConsoleLM *scon = opaque;
 
diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c
index 62395c19f4..5ec1c4b607 100644
--- a/hw/char/sclpconsole.c
+++ b/hw/char/sclpconsole.c
@@ -47,10 +47,10 @@ typedef struct SCLPConsole {
 /* character layer call-back functions */
 
 /* Return number of bytes that fit into iov buffer */
-static int chr_can_read(void *opaque)
+static size_t chr_can_read(void *opaque)
 {
     SCLPConsole *scon = opaque;
-    int avail = SIZE_BUFFER_VT220 - scon->iov_data_len;
+    size_t avail = SIZE_BUFFER_VT220 - scon->iov_data_len;
 
     if (avail == 0) {
         scon->notify = true;
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 69baed105b..f83bb8ee4e 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -561,7 +561,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr addr, unsigned size)
     return ret;
 }
 
-static int serial_can_receive(SerialState *s)
+static size_t serial_can_receive(SerialState *s)
 {
     if(s->fcr & UART_FCR_FE) {
         if (s->recv_fifo.num < UART_FIFO_LENGTH) {
@@ -600,7 +600,7 @@ static void fifo_timeout_int (void *opaque) {
     }
 }
 
-static int serial_can_receive1(void *opaque)
+static size_t serial_can_receive1(void *opaque)
 {
     SerialState *s = opaque;
     return serial_can_receive(s);
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c
index 04fdcee328..f5402d3b5c 100644
--- a/hw/char/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -300,7 +300,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,
     return ret;
 }
 
-static int sh_serial_can_receive(sh_serial_state *s)
+static size_t sh_serial_can_receive(sh_serial_state *s)
 {
     return s->scr & (1 << 4);
 }
@@ -311,7 +311,7 @@ static void sh_serial_receive_break(sh_serial_state *s)
         s->sr |= (1 << 4);
 }
 
-static int sh_serial_can_receive1(void *opaque)
+static size_t sh_serial_can_receive1(void *opaque)
 {
     sh_serial_state *s = opaque;
     return sh_serial_can_receive(s);
diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
index 42b4b61cce..0ac9dc8448 100644
--- a/hw/char/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -21,7 +21,7 @@ typedef struct VIOsPAPRVTYDevice {
 #define VIO_SPAPR_VTY_DEVICE(obj) \
      OBJECT_CHECK(VIOsPAPRVTYDevice, (obj), TYPE_VIO_SPAPR_VTY_DEVICE)
 
-static int vty_can_receive(void *opaque)
+static size_t vty_can_receive(void *opaque)
 {
     VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(opaque);
 
diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c
index 78bf142678..63256da77b 100644
--- a/hw/char/stm32f2xx_usart.c
+++ b/hw/char/stm32f2xx_usart.c
@@ -38,7 +38,7 @@
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
-static int stm32f2xx_usart_can_receive(void *opaque)
+static size_t stm32f2xx_usart_can_receive(void *opaque)
 {
     STM32F2XXUsartState *s = opaque;
 
diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c
index 076516991e..a9db0a3401 100644
--- a/hw/char/terminal3270.c
+++ b/hw/char/terminal3270.c
@@ -38,7 +38,7 @@ typedef struct Terminal3270 {
 #define TERMINAL_3270(obj) \
         OBJECT_CHECK(Terminal3270, (obj), TYPE_TERMINAL_3270)
 
-static int terminal_can_read(void *opaque)
+static size_t terminal_can_read(void *opaque)
 {
     Terminal3270 *t = opaque;
 
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index e3d368b976..b942159d82 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -126,7 +126,7 @@ static void guest_writable(VirtIOSerialPort *port)
 }
 
 /* Readiness of the guest to accept data on a port */
-static int chr_can_read(void *opaque)
+static size_t chr_can_read(void *opaque)
 {
     VirtConsole *vcon = opaque;
 
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index ca90c5c17e..0a1cbaeafa 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -116,7 +116,7 @@ static int ring_free_bytes(struct XenConsole *con)
     return (sizeof(intf->in) - space);
 }
 
-static int xencons_can_receive(void *opaque)
+static size_t xencons_can_receive(void *opaque)
 {
     struct XenConsole *con = opaque;
     return ring_free_bytes(con);
diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c
index b1abf8b604..2473cb0ad7 100644
--- a/hw/char/xilinx_uartlite.c
+++ b/hw/char/xilinx_uartlite.c
@@ -195,7 +195,7 @@ static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
     uart_update_irq(s);
 }
 
-static int uart_can_rx(void *opaque)
+static size_t uart_can_rx(void *opaque)
 {
     XilinxUARTLite *s = opaque;
 
diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index c52f80f771..7107d2fe9f 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -307,7 +307,7 @@ static void handle_msg(IPMIBmcExtern *ibe)
     k->handle_rsp(ibe->parent.intf, ibe->inbuf[0], ibe->inbuf + 1, ibe->inpos - 1);
 }
 
-static int can_receive(void *opaque)
+static size_t can_receive(void *opaque)
 {
     return 1;
 }
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index f506479845..01b331aaab 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -620,7 +620,7 @@ static void process_msg(IVShmemState *s, int64_t msg, int fd, Error **errp)
     }
 }
 
-static int ivshmem_can_receive(void *opaque)
+static size_t ivshmem_can_receive(void *opaque)
 {
     IVShmemState *s = opaque;
 
diff --git a/hw/riscv/riscv_htif.c b/hw/riscv/riscv_htif.c
index 2625f5e9e8..565120df7d 100644
--- a/hw/riscv/riscv_htif.c
+++ b/hw/riscv/riscv_htif.c
@@ -65,7 +65,7 @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
 /*
  * Called by the char dev to see if HTIF is ready to accept input.
  */
-static int htif_can_recv(void *opaque)
+static size_t htif_can_recv(void *opaque)
 {
     return 1;
 }
diff --git a/hw/riscv/sifive_uart.c b/hw/riscv/sifive_uart.c
index d4cbf91b9f..c6a8f5fbc4 100644
--- a/hw/riscv/sifive_uart.c
+++ b/hw/riscv/sifive_uart.c
@@ -137,7 +137,7 @@ static void uart_rx(void *opaque, const uint8_t *buf, size_t size)
     update_irq(s);
 }
 
-static int uart_can_rx(void *opaque)
+static size_t uart_can_rx(void *opaque)
 {
     SiFiveUARTState *s = opaque;
 
diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index b6fa35a4b4..5dc10ef850 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -112,7 +112,7 @@ static void ccid_card_vscard_send_init(PassthruState *s)
                          (uint8_t *)&msg, sizeof(msg));
 }
 
-static int ccid_card_vscard_can_read(void *opaque)
+static size_t ccid_card_vscard_can_read(void *opaque)
 {
     PassthruState *card = opaque;
 
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index efaeab484d..e9735d4b5d 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -421,7 +421,7 @@ static void usb_serial_handle_data(USBDevice *dev, USBPacket *p)
     }
 }
 
-static int usb_serial_can_read(void *opaque)
+static size_t usb_serial_can_read(void *opaque)
 {
     USBSerialState *s = opaque;
 
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index a73076ba78..f025c91d28 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1284,7 +1284,7 @@ static void usbredir_do_attach(void *opaque)
  * chardev callbacks
  */
 
-static int usbredir_chardev_can_read(void *opaque)
+static size_t usbredir_chardev_can_read(void *opaque)
 {
     USBRedirDevice *dev = opaque;
 
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index c5a7299266..b51f9a5267 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -182,7 +182,7 @@ typedef void IOReadHandler(void *opaque, const uint8_t *buf, size_t size);
  * is called again.  aio_notify() or qemu_notify_event() can be used to kick
  * the event loop.
  */
-typedef int IOCanReadHandler(void *opaque);
+typedef size_t IOCanReadHandler(void *opaque);
 
 /**
  * qemu_set_fd_handler: Register a file descriptor with the main loop
diff --git a/monitor.c b/monitor.c
index 12401ec60b..3417c5f044 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4038,7 +4038,7 @@ cleanup:
     free_cmdline_args(args, nb_args);
 }
 
-static int monitor_can_read(void *opaque)
+static size_t monitor_can_read(void *opaque)
 {
     Monitor *mon = opaque;
 
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 433e9ba287..9321d81a98 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -683,7 +683,7 @@ err:
     return ret < 0 ? ret : -EIO;
 }
 
-static int compare_chr_can_read(void *opaque)
+static size_t compare_chr_can_read(void *opaque)
 {
     return COMPARE_READ_LEN_MAX;
 }
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index 27b6e52a1d..8e16535fad 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -114,7 +114,7 @@ static void redirector_to_filter(NetFilterState *nf,
      }
 }
 
-static int redirector_chr_can_read(void *opaque)
+static size_t redirector_chr_can_read(void *opaque)
 {
     return REDIRECTOR_MAX_LEN;
 }
diff --git a/net/slirp.c b/net/slirp.c
index 5e864f4a4f..9dbcaffb07 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -712,7 +712,7 @@ struct GuestFwd {
     Slirp *slirp;
 };
 
-static int guestfwd_can_read(void *opaque)
+static size_t guestfwd_can_read(void *opaque)
 {
     struct GuestFwd *fwd = opaque;
     return slirp_socket_can_recv(fwd->slirp, fwd->server, fwd->port);
diff --git a/qtest.c b/qtest.c
index 0494afdfb3..bc685700cd 100644
--- a/qtest.c
+++ b/qtest.c
@@ -665,7 +665,7 @@ static void qtest_read(void *opaque, const uint8_t *buf, size_t size)
     qtest_process_inbuf(chr, inbuf);
 }
 
-static int qtest_can_read(void *opaque)
+static size_t qtest_can_read(void *opaque)
 {
     return 1024;
 }
diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index 241874ea4e..a57e61ef4a 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -161,7 +161,7 @@ typedef struct XtensaSimConsole {
 
 static XtensaSimConsole *sim_console;
 
-static int sim_console_can_read(void *opaque)
+static size_t sim_console_can_read(void *opaque)
 {
     XtensaSimConsole *p = opaque;
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 09/11] chardev: Let qemu_chr_fe_* use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 08/11] chardev: Let IOCanReadHandler " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* " Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Marc-André Lureau

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char-fe.c         | 8 ++++----
 chardev/char-win-stdio.c  | 2 +-
 chardev/char-win.c        | 2 +-
 include/chardev/char-fe.h | 6 +++---
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index a8931f7afd..b732f6566b 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -31,7 +31,7 @@
 #include "chardev/char-io.h"
 #include "chardev/char-mux.h"
 
-int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
+size_t qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, size_t len)
 {
     Chardev *s = be->chr;
 
@@ -42,7 +42,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
     return qemu_chr_write(s, buf, len, false);
 }
 
-int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
+size_t qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, size_t len)
 {
     Chardev *s = be->chr;
 
@@ -53,10 +53,10 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
     return qemu_chr_write(s, buf, len, true);
 }
 
-int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
+size_t qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, size_t len)
 {
     Chardev *s = be->chr;
-    int offset = 0;
+    size_t offset = 0;
     int res;
 
     if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) {
diff --git a/chardev/char-win-stdio.c b/chardev/char-win-stdio.c
index efcf7827eb..6b1a97144b 100644
--- a/chardev/char-win-stdio.c
+++ b/chardev/char-win-stdio.c
@@ -221,7 +221,7 @@ static void char_win_stdio_finalize(Object *obj)
     }
 }
 
-static int win_stdio_write(Chardev *chr, const uint8_t *buf, int len)
+static size_t win_stdio_write(Chardev *chr, const uint8_t *buf, size_t len)
 {
     HANDLE  hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
     DWORD   dwSize;
diff --git a/chardev/char-win.c b/chardev/char-win.c
index 05518e0958..7ea7d0a371 100644
--- a/chardev/char-win.c
+++ b/chardev/char-win.c
@@ -152,7 +152,7 @@ int win_chr_pipe_poll(void *opaque)
 }
 
 /* Called with chr_write_lock held.  */
-static int win_chr_write(Chardev *chr, const uint8_t *buf, int len1)
+static size_t win_chr_write(Chardev *chr, const uint8_t *buf, size_t len1)
 {
     WinChardev *s = WIN_CHARDEV(chr);
     DWORD len, ret, size, err;
diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index 46c997d352..2f95c890d8 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -184,7 +184,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
  *
  * Returns: the number of bytes consumed (0 if no associated Chardev)
  */
-int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
+size_t qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, size_t len);
 
 /**
  * qemu_chr_fe_write_all:
@@ -198,7 +198,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
  *
  * Returns: the number of bytes consumed (0 if no associated Chardev)
  */
-int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
+size_t qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, size_t len);
 
 /**
  * qemu_chr_fe_read_all:
@@ -209,7 +209,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
  *
  * Returns: the number of bytes read (0 if no associated Chardev)
  */
-int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);
+size_t qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, size_t len);
 
 /**
  * qemu_chr_fe_ioctl:
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 09/11] chardev: Let qemu_chr_fe_* " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  6:43   ` Pavel Dovgalyuk
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned Philippe Mathieu-Daudé
  2018-10-12  8:20 ` [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Daniel P. Berrangé
  11 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, Marc-André Lureau, Pavel Dovgalyuk

Since IOCanReadHandler now returns an unsigned value, the assertion
does not make sense anymore.  We choose however to keep a "fail-safe"
assertion to catch undesired overflows.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char.c          | 17 +++++++++--------
 include/chardev/char.h  |  9 +++++----
 include/sysemu/replay.h |  8 ++++----
 replay/replay-char.c    |  8 ++++----
 stubs/replay.c          |  8 ++++----
 5 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/chardev/char.c b/chardev/char.c
index 608c2569f4..ef6d07e132 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -100,7 +100,7 @@ static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
 
 static int qemu_chr_write_buffer(Chardev *s,
                                  const uint8_t *buf, int len,
-                                 int *offset, bool write_all)
+                                 size_t *offset, bool write_all)
 {
     ChardevClass *cc = CHARDEV_GET_CLASS(s);
     int res = 0;
@@ -132,9 +132,10 @@ static int qemu_chr_write_buffer(Chardev *s,
     return res;
 }
 
-int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
+size_t qemu_chr_write(Chardev *s, const uint8_t *buf, size_t len,
+                      bool write_all)
 {
-    int offset = 0;
+    size_t offset = 0;
     int res;
 
     if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
@@ -156,21 +157,21 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
     return offset;
 }
 
-int qemu_chr_be_can_write(Chardev *s)
+size_t qemu_chr_be_can_write(Chardev *s)
 {
     CharBackend *be = s->be;
-    int res;
+    size_t res;
 
     if (!be || !be->chr_can_read) {
         return 0;
     }
 
     res = be->chr_can_read(be->opaque);
-    assert(res >= 0);
+    assert((ssize_t)res >= 0); /* "fail-safe" assertion */
     return res;
 }
 
-void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
+void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, size_t len)
 {
     CharBackend *be = s->be;
 
@@ -179,7 +180,7 @@ void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
     }
 }
 
-void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len)
+void qemu_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
 {
     if (qemu_chr_replay(s)) {
         if (replay_mode == REPLAY_MODE_PLAY) {
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 091a514022..65f93adbd6 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -163,7 +163,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
  *
  * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
  */
-int qemu_chr_be_can_write(Chardev *s);
+size_t qemu_chr_be_can_write(Chardev *s);
 
 /**
  * qemu_chr_be_write:
@@ -174,7 +174,7 @@ int qemu_chr_be_can_write(Chardev *s);
  * the caller should call @qemu_chr_be_can_write to determine how much data
  * the front end can currently accept.
  */
-void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);
+void qemu_chr_be_write(Chardev *s, uint8_t *buf, size_t len);
 
 /**
  * qemu_chr_be_write_impl:
@@ -183,7 +183,7 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);
  *
  * Implementation of back end writing. Used by replay module.
  */
-void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len);
+void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, size_t len);
 
 /**
  * qemu_chr_be_update_read_handlers:
@@ -211,7 +211,8 @@ void qemu_chr_set_feature(Chardev *chr,
                           ChardevFeature feature);
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
                                 bool permit_mux_mon);
-int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
+size_t qemu_chr_write(Chardev *s, const uint8_t *buf, size_t len,
+                      bool write_all);
 #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
 int qemu_chr_wait_connected(Chardev *chr, Error **errp);
 
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index 7f7a594eca..0856b66888 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -148,17 +148,17 @@ uint64_t blkreplay_next_id(void);
 /*! Registers char driver to save it's events */
 void replay_register_char_driver(struct Chardev *chr);
 /*! Saves write to char device event to the log */
-void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);
+void replay_chr_be_write(struct Chardev *s, uint8_t *buf, size_t len);
 /*! Writes char write return value to the replay log. */
-void replay_char_write_event_save(int res, int offset);
+void replay_char_write_event_save(int res, size_t offset);
 /*! Reads char write return value from the replay log. */
-void replay_char_write_event_load(int *res, int *offset);
+void replay_char_write_event_load(int *res, size_t *offset);
 /*! Reads information about read_all character event. */
 int replay_char_read_all_load(uint8_t *buf);
 /*! Writes character read_all error code into the replay log. */
 void replay_char_read_all_save_error(int res);
 /*! Writes character read_all execution result into the replay log. */
-void replay_char_read_all_save_buf(uint8_t *buf, int offset);
+void replay_char_read_all_save_buf(uint8_t *buf, size_t offset);
 
 /* Network */
 
diff --git a/replay/replay-char.c b/replay/replay-char.c
index 736cc8c2e6..9c4ec3c794 100644
--- a/replay/replay-char.c
+++ b/replay/replay-char.c
@@ -49,7 +49,7 @@ void replay_register_char_driver(Chardev *chr)
     char_drivers[drivers_count++] = chr;
 }
 
-void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
+void replay_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
 {
     CharEvent *event = g_malloc0(sizeof(CharEvent));
 
@@ -94,7 +94,7 @@ void *replay_event_char_read_load(void)
     return event;
 }
 
-void replay_char_write_event_save(int res, int offset)
+void replay_char_write_event_save(int res, size_t offset)
 {
     g_assert(replay_mutex_locked());
 
@@ -104,7 +104,7 @@ void replay_char_write_event_save(int res, int offset)
     replay_put_dword(offset);
 }
 
-void replay_char_write_event_load(int *res, int *offset)
+void replay_char_write_event_load(int *res, size_t *offset)
 {
     g_assert(replay_mutex_locked());
 
@@ -150,7 +150,7 @@ void replay_char_read_all_save_error(int res)
     replay_put_dword(res);
 }
 
-void replay_char_read_all_save_buf(uint8_t *buf, int offset)
+void replay_char_read_all_save_buf(uint8_t *buf, size_t offset)
 {
     g_assert(replay_mutex_locked());
     replay_save_instructions();
diff --git a/stubs/replay.c b/stubs/replay.c
index 04279abb2c..030f508aef 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -34,17 +34,17 @@ void replay_register_char_driver(Chardev *chr)
 {
 }
 
-void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
+void replay_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
 {
     abort();
 }
 
-void replay_char_write_event_save(int res, int offset)
+void replay_char_write_event_save(int res, size_t offset)
 {
     abort();
 }
 
-void replay_char_write_event_load(int *res, int *offset)
+void replay_char_write_event_load(int *res, size_t *offset)
 {
     abort();
 }
@@ -59,7 +59,7 @@ void replay_char_read_all_save_error(int res)
     abort();
 }
 
-void replay_char_read_all_save_buf(uint8_t *buf, int offset)
+void replay_char_read_all_save_buf(uint8_t *buf, size_t offset)
 {
     abort();
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* " Philippe Mathieu-Daudé
@ 2018-10-12  0:22 ` Philippe Mathieu-Daudé
  2018-10-12  8:05   ` Paolo Bonzini
  2018-10-12  8:20 ` [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Daniel P. Berrangé
  11 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-12  0:22 UTC (permalink / raw)
  To: Paolo Bonzini, Prasad J Pandit
  Cc: Philippe Mathieu-Daudé, qemu-devel, Marc-André Lureau

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char-fd.c         | 2 +-
 include/chardev/char-fd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-fd.c b/chardev/char-fd.c
index bb426fa4b1..900da2f935 100644
--- a/chardev/char-fd.c
+++ b/chardev/char-fd.c
@@ -43,7 +43,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
     FDChardev *s = FD_CHARDEV(opaque);
-    int len;
+    size_t len;
     uint8_t buf[CHR_READ_BUF_LEN];
     ssize_t ret;
 
diff --git a/include/chardev/char-fd.h b/include/chardev/char-fd.h
index e7c2b176f9..36c6b89cee 100644
--- a/include/chardev/char-fd.h
+++ b/include/chardev/char-fd.h
@@ -31,7 +31,7 @@ typedef struct FDChardev {
     Chardev parent;
 
     QIOChannel *ioc_in, *ioc_out;
-    int max_size;
+    size_t max_size;
 } FDChardev;
 
 #define TYPE_CHARDEV_FD "chardev-fd"
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations Philippe Mathieu-Daudé
@ 2018-10-12  0:51   ` Corey Minyard
  0 siblings, 0 replies; 20+ messages in thread
From: Corey Minyard @ 2018-10-12  0:51 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Paolo Bonzini, Prasad J Pandit; +Cc: qemu-devel

On 10/11/2018 07:22 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   hw/ipmi/ipmi_bmc_extern.c | 4 ----
>   1 file changed, 4 deletions(-)
>
> diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
> index bf0b7ee0f5..8c78b9804b 100644
> --- a/hw/ipmi/ipmi_bmc_extern.c
> +++ b/hw/ipmi/ipmi_bmc_extern.c
> @@ -85,10 +85,6 @@ typedef struct IPMIBmcExtern {
>       bool send_reset;
>   } IPMIBmcExtern;
>   
> -static int can_receive(void *opaque);
> -static void receive(void *opaque, const uint8_t *buf, int size);
> -static void chr_event(void *opaque, int event);
> -
>   static unsigned char
>   ipmb_checksum(const unsigned char *data, int size, unsigned char start)
>   {

Looks good to me.  Thanks.

Acked-by: Corey Minyard <cminyard@mvista.com>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* use unsigned type
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* " Philippe Mathieu-Daudé
@ 2018-10-12  6:43   ` Pavel Dovgalyuk
  0 siblings, 0 replies; 20+ messages in thread
From: Pavel Dovgalyuk @ 2018-10-12  6:43 UTC (permalink / raw)
  To: 'Philippe Mathieu-Daudé', 'Paolo Bonzini',
	'Prasad J Pandit'
  Cc: qemu-devel, 'Marc-André Lureau', 'Pavel Dovgalyuk'

> From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> Since IOCanReadHandler now returns an unsigned value, the assertion
> does not make sense anymore.  We choose however to keep a "fail-safe"
> assertion to catch undesired overflows.
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  chardev/char.c          | 17 +++++++++--------
>  include/chardev/char.h  |  9 +++++----
>  include/sysemu/replay.h |  8 ++++----
>  replay/replay-char.c    |  8 ++++----
>  stubs/replay.c          |  8 ++++----
>  5 files changed, 26 insertions(+), 24 deletions(-)
> 
> diff --git a/chardev/char.c b/chardev/char.c
> index 608c2569f4..ef6d07e132 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -100,7 +100,7 @@ static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
> 
>  static int qemu_chr_write_buffer(Chardev *s,
>                                   const uint8_t *buf, int len,
> -                                 int *offset, bool write_all)
> +                                 size_t *offset, bool write_all)
>  {
>      ChardevClass *cc = CHARDEV_GET_CLASS(s);
>      int res = 0;
> @@ -132,9 +132,10 @@ static int qemu_chr_write_buffer(Chardev *s,
>      return res;
>  }
> 
> -int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
> +size_t qemu_chr_write(Chardev *s, const uint8_t *buf, size_t len,
> +                      bool write_all)
>  {
> -    int offset = 0;
> +    size_t offset = 0;
>      int res;
> 
>      if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
> @@ -156,21 +157,21 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool
> write_all)
>      return offset;
>  }
> 
> -int qemu_chr_be_can_write(Chardev *s)
> +size_t qemu_chr_be_can_write(Chardev *s)
>  {
>      CharBackend *be = s->be;
> -    int res;
> +    size_t res;
> 
>      if (!be || !be->chr_can_read) {
>          return 0;
>      }
> 
>      res = be->chr_can_read(be->opaque);
> -    assert(res >= 0);
> +    assert((ssize_t)res >= 0); /* "fail-safe" assertion */
>      return res;
>  }
> 
> -void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
> +void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, size_t len)
>  {
>      CharBackend *be = s->be;
> 
> @@ -179,7 +180,7 @@ void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len)
>      }
>  }
> 
> -void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len)
> +void qemu_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
>  {
>      if (qemu_chr_replay(s)) {
>          if (replay_mode == REPLAY_MODE_PLAY) {
> diff --git a/include/chardev/char.h b/include/chardev/char.h
> index 091a514022..65f93adbd6 100644
> --- a/include/chardev/char.h
> +++ b/include/chardev/char.h
> @@ -163,7 +163,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
>   *
>   * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
>   */
> -int qemu_chr_be_can_write(Chardev *s);
> +size_t qemu_chr_be_can_write(Chardev *s);
> 
>  /**
>   * qemu_chr_be_write:
> @@ -174,7 +174,7 @@ int qemu_chr_be_can_write(Chardev *s);
>   * the caller should call @qemu_chr_be_can_write to determine how much data
>   * the front end can currently accept.
>   */
> -void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);
> +void qemu_chr_be_write(Chardev *s, uint8_t *buf, size_t len);
> 
>  /**
>   * qemu_chr_be_write_impl:
> @@ -183,7 +183,7 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);
>   *
>   * Implementation of back end writing. Used by replay module.
>   */
> -void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len);
> +void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, size_t len);
> 
>  /**
>   * qemu_chr_be_update_read_handlers:
> @@ -211,7 +211,8 @@ void qemu_chr_set_feature(Chardev *chr,
>                            ChardevFeature feature);
>  QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
>                                  bool permit_mux_mon);
> -int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
> +size_t qemu_chr_write(Chardev *s, const uint8_t *buf, size_t len,
> +                      bool write_all);
>  #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
>  int qemu_chr_wait_connected(Chardev *chr, Error **errp);
> 
> diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
> index 7f7a594eca..0856b66888 100644
> --- a/include/sysemu/replay.h
> +++ b/include/sysemu/replay.h
> @@ -148,17 +148,17 @@ uint64_t blkreplay_next_id(void);
>  /*! Registers char driver to save it's events */
>  void replay_register_char_driver(struct Chardev *chr);
>  /*! Saves write to char device event to the log */
> -void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);
> +void replay_chr_be_write(struct Chardev *s, uint8_t *buf, size_t len);
>  /*! Writes char write return value to the replay log. */
> -void replay_char_write_event_save(int res, int offset);
> +void replay_char_write_event_save(int res, size_t offset);
>  /*! Reads char write return value from the replay log. */
> -void replay_char_write_event_load(int *res, int *offset);
> +void replay_char_write_event_load(int *res, size_t *offset);
>  /*! Reads information about read_all character event. */
>  int replay_char_read_all_load(uint8_t *buf);
>  /*! Writes character read_all error code into the replay log. */
>  void replay_char_read_all_save_error(int res);
>  /*! Writes character read_all execution result into the replay log. */
> -void replay_char_read_all_save_buf(uint8_t *buf, int offset);
> +void replay_char_read_all_save_buf(uint8_t *buf, size_t offset);
> 
>  /* Network */
> 
> diff --git a/replay/replay-char.c b/replay/replay-char.c
> index 736cc8c2e6..9c4ec3c794 100644
> --- a/replay/replay-char.c
> +++ b/replay/replay-char.c
> @@ -49,7 +49,7 @@ void replay_register_char_driver(Chardev *chr)
>      char_drivers[drivers_count++] = chr;
>  }
> 
> -void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
> +void replay_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
>  {
>      CharEvent *event = g_malloc0(sizeof(CharEvent));
> 
> @@ -94,7 +94,7 @@ void *replay_event_char_read_load(void)
>      return event;
>  }
> 
> -void replay_char_write_event_save(int res, int offset)
> +void replay_char_write_event_save(int res, size_t offset)
>  {
>      g_assert(replay_mutex_locked());
> 
> @@ -104,7 +104,7 @@ void replay_char_write_event_save(int res, int offset)
>      replay_put_dword(offset);
>  }
> 
> -void replay_char_write_event_load(int *res, int *offset)
> +void replay_char_write_event_load(int *res, size_t *offset)
>  {
>      g_assert(replay_mutex_locked());
> 
> @@ -150,7 +150,7 @@ void replay_char_read_all_save_error(int res)
>      replay_put_dword(res);
>  }
> 
> -void replay_char_read_all_save_buf(uint8_t *buf, int offset)
> +void replay_char_read_all_save_buf(uint8_t *buf, size_t offset)
>  {
>      g_assert(replay_mutex_locked());
>      replay_save_instructions();
> diff --git a/stubs/replay.c b/stubs/replay.c
> index 04279abb2c..030f508aef 100644
> --- a/stubs/replay.c
> +++ b/stubs/replay.c
> @@ -34,17 +34,17 @@ void replay_register_char_driver(Chardev *chr)
>  {
>  }
> 
> -void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
> +void replay_chr_be_write(Chardev *s, uint8_t *buf, size_t len)
>  {
>      abort();
>  }
> 
> -void replay_char_write_event_save(int res, int offset)
> +void replay_char_write_event_save(int res, size_t offset)
>  {
>      abort();
>  }
> 
> -void replay_char_write_event_load(int *res, int *offset)
> +void replay_char_write_event_load(int *res, size_t *offset)
>  {
>      abort();
>  }
> @@ -59,7 +59,7 @@ void replay_char_read_all_save_error(int res)
>      abort();
>  }
> 
> -void replay_char_read_all_save_buf(uint8_t *buf, int offset)
> +void replay_char_read_all_save_buf(uint8_t *buf, size_t offset)
>  {
>      abort();
>  }
> --
> 2.17.1


What about casting to int here:

void replay_event_char_read_run(void *opaque)
{
    CharEvent *event = (CharEvent *)opaque;

    qemu_chr_be_write_impl(char_drivers[event->id], event->buf,
                           (int)event->len);

    g_free(event->buf);
    g_free(event);
}



Pavel Dovgalyuk

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned Philippe Mathieu-Daudé
@ 2018-10-12  8:05   ` Paolo Bonzini
  0 siblings, 0 replies; 20+ messages in thread
From: Paolo Bonzini @ 2018-10-12  8:05 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Prasad J Pandit
  Cc: qemu-devel, Marc-André Lureau

On 12/10/2018 02:22, Philippe Mathieu-Daudé wrote:
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  chardev/char-fd.c         | 2 +-
>  include/chardev/char-fd.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/chardev/char-fd.c b/chardev/char-fd.c
> index bb426fa4b1..900da2f935 100644
> --- a/chardev/char-fd.c
> +++ b/chardev/char-fd.c
> @@ -43,7 +43,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)
>  {
>      Chardev *chr = CHARDEV(opaque);
>      FDChardev *s = FD_CHARDEV(opaque);
> -    int len;
> +    size_t len;
>      uint8_t buf[CHR_READ_BUF_LEN];
>      ssize_t ret;
>  
> diff --git a/include/chardev/char-fd.h b/include/chardev/char-fd.h
> index e7c2b176f9..36c6b89cee 100644
> --- a/include/chardev/char-fd.h
> +++ b/include/chardev/char-fd.h
> @@ -31,7 +31,7 @@ typedef struct FDChardev {
>      Chardev parent;
>  
>      QIOChannel *ioc_in, *ioc_out;
> -    int max_size;
> +    size_t max_size;
>  } FDChardev;
>  
>  #define TYPE_CHARDEV_FD "chardev-fd"
> 

This shouldn't be just for max_size, it should be for all variables that
are set in the *_read_poll functions (those that you touch in patch 3).

These variables are than used very little, basically only in a

    len = MAX(s->max_size, sizeof(buf))

statement, so this switch is safe.  However, the order of the patches
should be first 4, then this one (the assertion shows that the switch to
unsigned is safe), then 5-6-9-10, then 7-8.  If you convert
implementations before users, the users could in principle overflow
"int" when passing an arguments or storing its value.

All this of course should be documented in commit messages, which are a
bit... scant in this series. :)  I'm usually okay with very short commit
messages when the changes are spread across many commits (in that case,
I usually document what all the repetitive changes are in the patches
before and/or after those changes), but in this case you are leaving out
completely the "why" for the changes, and that's not really a good idea.

Finally, can you please include a patch to adjust the assertions in the
USB smartcard code, as mentioned in my original reply to Prasad?

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type
  2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned Philippe Mathieu-Daudé
@ 2018-10-12  8:20 ` Daniel P. Berrangé
  11 siblings, 0 replies; 20+ messages in thread
From: Daniel P. Berrangé @ 2018-10-12  8:20 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Paolo Bonzini, Prasad J Pandit, qemu-devel

On Fri, Oct 12, 2018 at 02:22:06AM +0200, Philippe Mathieu-Daudé wrote:
> Hi Paolo,
> 
> Here are the changes you suggested in
> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.html
> 
> First two simple cleanups while here,
> then slowly convert backends then frontends.
> 
> Regards,
> 
> Phil.
> 
> Philippe Mathieu-Daudé (11):
>   hw/ipmi: Remove unnecessary declarations
>   target/xtensa: Remove unnecessary declarations
>   chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
>   chardev: Assert backend's chr_can_read() is positive
>   chardev: Let chr_sync_read() use unsigned type
>   chardev: Let chr_write use unsigned type
>   chardev: Let IOReadHandler use unsigned type
>   chardev: Let IOCanReadHandler use unsigned type
>   chardev: Let qemu_chr_fe_* use unsigned type
>   chardev: Let qemu_chr_be_* use unsigned type
>   chardev: FDChardev::max_size be unsigned

s/unsigned/size_t/ in all these commit messages, as it looked
like you meant 'unsigned int' with the current commit msg.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler use unsigned type
  2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler " Philippe Mathieu-Daudé
@ 2021-01-22 11:26   ` Richard Purdie
  2021-01-22 11:52     ` P J P
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Purdie @ 2021-01-22 11:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Paolo Bonzini, Prasad J Pandit
  Cc: Peter Maydell, Li Zhijian, Michael S. Tsirkin, Jan Kiszka,
	Jason Wang, Palmer Dabbelt, qemu-devel, Alexander Graf,
	Max Filippov, Michael Clark, Gerd Hoffmann, Edgar E. Iglesias,
	Stefano Stabellini, Alberto Garcia, Sagar Karandikar,
	Markus Armbruster, Christian Borntraeger, Antony Pavlov,
	Anthony Perard, Marc-André Lureau, Samuel Thibault,
	Laurent Vivier, Corey Minyard, Amit Shah, Alistair Francis,
	Dr. David Alan Gilbert, Fabien Chouteau, Peter Chubb, Zhang Chen,
	David Gibson, Igor Mitsyanko, Bastian Koppelmann, Cornelia Huck,
	Thomas Huth, Michael Walle

On Fri, 2018-10-12 at 02:22 +0200, Philippe Mathieu-Daudé wrote:
> The number of bytes can not be negative nor zero.
> 
> Fixed 2 format string:
> - hw/char/spapr_vty.c
> - hw/usb/ccid-card-passthru.c
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Acked-by: Alberto Garcia <berto@igalia.com>

Sorry to drag up an old patch series. As far as I can see this series
was never applied. I suspect a better way of solving the issue may have
been found? If so can anyone point me at that change?

I ask since CVE-2018-18438 is marked as affecting all qemu versions
(https://nvd.nist.gov/vuln/detail/CVE-2018-18438).

If it was fixed, the version mask could be updated. If the fix wasn't
deemed worthwhile for some reason that is also fine and I can mark this
one as such in our system. I'm being told we only need one of the
patches in this series which I also don't believe as I suspect we
either need the set or none of them!

Any info would be most welcome.

Cheers,

Richard







^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler use unsigned type
  2021-01-22 11:26   ` Richard Purdie
@ 2021-01-22 11:52     ` P J P
  2021-01-22 13:55       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 20+ messages in thread
From: P J P @ 2021-01-22 11:52 UTC (permalink / raw)
  To: Richard Purdie
  Cc: Peter Maydell, Li Zhijian, Michael S. Tsirkin, Jan Kiszka,
	Jason Wang, Palmer Dabbelt, qemu-devel, Alexander Graf,
	Max Filippov, Michael Clark, Gerd Hoffmann, Edgar E. Iglesias,
	Stefano Stabellini, Alberto Garcia, Sagar Karandikar,
	Markus Armbruster, Christian Borntraeger, Antony Pavlov,
	Anthony Perard, Marc-André Lureau,
	Philippe Mathieu-Daudé,
	Samuel Thibault, Laurent Vivier, Corey Minyard, Amit Shah,
	Alistair Francis, Dr. David Alan Gilbert, Fabien Chouteau,
	Peter Chubb, Zhang Chen, David Gibson, Igor Mitsyanko,
	Bastian Koppelmann, Cornelia Huck, Thomas Huth, Michael Walle,
	Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1018 bytes --]

+-- On Fri, 22 Jan 2021, Richard Purdie wrote --+
| If so can anyone point me at that change?
| 
| I ask since CVE-2018-18438 is marked as affecting all qemu versions
| (https://nvd.nist.gov/vuln/detail/CVE-2018-18438).
| 
| If it was fixed, the version mask could be updated. If the fix wasn't deemed 
| worthwhile for some reason that is also fine and I can mark this one as such 
| in our system. I'm being told we only need one of the patches in this series 
| which I also don't believe as I suspect we either need the set or none of 
| them!
| 
| Any info would be most welcome.

  -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02239.html
  -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02231.html

* Yes, the type change fix had come up during patch reviews above, and this 
  series implemented the change.

* Series is required IIUC, didn't realise it's not merged.


Thank you. 
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler use unsigned type
  2021-01-22 11:52     ` P J P
@ 2021-01-22 13:55       ` Philippe Mathieu-Daudé
  2021-01-22 15:25         ` Richard Purdie
  0 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-01-22 13:55 UTC (permalink / raw)
  To: P J P, Richard Purdie, Marc-André Lureau
  Cc: Peter Maydell, Li Zhijian, Michael S. Tsirkin, Jan Kiszka,
	Jason Wang, Palmer Dabbelt, qemu-devel, Alexander Graf,
	Max Filippov, Michael Clark, Gerd Hoffmann, Edgar E. Iglesias,
	Stefano Stabellini, Alberto Garcia, Sagar Karandikar,
	Markus Armbruster, Christian Borntraeger, Antony Pavlov,
	Anthony Perard, Samuel Thibault, Laurent Vivier, Corey Minyard,
	Amit Shah, Alistair Francis, Dr. David Alan Gilbert,
	Fabien Chouteau, Peter Chubb, Zhang Chen, David Gibson,
	Igor Mitsyanko, Bastian Koppelmann, Cornelia Huck, Thomas Huth,
	Michael Walle, Paolo Bonzini

Hi Prasad, Richard.

On 1/22/21 12:52 PM, P J P wrote:
> +-- On Fri, 22 Jan 2021, Richard Purdie wrote --+
> | If so can anyone point me at that change?
> | 
> | I ask since CVE-2018-18438 is marked as affecting all qemu versions
> | (https://nvd.nist.gov/vuln/detail/CVE-2018-18438).
> | 
> | If it was fixed, the version mask could be updated. If the fix wasn't deemed 
> | worthwhile for some reason that is also fine and I can mark this one as such 
> | in our system. I'm being told we only need one of the patches in this series 
> | which I also don't believe as I suspect we either need the set or none of 
> | them!
> | 
> | Any info would be most welcome.
> 
>   -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02239.html
>   -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02231.html
> 
> * Yes, the type change fix had come up during patch reviews above, and this 
>   series implemented the change.
> 
> * Series is required IIUC, didn't realise it's not merged.

Audit from Marc-André pointed that this is unlikely, we asked the
reporter for a reproducer and got not news, and eventually closed
this as NOTABUG (not even WONTFIX):
https://bugzilla.redhat.com/show_bug.cgi?id=1609015

Regards,

Phil.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler use unsigned type
  2021-01-22 13:55       ` Philippe Mathieu-Daudé
@ 2021-01-22 15:25         ` Richard Purdie
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Purdie @ 2021-01-22 15:25 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, P J P, Marc-André Lureau; +Cc: qemu-devel

On Fri, 2021-01-22 at 14:55 +0100, Philippe Mathieu-Daudé wrote:
> Hi Prasad, Richard.
> 
> On 1/22/21 12:52 PM, P J P wrote:
> > +-- On Fri, 22 Jan 2021, Richard Purdie wrote --+
> > > If so can anyone point me at that change?
> > > 
> > > I ask since CVE-2018-18438 is marked as affecting all qemu versions
> > > (https://nvd.nist.gov/vuln/detail/CVE-2018-18438).
> > > 
> > > If it was fixed, the version mask could be updated. If the fix wasn't deemed 
> > > worthwhile for some reason that is also fine and I can mark this one as such 
> > > in our system. I'm being told we only need one of the patches in this series 
> > > which I also don't believe as I suspect we either need the set or none of 
> > > them!
> > > 
> > > Any info would be most welcome.
> > 
> >   -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02239.html
> >   -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02231.html
> > 
> > * Yes, the type change fix had come up during patch reviews above, and this 
> >   series implemented the change.
> > 
> > * Series is required IIUC, didn't realise it's not merged.
> 
> Audit from Marc-André pointed that this is unlikely, we asked the
> reporter for a reproducer and got not news, and eventually closed
> this as NOTABUG (not even WONTFIX):
> https://bugzilla.redhat.com/show_bug.cgi?id=1609015

I guessed there some resolution like this but couldn't find it thanks
for the pointer. It's now clear in the archives and I can handle
appropriately rejecting carrying those patches, thanks!

Cheers,

Richard



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-01-22 15:26 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12  0:22 [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 01/11] hw/ipmi: Remove unnecessary declarations Philippe Mathieu-Daudé
2018-10-12  0:51   ` Corey Minyard
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 02/11] target/xtensa: " Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 03/11] chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 04/11] chardev: Assert backend's chr_can_read() is positive Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 05/11] chardev: Let chr_sync_read() use unsigned type Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 06/11] chardev: Let chr_write " Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 07/11] chardev: Let IOReadHandler " Philippe Mathieu-Daudé
2021-01-22 11:26   ` Richard Purdie
2021-01-22 11:52     ` P J P
2021-01-22 13:55       ` Philippe Mathieu-Daudé
2021-01-22 15:25         ` Richard Purdie
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 08/11] chardev: Let IOCanReadHandler " Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 09/11] chardev: Let qemu_chr_fe_* " Philippe Mathieu-Daudé
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 10/11] chardev: Let qemu_chr_be_* " Philippe Mathieu-Daudé
2018-10-12  6:43   ` Pavel Dovgalyuk
2018-10-12  0:22 ` [Qemu-devel] [PATCH v2 11/11] chardev: FDChardev::max_size be unsigned Philippe Mathieu-Daudé
2018-10-12  8:05   ` Paolo Bonzini
2018-10-12  8:20 ` [Qemu-devel] [PATCH v2 00/11] chardev: Convert IO handlers to use unsigned type Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).