chardev: Convert qemu_chr_write() to take a size_t argument
v3 cover chardev: Convert qemu_chr_write() to take a size_t argument
Hi,
This series convert the chardev::qemu_chr_write() to take unsigned length argument. To do so I went through all caller and checked if there are no negative value possible.
I'm having headaches with the Xen backend, talking with Marc-André he suggested I ask help to the Xen maintainers.
Since the series is becoming quite big, I splitted it:
- part 1: convert qemu_chr_write()
- part 2: convert IOReadHandler
part 1 can be reviewed and merged without part 2.
The git diffstat is not huge, but there are various chardev subsystems so many maintainers to ask for Ack.
v2: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02396.html
v1: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02200.html
(from Prasad J Pandit)
Changes requested by Paolo:
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.html
Please review,
Phil.
Philippe Mathieu-Daudé (25):
chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
chardev: Assert IOCanReadHandler can not be negative chardev/wctablet: Use unsigned type to hold unsigned value
chardev: Let qemu_chr_be_can_write() return a size_t types
gdbstub: Use size_t for strlen() return value
gdbstub: Use size_t to hold GDBState::last_packet_len
gdbstub: Let put_buffer() use size_t
ui/gtk: Remove pointless cast
vhost-user: Express sizeof with size_t
usb-redir: Verify usbredirparser_write get called with positive count
xen: Let xencons_send() take a 'size' argument
xen: Let buffer_append() return the size consumed
RFC xen: Let buffer_append() return a size_t
virtio-serial: Let VirtIOSerialPortClass::have_data() use size_t
spapr-vty: Let vty_putchars() use size_t
tpm: Use size_t to hold sizes
net/filter-mirror: Use size_t
s390x/3270: Let insert_IAC_escape_char() use size_t s390/ebcdic: Use size_t to iterate over arrays
s390x/sclp: Use a const variable to improve readability s390x/sclp: Use size_t in process_mdb()
s390x/sclp: Let write_console_data() take a size_t hw/ipmi: Assert outlen > outpos
chardev: Let qemu_chr_fe_write[_all] use size_t type argument
chardev: Let qemu_chr_write[_all] use size_t
chardev/baum.c | 6 +++--- chardev/char-fd.c | 6 +++--- chardev/char-fe.c | 4 ++-- chardev/char-io.c | 6 +++--- chardev/char-mux.c | 3 ++- chardev/char-pty.c | 8 ++++---- chardev/char-socket.c | 13 +++++++------ chardev/char-udp.c | 8 ++++---- chardev/char-win.c | 2 +- chardev/char.c | 15 +++++++++------ chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/trace-events | 2 +- chardev/wctablet.c | 9 +++++---- gdbstub.c | 8 ++++---- hw/bt/hci-csr.c | 2 +- hw/char/sclpconsole-lm.c | 12 +++++++----- hw/char/spapr_vty.c | 2 +- hw/char/terminal3270.c | 7 ++++--- hw/char/virtio-console.c | 2 +- hw/char/xen_console.c | 24 +++++++++++++++--------- hw/ipmi/ipmi_bmc_extern.c | 3 ++- hw/tpm/tpm_emulator.c | 7 ++++--- hw/usb/redirect.c | 6 +++++- hw/virtio/vhost-user.c | 14 ++++++++------ include/chardev/char-fd.h | 2 +- include/chardev/char-fe.h | 4 ++-- include/chardev/char-io.h | 2 +- include/chardev/char.h | 4 ++-- include/hw/ppc/spapr_vio.h | 2 +- include/hw/s390x/ebcdic.h | 8 ++++---- include/hw/virtio/virtio-serial.h | 2 +- include/sysemu/replay.h | 2 +- net/filter-mirror.c | 2 +- replay/replay-char.c | 2 +- stubs/replay.c | 2 +- ui/console.c | 6 +++--- ui/gtk.c | 2 +- 38 files changed, 119 insertions(+), 96 deletions(-)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/25 chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
IOWatchPoll::fd_can_read() really is a GSourceFunc type, it simply returns a boolean value.
Update the backends to return a boolean, whether there is data to read from the source or not.
--- chardev/char-fd.c | 4 ++-- chardev/char-io.c | 6 +++--- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 6 +++--- chardev/char-udp.c | 4 ++-- include/chardev/char-io.h | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-)
chardev/char-fd.c +2 -2
@@ -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)
chardev/char-io.c +3 -3
@@ -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;
@@ -44,7 +44,7 @@ static gboolean io_watch_poll_prepare(GSource *source, gint *timeout) {IOWatchPoll *iwp =io_watch_poll_from_source (source); -bool now_active = iwp->fd_can_read (iwp->opaque) >0 ; +bool now_active = iwp->fd_can_read (iwp->opaque);bool was_active = iwp->src !=NULL ;if (was_active == now_active) {return FALSE;
@@ -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)
chardev/char-pty.c +2 -2
@@ -119,13 +119,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)
chardev/char-socket.c +3 -3
@@ -147,7 +147,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. */
@@ -184,7 +184,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);
@@ -192,7 +192,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,
chardev/char-udp.c +2 -2
@@ -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)
include/chardev/char-io.h +1 -1
@@ -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);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 01/25] chardev: Simplify IOWatchPoll::fd_can_read as a GSourceFunc
Quoted 8 lines · Philippe Mathieu-Daudé
IOWatchPoll::fd_can_read()really is a GSourceFunc type, it simply returns a boolean value.
Update the backends to return a boolean, whether there is data to read from the source or not.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 147 lines
--- chardev/char-fd.c | 4 ++-- chardev/char-io.c | 6 +++--- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 6 +++--- chardev/char-udp.c | 4 ++-- include/chardev/char-io.h | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-)chardev/char-fd.c +2
-2@@ -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)chardev/char-io.c +3
-3@@ -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;@@ -44,7 +44,7 @@ static gboolean io_watch_poll_prepare(GSource *source, gint *timeout) {IOWatchPoll *iwp =io_watch_poll_from_source (source); -bool now_active = iwp->fd_can_read (iwp->opaque) >0 ; +bool now_active = iwp->fd_can_read (iwp->opaque);bool was_active = iwp->src !=NULL ;if (was_active == now_active) {return FALSE;@@ -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)chardev/char-pty.c +2
-2@@ -119,13 +119,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)chardev/char-socket.c +3
-3@@ -147,7 +147,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. */ @@ -184,7 +184,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);@@ -192,7 +192,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,chardev/char-udp.c +2
-2@@ -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)include/chardev/char-io.h +1
-2@@ -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); --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 2/25 chardev: Assert IOCanReadHandler can not be negative
In reply to Philippe Mathieu-DaudéThe backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
chardev/char.c +4 -1
@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 02/25] chardev: Assert IOCanReadHandler can not be negative
Hi
Quoted 7 lines · Philippe Mathieu-Daudé
The backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
In such patch, you should do extensive review of existing callbacks, or find a convincing argument that this can't break.
The problem is there are a lot of can_read callbacks, and it's not trivial. The *first* of git-grep is rng_egd_chr_can_read()
57 QSIMPLEQ_FOREACH(req, &s->parent.requests, next) {
58 size += req->size - req->offset;
59 }
60
61 return size;
Clearly not obvious if it returns >= 0.
Another approach is to look at the caller and the return value handling. If none handle negative values (or would have wrong behaviour with negative values), the assert() is perhaps justified, as it could prevent from doing more harm.
Quoted 28 lines
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)chardev/char.c +4
-2@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len) --2.20.1
Re: [Qemu-devel] [PATCH v3 02/25] chardev: Assert IOCanReadHandler can not be negative
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Philippe Mathieu-Daudé
The backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
Quoted 5 lines
Quoted 2 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>In such patch, you should do extensive review of existing callbacks, or find a convincing argument that this can't break.
Argh I missed that.
Quoted 9 lines
The problem is there are a lot of
can_readcallbacks, and it's not trivial. The *first* of git-grep isrng_egd_chr_can_read()57
QSIMPLEQ_FOREACH(req, &s->parent.requests, next){
58 size +=req->size-req->offset;
59 }
60
61 return size;
Quoted 6 lines
Clearly not obvious if it returns >= 0.
Another approach is to look at the caller and the return value handling. If none handle negative values (or would have wrong behaviour with negative values), the
assert()is perhaps justified, as it could prevent from doing more harm.
I'll go and audit all of them.
Thanks for the review!
Phil.
Quoted 24 lines
Quoted 24 lines
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)chardev/char.c +4
-1@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }
Quoted 4 lines
Quoted 4 lines
chardev/char.c +0
-1void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len) --2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 02/25] chardev: Assert IOCanReadHandler can not be negative
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Philippe Mathieu-Daudé
The backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
Quoted 5 lines
Quoted 2 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>In such patch, you should do extensive review of existing callbacks, or find a convincing argument that this can't break.
Argh I missed that.
Quoted 9 lines
The problem is there are a lot of
can_readcallbacks, and it's not trivial. The *first* of git-grep isrng_egd_chr_can_read()57
QSIMPLEQ_FOREACH(req, &s->parent.requests, next){
58 size +=req->size-req->offset;
59 }
60
61 return size;
Quoted 8 lines
Quoted 6 lines
Clearly not obvious if it returns >= 0.
Another approach is to look at the caller and the return value handling. If none handle negative values (or would have wrong behaviour with negative values), the
assert()is perhaps justified, as it could prevent from doing more harm.I'll go and audit all of them.
Actually I already did the work, but it is in the part #2 after this series, as suggested by Paolo:
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.html
I'll simply cherry-pick the commit from series #2 before this patch.
Thanks,
Phil.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)chardev/char.c +4
-2@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len) --2.20.1
Re: [PATCH v3 02/25] chardev: Assert IOCanReadHandler can not be negative
In reply to Philippe Mathieu-DaudéQuoted 27 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Philippe Mathieu-Daudé
The backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
Quoted 5 lines
Quoted 2 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>In such patch, you should do extensive review of existing callbacks, or find a convincing argument that this can't break.
Argh I missed that.
Quoted 9 lines
The problem is there are a lot of
can_readcallbacks, and it's not trivial. The *first* of git-grep isrng_egd_chr_can_read()57
QSIMPLEQ_FOREACH(req, &s->parent.requests, next){
58 size +=req->size-req->offset;
59 }
60
61 return size;
Quoted 8 lines
Quoted 6 lines
Clearly not obvious if it returns >= 0.
Another approach is to look at the caller and the return value handling. If none handle negative values (or would have wrong behaviour with negative values), the
assert()is perhaps justified, as it could prevent from doing more harm.I'll go and audit all of them.
Actually I already did the work, but it is in the part #2 after this series, as suggested by Paolo:
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.html
I'll simply cherry-pick the commit from series #2 before this patch.
Thanks,
Phil.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)chardev/char.c +4
-1@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
chardev/char.c +0
-1void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len) --2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 02/25] chardev: Assert IOCanReadHandler can not be negative
In reply to Philippe Mathieu-DaudéHi
Quoted 7 lines · Philippe Mathieu-Daudé
The backend should not return a negative length to read. We will later change the prototype of IOCanReadHandler to return an unsigned length. Meanwhile make sure the return length is positive.
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
In such patch, you should do extensive review of existing callbacks, or find a convincing argument that this can't break.
The problem is there are a lot of can_read callbacks, and it's not trivial. The *first* of git-grep is rng_egd_chr_can_read()
57 QSIMPLEQ_FOREACH(req, &s->parent.requests, next) {
58 size += req->size - req->offset;
59 }
60
61 return size;
Clearly not obvious if it returns >= 0.
Another approach is to look at the caller and the return value handling. If none handle negative values (or would have wrong behaviour with negative values), the assert() is perhaps justified, as it could prevent from doing more harm.
Quoted 26 lines
--- chardev/char.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)chardev/char.c +4
-2@@ -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 receivable_bytes;if (!be || !be->chr_can_read) {return 0 ; } -return be->chr_can_read (be->opaque); + receivable_bytes = be->chr_can_read (be->opaque); +assert (receivable_bytes >=0 ); +return receivable_bytes; }void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len) --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 3/25 chardev/wctablet: Use unsigned type to hold unsigned value
In reply to Philippe Mathieu-DaudéTabletChardev::query is an array of uint8_t.
Use the same type to hold it (this also silent a -Wsign-conversion warning in the trace function).
--- chardev/trace-events | 2 +- chardev/wctablet.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
chardev/trace-events +1 -1
@@ -5,7 +5,7 @@ wct_init(void) "" wct_cmd_re(void) "" wct_cmd_st(void) "" wct_cmd_sp(void) "" -wct_cmd_ts(int input) "0x%02x" +wct_cmd_ts(uint8_t input) "0x%02x" wct_cmd_other(const char *cmd) "%s" wct_speed(int speed) "%d"
chardev/wctablet.c +3 -2
@@ -207,7 +207,8 @@ static int wctablet_chr_write(struct Chardev *chr, const uint8_t *buf, int len) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -unsigned int i, clen; +size_t i; +unsigned int clen;char *pos;if (tablet->line_speed !=9600 ) {
@@ -269,7 +270,7 @@ static int wctablet_chr_write(struct Chardev *chr, }else if (strncmp ((char *)tablet->query,"TS" ,2 ) ==0 && clen ==3 ) { -unsigned int input = tablet->query[2 ]; +uint8_t input = tablet->query[2 ];uint8_t codes[7 ] = {0xa3 , ((input & 0x80) == 0) ? 0x7e : 0x7f,
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 03/25] chardev/wctablet: Use unsigned type to hold unsigned value
Quoted 5 lines · Philippe Mathieu-Daudé
TabletChardev::queryis an array ofuint8_t.
Use the same type to hold it (this also silent a -Wsign-conversion warning in the trace function).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 44 lines
--- chardev/trace-events | 2 +- chardev/wctablet.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)chardev/trace-events +1
-1@@ -5,7 +5,7 @@ wct_init(void) "" wct_cmd_re(void) "" wct_cmd_st(void) "" wct_cmd_sp(void) "" -wct_cmd_ts(int input) "0x%02x" +wct_cmd_ts(uint8_t input) "0x%02x" wct_cmd_other(const char *cmd) "%s" wct_speed(int speed) "%d"chardev/wctablet.c +3
-2@@ -207,7 +207,8 @@ static int wctablet_chr_write(struct Chardev *chr, const uint8_t *buf, int len) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -unsigned int i, clen; +size_t i; +unsigned int clen;char *pos;if (tablet->line_speed !=9600 ) {@@ -269,7 +270,7 @@ static int wctablet_chr_write(struct Chardev *chr, }else if (strncmp ((char *)tablet->query,"TS" ,2 ) ==0 && clen ==3 ) { -unsigned int input = tablet->query[2 ]; +uint8_t input = tablet->query[2 ];uint8_t codes[7 ] = {0xa3 , ((input & 0x80) == 0) ? 0x7e : 0x7f,Signature · 1 line
2.20.1
Re: [PATCH v3 03/25] chardev/wctablet: Use unsigned type to hold unsigned value
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
TabletChardev::queryis an array ofuint8_t.
Use the same type to hold it (this also silent a -Wsign-conversion warning in the trace function).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 44 lines
--- chardev/trace-events | 2 +- chardev/wctablet.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)chardev/trace-events +1
-1@@ -5,7 +5,7 @@ wct_init(void) "" wct_cmd_re(void) "" wct_cmd_st(void) "" wct_cmd_sp(void) "" -wct_cmd_ts(int input) "0x%02x" +wct_cmd_ts(uint8_t input) "0x%02x" wct_cmd_other(const char *cmd) "%s" wct_speed(int speed) "%d"chardev/wctablet.c +3
-2@@ -207,7 +207,8 @@ static int wctablet_chr_write(struct Chardev *chr, const uint8_t *buf, int len) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -unsigned int i, clen; +size_t i; +unsigned int clen;char *pos;if (tablet->line_speed !=9600 ) {@@ -269,7 +270,7 @@ static int wctablet_chr_write(struct Chardev *chr, }else if (strncmp ((char *)tablet->query,"TS" ,2 ) ==0 && clen ==3 ) { -unsigned int input = tablet->query[2 ]; +uint8_t input = tablet->query[2 ];uint8_t codes[7 ] = {0xa3 , ((input & 0x80) == 0) ? 0x7e : 0x7f,Signature · 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 03/25] chardev/wctablet: Use unsigned type to hold unsigned value
In reply to Philippe Mathieu-DaudéHi
Quoted 6 lines · Philippe Mathieu-Daudé
TabletChardev::queryis an array ofuint8_t.
Use the same type to hold it (this also silent a -Wsign-conversion warning in the trace function).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 44 lines
--- chardev/trace-events | 2 +- chardev/wctablet.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)chardev/trace-events +1
-1@@ -5,7 +5,7 @@ wct_init(void) "" wct_cmd_re(void) "" wct_cmd_st(void) "" wct_cmd_sp(void) "" -wct_cmd_ts(int input) "0x%02x" +wct_cmd_ts(uint8_t input) "0x%02x" wct_cmd_other(const char *cmd) "%s" wct_speed(int speed) "%d"chardev/wctablet.c +3
-3@@ -207,7 +207,8 @@ static int wctablet_chr_write(struct Chardev *chr, const uint8_t *buf, int len) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -unsigned int i, clen; +size_t i; +unsigned int clen;char *pos;if (tablet->line_speed !=9600 ) {@@ -269,7 +270,7 @@ static int wctablet_chr_write(struct Chardev *chr, }else if (strncmp ((char *)tablet->query,"TS" ,2 ) ==0 && clen ==3 ) { - unsigned int input = tablet->query[2]; +uint8_t input = tablet->query[2 ];uint8_t codes[7 ] = {0xa3 , ((input & 0x80) == 0) ? 0x7e : 0x7f, --2.20.1
Re: [PATCH v3 03/25] chardev/wctablet: Use unsigned type to hold unsigned value
In reply to Philippe Mathieu-DaudéHi
Quoted 6 lines · Philippe Mathieu-Daudé
TabletChardev::queryis an array ofuint8_t.
Use the same type to hold it (this also silent a -Wsign-conversion warning in the trace function).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 42 lines
--- chardev/trace-events | 2 +- chardev/wctablet.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)chardev/trace-events +1
-1@@ -5,7 +5,7 @@ wct_init(void) "" wct_cmd_re(void) "" wct_cmd_st(void) "" wct_cmd_sp(void) "" -wct_cmd_ts(int input) "0x%02x" +wct_cmd_ts(uint8_t input) "0x%02x" wct_cmd_other(const char *cmd) "%s" wct_speed(int speed) "%d"chardev/wctablet.c +3
-3@@ -207,7 +207,8 @@ static int wctablet_chr_write(struct Chardev *chr, const uint8_t *buf, int len) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -unsigned int i, clen; +size_t i; +unsigned int clen;char *pos;if (tablet->line_speed !=9600 ) {@@ -269,7 +270,7 @@ static int wctablet_chr_write(struct Chardev *chr, }else if (strncmp ((char *)tablet->query,"TS" ,2 ) ==0 && clen ==3 ) { - unsigned int input = tablet->query[2]; +uint8_t input = tablet->query[2 ];uint8_t codes[7 ] = {0xa3 , ((input & 0x80) == 0) ? 0x7e : 0x7f, --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 4/25 chardev: Let qemu_chr_be_can_write() return a size_t types
In reply to Philippe Mathieu-DaudéIn the previous commit we added an assert to be sure than qemu_chr_be_can_write() will never return a negative value. We can now change its prototype to return a size_t. Adapt the backends accordingly.
--- chardev/baum.c | 6 +++--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 7 ++++--- chardev/char-udp.c | 4 ++-- chardev/char-win.c | 2 +- chardev/char.c | 2 +- chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/wctablet.c | 4 ++-- hw/bt/hci-csr.c | 2 +- include/chardev/char-fd.h | 2 +- include/chardev/char.h | 2 +- ui/console.c | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-)
chardev/baum.c +3 -3
@@ -265,7 +265,7 @@ static int baum_deferred_init(BaumChardev *baum)static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum =BAUM_CHARDEV (chr); -int room, first; +size_t room, first;if (!baum->out_buf_used)return ;
@@ -292,7 +292,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) {Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf; -int room; +size_t room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC )
@@ -303,7 +303,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Fits */ qemu_chr_be_write (chr, io_buf, len); }else { -int first; +size_t first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ qemu_chr_be_write (chr, io_buf, room);
chardev/char-fd.c +1 -1
@@ -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;
chardev/char-pty.c +2 -2
@@ -34,7 +34,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; - int read_bytes; + size_t read_bytes; int connected; GSource *timer_src;
@@ -132,7 +132,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); -gsize len; +size_t len;uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret;
chardev/char-socket.c +4 -3
@@ -60,7 +60,7 @@ typedef struct {GSource *hup_source;QCryptoTLSCreds *tls_creds;TCPChardevState state; -int max_size; +size_t max_size;int do_telnetopt;int do_nodelay;int *read_msgfds;
@@ -493,10 +493,11 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque);uint8_t buf[CHR_READ_BUF_LEN ]; -int len, size; +size_t len; +int size;if ((s->state !=TCP_CHARDEV_STATE_CONNECTED ) || - s->max_size <=0 ) { + s->max_size ==0 ) {return TRUE; } len =sizeof (buf);
chardev/char-udp.c +2 -2
@@ -39,7 +39,7 @@ typedef struct {uint8_t buf[CHR_READ_BUF_LEN ];int bufcnt;int bufptr; -int max_size; +size_t max_size; } UdpChardev;#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)
@@ -58,7 +58,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)Chardev *chr =CHARDEV (s);while (s->max_size >0 && s->bufptr < s->bufcnt) { -int n =MIN (s->max_size, s->bufcnt - s->bufptr); +size_t n =MIN (s->max_size, s->bufcnt - s->bufptr);qemu_chr_be_write (chr, &s->buf[s->bufptr], n); s->bufptr += n; s->max_size =qemu_chr_be_can_write (chr);
chardev/char-win.c +1 -1
@@ -29,7 +29,7 @@static void win_chr_read (Chardev *chr,DWORD len) {WinChardev *s =WIN_CHARDEV (chr); -int max_size =qemu_chr_be_can_write (chr); +size_t max_size =qemu_chr_be_can_write (chr);int ret, err;uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;
chardev/char.c +1 -1
@@ -156,7 +156,7 @@ 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 receivable_bytes;
chardev/msmouse.c +2 -2
@@ -38,7 +38,7 @@ typedef struct {bool btns[INPUT_BUTTON__MAX ];bool btnc[INPUT_BUTTON__MAX ];uint8_t outbuf[32 ]; -int outlen; +size_t outlen; } MouseChardev;#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"
@@ -48,7 +48,7 @@ typedef struct {static void msmouse_chr_accept_input (Chardev *chr) {MouseChardev *mouse =MOUSE_CHARDEV (chr); -int len; +size_t len; len =qemu_chr_be_can_write (chr);if (len > mouse->outlen) {
chardev/spice.c +1 -1
@@ -43,7 +43,7 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (chr); +size_t can_write =qemu_chr_be_can_write (chr); last_out =MIN (len, can_write);if (last_out <=0 ) {break ;
chardev/wctablet.c +2 -2
@@ -74,7 +74,7 @@ typedef struct {/* Command to be sent to serial port */ uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN ]; -int outlen; +size_t outlen;int line_speed;bool send_events;
@@ -186,7 +186,7 @@ static QemuInputHandler wctablet_handler = {static void wctablet_chr_accept_input (Chardev *chr) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -int len, canWrite; +size_t len, canWrite; canWrite =qemu_chr_be_can_write (chr); len = canWrite;
hw/bt/hci-csr.c +1 -1
@@ -38,7 +38,7 @@ struct csrhci_s {#define FIFO_LEN 4096int out_start;int out_len; -int out_size; +size_t out_size;uint8_t outfifo[FIFO_LEN *2 ];uint8_t inpkt[FIFO_LEN ];enum {
include/chardev/char-fd.h +1 -1
@@ -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"
include/chardev/char.h +1 -1
@@ -173,7 +173,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:
ui/console.c +3 -3
@@ -61,8 +61,8 @@ enum TTYState {typedef struct QEMUFIFO {uint8_t *buf; -int buf_size; -int count, wptr, rptr; +size_t buf_size, count; +int wptr, rptr; }QEMUFIFO ;static int qemu_fifo_write (QEMUFIFO *f,const uint8_t *buf,int len1)
@@ -1110,7 +1110,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)static void kbd_send_chars (void *opaque) {QemuConsole *s = opaque; -int len; +size_t len;uint8_t buf[16 ]; len =qemu_chr_be_can_write (s->chr);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 04/25] chardev: Let qemu_chr_be_can_write() return a size_t types
Hi
Quoted 5 lines · Philippe Mathieu-Daudé
In the previous commit we added an assert to be sure than
qemu_chr_be_can_write()will never return a negative value. We can now change its prototype to return asize_t. Adapt the backends accordingly.
Each variable you change to an unsigned type, we should check it isn't used with negative values.
Quoted 43 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- chardev/baum.c | 6 +++--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 7 ++++--- chardev/char-udp.c | 4 ++-- chardev/char-win.c | 2 +- chardev/char.c | 2 +- chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/wctablet.c | 4 ++-- hw/bt/hci-csr.c | 2 +- include/chardev/char-fd.h | 2 +- include/chardev/char.h | 2 +- ui/console.c | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-)chardev/baum.c +2
-2@@ -265,7 +265,7 @@ static int baum_deferred_init(BaumChardev *baum)static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum =BAUM_CHARDEV (chr); -int room, first; +size_t room, first;if (!baum->out_buf_used)return ;@@ -292,7 +292,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) {Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf; -int room; +size_t room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC )
chardev/baum.c static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) · line 309
Quoted 8 lines
chardev/baum.c +1
-1@@ -303,7 +303,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Fits */ qemu_chr_be_write (chr, io_buf, len); }else { -int first; +size_t first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ qemu_chr_be_write (chr, io_buf, room);
baum room & first are only used for non-negative capacity values. ack
chardev/char-fd.c static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 49
Quoted 13 lines
chardev/char-fd.c +1
-1@@ -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;
fd len is only used for non-negative buffer size. ack
chardev/char-pty.c line 38
Quoted 11 lines
chardev/char-pty.c +1
-1@@ -34,7 +34,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; - int read_bytes; + size_t read_bytes;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-pty.c static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 137
Quoted 10 lines
chardev/char-pty.c +1
-1int connected;GSource *timer_src;@@ -132,7 +132,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); -gsize len; +size_t len;uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret;
pty len is only used for non-negative buffer size. ack
chardev/char-socket.c typedef struct { · line 63
Quoted 10 lines
chardev/char-socket.c +1
-1@@ -60,7 +60,7 @@ typedef struct {GSource *hup_source;QCryptoTLSCreds *tls_creds;TCPChardevState state; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-socket.c static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 496
Quoted 9 lines
chardev/char-socket.c +1
-1int do_telnetopt;int do_nodelay;int *read_msgfds;@@ -493,10 +493,11 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque);uint8_t buf[CHR_READ_BUF_LEN ]; -int len, size; +size_t len;
len is only used for non-negative buffer size. ack
Quoted 13 lines
chardev/char-socket.c +2
-1+int size;if ((s->state !=TCP_CHARDEV_STATE_CONNECTED ) || - s->max_size <=0 ) { + s->max_size ==0 ) {return TRUE; } len =sizeof (buf);chardev/char-udp.c +0
-0
chardev/char-udp.c typedef struct { · line 42
Quoted 5 lines
chardev/char-udp.c +1
-1@@ -39,7 +39,7 @@ typedef struct {uint8_t buf[CHR_READ_BUF_LEN ];int bufcnt;int bufptr; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-udp.c static void udp_chr_flush_buffer(UdpChardev *s) · line 61
Quoted 9 lines
chardev/char-udp.c +1
-1} UdpChardev;#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)@@ -58,7 +58,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)Chardev *chr =CHARDEV (s);while (s->max_size >0 && s->bufptr < s->bufcnt) { -int n =MIN (s->max_size, s->bufcnt - s->bufptr); +size_t n =MIN (s->max_size, s->bufcnt - s->bufptr);
the while() condition ensures the value will be > 0. ack
chardev/char-win.c line 32
Quoted 13 lines
chardev/char-udp.c +0
-0qemu_chr_be_write (chr, &s->buf[s->bufptr], n); s->bufptr += n; s->max_size =qemu_chr_be_can_write (chr);chardev/char-win.c +1
-1@@ -29,7 +29,7 @@static void win_chr_read (Chardev *chr,DWORD len) {WinChardev *s =WIN_CHARDEV (chr); -int max_size =qemu_chr_be_can_write (chr); +size_t max_size =qemu_chr_be_can_write (chr);
unmodified, ack
Quoted 21 lines
chardev/char-win.c +0
-0int ret, err;uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;chardev/char.c +1
-1@@ -156,7 +156,7 @@ 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 receivable_bytes;chardev/msmouse.c +0
-0
chardev/msmouse.c typedef struct { · line 41
Quoted 5 lines
chardev/msmouse.c +1
-1@@ -38,7 +38,7 @@ typedef struct {bool btns[INPUT_BUTTON__MAX ];bool btnc[INPUT_BUTTON__MAX ];uint8_t outbuf[32 ]; -int outlen; +size_t outlen;
outlen is only used as non-negative buffer size, ack
chardev/msmouse.c typedef struct { · line 53
Quoted 11 lines
chardev/msmouse.c +1
-1} MouseChardev;#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"@@ -48,7 +48,7 @@ typedef struct {static void msmouse_chr_accept_input (Chardev *chr) {MouseChardev *mouse =MOUSE_CHARDEV (chr); -int len; +size_t len; len =qemu_chr_be_can_write (chr);
same
chardev/spice.c static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) · line 46
Quoted 11 lines
chardev/msmouse.c +0
-0if (len > mouse->outlen) {chardev/spice.c +1
-1@@ -43,7 +43,7 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (chr); +size_t can_write =qemu_chr_be_can_write (chr);
unmodified value, ack
chardev/wctablet.c typedef struct { · line 77
Quoted 13 lines
chardev/spice.c +0
-0last_out =MIN (len, can_write);if (last_out <=0 ) {break ;chardev/wctablet.c +1
-1@@ -74,7 +74,7 @@ typedef struct {/* Command to be sent to serial port */ uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN ]; -int outlen; +size_t outlen;
Used as non-negative buffer size only, ack
chardev/wctablet.c static QemuInputHandler wctablet_handler = { · line 189
Quoted 9 lines
chardev/wctablet.c +1
-1int line_speed;bool send_events;@@ -186,7 +186,7 @@ static QemuInputHandler wctablet_handler = {static void wctablet_chr_accept_input (Chardev *chr) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -int len, canWrite; +size_t len, canWrite;
Used as non-negative buffer size only, ack
hw/bt/hci-csr.c struct csrhci_s { · line 41
Quoted 13 lines
chardev/wctablet.c +0
-0canWrite =qemu_chr_be_can_write (chr); len = canWrite;hw/bt/hci-csr.c +1
-1@@ -38,7 +38,7 @@ struct csrhci_s {#define FIFO_LEN 4096int out_start;int out_len; -int out_size; +size_t out_size;
Used as non-negative buffer size only, ack
include/chardev/char-fd.h typedef struct FDChardev { · line 34
Quoted 13 lines
hw/bt/hci-csr.c +0
-0uint8_t outfifo[FIFO_LEN *2 ];uint8_t inpkt[FIFO_LEN ];enum {include/chardev/char-fd.h +1
-1@@ -31,7 +31,7 @@ typedef struct FDChardev {Chardev parent;QIOChannel *ioc_in, *ioc_out; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
Quoted 21 lines
include/chardev/char-fd.h +0
-0} FDChardev;#define TYPE_CHARDEV_FD "chardev-fd"include/chardev/char.h +1
-1@@ -173,7 +173,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: ui/console.c +0
-0
ui/console.c enum TTYState { · line 65
Quoted 7 lines
ui/console.c +2
-2@@ -61,8 +61,8 @@ enum TTYState { typedef struct QEMUFIFO { uint8_t *buf; - int buf_size; - int count, wptr, rptr; + size_t buf_size, count; + int wptr, rptr;
Only used as non-negative buffer size, ack
ui/console.c static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 1113
Quoted 9 lines
ui/console.c +1
-1}QEMUFIFO ;static int qemu_fifo_write (QEMUFIFO *f,const uint8_t *buf,int len1)@@ -1110,7 +1110,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)static void kbd_send_chars (void *opaque) {QemuConsole *s = opaque; -int len; +size_t len;
Only used as non-negative buffer size, ack
Quoted 6 lines
ui/console.c +0
-1uint8_t buf[16 ]; len =qemu_chr_be_can_write (s->chr); --2.20.1
That was painful, hopefully I didn't miss something...
Re: [Qemu-devel] [PATCH v3 04/25] chardev: Let qemu_chr_be_can_write() return a size_t types
Quoted 5 lines · Marc-André Lureau
Hi
Quoted 1 line · Philippe Mathieu-Daudé
Quoted 7 lines
Quoted 4 lines
In the previous commit we added an assert to be sure than
qemu_chr_be_can_write()will never return a negative value. We can now change its prototype to return asize_t. Adapt the backends accordingly.Each variable you change to an unsigned type, we should check it isn't used with negative values.
Fortunately the preprocessor can help here!
Oh I forgot to write down the steps I ran:
# enable warnings
$ configure \
--extra-cflags='-Wtype-limits -Wsign-conversion -Wsign-compare' \
--disable-werror# since there are many sign abuse, build blindly $ make 2>/dev/null
# now refresh the source we modified
$ git diff --name-only origin/master \
| egrep \.c\$ \
| xargs touch# build again and carefully watch the warnings # (there are many unuseful #include warnings, ignore them) $ make
Quoted 330 lines
Quoted 43 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- chardev/baum.c | 6 +++--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 7 ++++--- chardev/char-udp.c | 4 ++-- chardev/char-win.c | 2 +- chardev/char.c | 2 +- chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/wctablet.c | 4 ++-- hw/bt/hci-csr.c | 2 +- include/chardev/char-fd.h | 2 +- include/chardev/char.h | 2 +- ui/console.c | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-)chardev/baum.c +2
-2@@ -265,7 +265,7 @@ static int baum_deferred_init(BaumChardev *baum)static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum =BAUM_CHARDEV (chr); -int room, first; +size_t room, first;if (!baum->out_buf_used)return ;@@ -292,7 +292,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) {Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf; -int room; +size_t room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC )chardev/baum.c static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) · line 309
Quoted 8 lines
chardev/baum.c +1
-1@@ -303,7 +303,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Fits */ qemu_chr_be_write (chr, io_buf, len); }else { -int first; +size_t first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ qemu_chr_be_write (chr, io_buf, room);baum room & first are only used for non-negative capacity values. ack
chardev/char-fd.c static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 49
Quoted 13 lines
chardev/char-fd.c +1
-1@@ -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;fd len is only used for non-negative buffer size. ack
chardev/char-pty.c line 38
Quoted 11 lines
chardev/char-pty.c +1
-1@@ -34,7 +34,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; - int read_bytes; + size_t read_bytes;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-pty.c static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 137
Quoted 10 lines
chardev/char-pty.c +1
-1int connected;GSource *timer_src;@@ -132,7 +132,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); -gsize len; +size_t len;uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret;pty len is only used for non-negative buffer size. ack
chardev/char-socket.c typedef struct { · line 63
Quoted 10 lines
chardev/char-socket.c +1
-1@@ -60,7 +60,7 @@ typedef struct {GSource *hup_source;QCryptoTLSCreds *tls_creds;TCPChardevState state; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-socket.c static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 496
Quoted 9 lines
chardev/char-socket.c +1
-1int do_telnetopt;int do_nodelay;int *read_msgfds;@@ -493,10 +493,11 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque);uint8_t buf[CHR_READ_BUF_LEN ]; -int len, size; +size_t len;len is only used for non-negative buffer size. ack
Quoted 13 lines
chardev/char-socket.c +2
-1+int size;if ((s->state !=TCP_CHARDEV_STATE_CONNECTED ) || - s->max_size <=0 ) { + s->max_size ==0 ) {return TRUE; } len =sizeof (buf);chardev/char-udp.c +0
-0chardev/char-udp.c typedef struct { · line 42
Quoted 5 lines
chardev/char-udp.c +1
-1@@ -39,7 +39,7 @@ typedef struct {uint8_t buf[CHR_READ_BUF_LEN ];int bufcnt;int bufptr; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-udp.c static void udp_chr_flush_buffer(UdpChardev *s) · line 61
Quoted 9 lines
chardev/char-udp.c +1
-1} UdpChardev;#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)@@ -58,7 +58,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)Chardev *chr =CHARDEV (s);while (s->max_size >0 && s->bufptr < s->bufcnt) { -int n =MIN (s->max_size, s->bufcnt - s->bufptr); +size_t n =MIN (s->max_size, s->bufcnt - s->bufptr);the
while()condition ensures the value will be > 0. ackchardev/char-win.c line 32
Quoted 13 lines
chardev/char-udp.c +0
-0qemu_chr_be_write (chr, &s->buf[s->bufptr], n); s->bufptr += n; s->max_size =qemu_chr_be_can_write (chr);chardev/char-win.c +1
-1@@ -29,7 +29,7 @@static void win_chr_read (Chardev *chr,DWORD len) {WinChardev *s =WIN_CHARDEV (chr); -int max_size =qemu_chr_be_can_write (chr); +size_t max_size =qemu_chr_be_can_write (chr);unmodified, ack
Quoted 21 lines
chardev/char-win.c +0
-0int ret, err;uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;chardev/char.c +1
-1@@ -156,7 +156,7 @@ 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 receivable_bytes;chardev/msmouse.c +0
-0chardev/msmouse.c typedef struct { · line 41
Quoted 5 lines
chardev/msmouse.c +1
-1@@ -38,7 +38,7 @@ typedef struct {bool btns[INPUT_BUTTON__MAX ];bool btnc[INPUT_BUTTON__MAX ];uint8_t outbuf[32 ]; -int outlen; +size_t outlen;outlen is only used as non-negative buffer size, ack
chardev/msmouse.c typedef struct { · line 53
Quoted 11 lines
chardev/msmouse.c +1
-1} MouseChardev;#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"@@ -48,7 +48,7 @@ typedef struct {static void msmouse_chr_accept_input (Chardev *chr) {MouseChardev *mouse =MOUSE_CHARDEV (chr); -int len; +size_t len; len =qemu_chr_be_can_write (chr);same
chardev/spice.c static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) · line 46
Quoted 11 lines
chardev/msmouse.c +0
-0if (len > mouse->outlen) {chardev/spice.c +1
-1@@ -43,7 +43,7 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (chr); +size_t can_write =qemu_chr_be_can_write (chr);unmodified value, ack
chardev/wctablet.c typedef struct { · line 77
Quoted 13 lines
chardev/spice.c +0
-0last_out =MIN (len, can_write);if (last_out <=0 ) {break ;chardev/wctablet.c +1
-1@@ -74,7 +74,7 @@ typedef struct {/* Command to be sent to serial port */ uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN ]; -int outlen; +size_t outlen;Used as non-negative buffer size only, ack
chardev/wctablet.c static QemuInputHandler wctablet_handler = { · line 189
Quoted 9 lines
chardev/wctablet.c +1
-1int line_speed;bool send_events;@@ -186,7 +186,7 @@ static QemuInputHandler wctablet_handler = {static void wctablet_chr_accept_input (Chardev *chr) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -int len, canWrite; +size_t len, canWrite;Used as non-negative buffer size only, ack
hw/bt/hci-csr.c struct csrhci_s { · line 41
Quoted 13 lines
chardev/wctablet.c +0
-0canWrite =qemu_chr_be_can_write (chr); len = canWrite;hw/bt/hci-csr.c +1
-1@@ -38,7 +38,7 @@ struct csrhci_s {#define FIFO_LEN 4096int out_start;int out_len; -int out_size; +size_t out_size;Used as non-negative buffer size only, ack
include/chardev/char-fd.h typedef struct FDChardev { · line 34
Quoted 13 lines
hw/bt/hci-csr.c +0
-0uint8_t outfifo[FIFO_LEN *2 ];uint8_t inpkt[FIFO_LEN ];enum {include/chardev/char-fd.h +1
-1@@ -31,7 +31,7 @@ typedef struct FDChardev {Chardev parent;QIOChannel *ioc_in, *ioc_out; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackQuoted 21 lines
include/chardev/char-fd.h +0
-0} FDChardev;#define TYPE_CHARDEV_FD "chardev-fd"include/chardev/char.h +1
-1@@ -173,7 +173,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: ui/console.c +0
-0ui/console.c enum TTYState { · line 65
Quoted 7 lines
ui/console.c +2
-2@@ -61,8 +61,8 @@ enum TTYState { typedef struct QEMUFIFO { uint8_t *buf; - int buf_size; - int count, wptr, rptr; + size_t buf_size, count; + int wptr, rptr;Only used as non-negative buffer size, ack
ui/console.c static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 1113
Quoted 9 lines
ui/console.c +1
-1}QEMUFIFO ;static int qemu_fifo_write (QEMUFIFO *f,const uint8_t *buf,int len1)@@ -1110,7 +1110,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)static void kbd_send_chars (void *opaque) {QemuConsole *s = opaque; -int len; +size_t len;Only used as non-negative buffer size, ack
Quoted 8 lines
Quoted 6 lines
ui/console.c +0
-1uint8_t buf[16 ]; len =qemu_chr_be_can_write (s->chr); --2.20.1
That was painful, hopefully I didn't miss something...
As is this series and its rebases...
I hope you will still be as willingful to review the follow up series (part #2) which is worst.
I felt this is pointless to write the same detailed review you did in the commit message, because the reviewer still has to go to each patch and verify.
Quoted 3 lines
Reviewed-by Marc-André Lureau <[email protected]>
Thanks a lot!
Phil.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 04/25] chardev: Let qemu_chr_be_can_write() return a size_t types
Hi
Quoted 375 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Marc-André Lureau
Hi
Quoted 1 line · Philippe Mathieu-Daudé
Quoted 7 lines
Quoted 4 lines
In the previous commit we added an assert to be sure than
qemu_chr_be_can_write()will never return a negative value. We can now change its prototype to return asize_t. Adapt the backends accordingly.Each variable you change to an unsigned type, we should check it isn't used with negative values.
Fortunately the preprocessor can help here!
Oh I forgot to write down the steps I ran:
# enable warnings $ configure \ --extra-cflags='-Wtype-limits -Wsign-conversion -Wsign-compare' \ --disable-werror# since there are many sign abuse, build blindly $ make 2>/dev/null# now refresh the source we modified $ git diff --name-only origin/master \ | egrep \.c\$ \ | xargs touch# build again and carefully watch the warnings # (there are many unuseful #include warnings, ignore them) $ makeQuoted 330 lines
Quoted 43 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- chardev/baum.c | 6 +++--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 7 ++++--- chardev/char-udp.c | 4 ++-- chardev/char-win.c | 2 +- chardev/char.c | 2 +- chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/wctablet.c | 4 ++-- hw/bt/hci-csr.c | 2 +- include/chardev/char-fd.h | 2 +- include/chardev/char.h | 2 +- ui/console.c | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-)chardev/baum.c +2
-2@@ -265,7 +265,7 @@ static int baum_deferred_init(BaumChardev *baum)static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum =BAUM_CHARDEV (chr); -int room, first; +size_t room, first;if (!baum->out_buf_used)return ;@@ -292,7 +292,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) {Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf; -int room; +size_t room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC )chardev/baum.c static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) · line 309
Quoted 8 lines
chardev/baum.c +1
-1@@ -303,7 +303,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Fits */ qemu_chr_be_write (chr, io_buf, len); }else { -int first; +size_t first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ qemu_chr_be_write (chr, io_buf, room);baum room & first are only used for non-negative capacity values. ack
chardev/char-fd.c static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 49
Quoted 13 lines
chardev/char-fd.c +1
-1@@ -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;fd len is only used for non-negative buffer size. ack
chardev/char-pty.c line 38
Quoted 11 lines
chardev/char-pty.c +1
-1@@ -34,7 +34,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; - int read_bytes; + size_t read_bytes;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-pty.c static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 137
Quoted 10 lines
chardev/char-pty.c +1
-1int connected;GSource *timer_src;@@ -132,7 +132,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); -gsize len; +size_t len;uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret;pty len is only used for non-negative buffer size. ack
chardev/char-socket.c typedef struct { · line 63
Quoted 10 lines
chardev/char-socket.c +1
-1@@ -60,7 +60,7 @@ typedef struct {GSource *hup_source;QCryptoTLSCreds *tls_creds;TCPChardevState state; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-socket.c static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 496
Quoted 9 lines
chardev/char-socket.c +1
-1int do_telnetopt;int do_nodelay;int *read_msgfds;@@ -493,10 +493,11 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque);uint8_t buf[CHR_READ_BUF_LEN ]; -int len, size; +size_t len;len is only used for non-negative buffer size. ack
Quoted 13 lines
chardev/char-socket.c +2
-1+int size;if ((s->state !=TCP_CHARDEV_STATE_CONNECTED ) || - s->max_size <=0 ) { + s->max_size ==0 ) {return TRUE; } len =sizeof (buf);chardev/char-udp.c +0
-0chardev/char-udp.c typedef struct { · line 42
Quoted 5 lines
chardev/char-udp.c +1
-1@@ -39,7 +39,7 @@ typedef struct {uint8_t buf[CHR_READ_BUF_LEN ];int bufcnt;int bufptr; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackchardev/char-udp.c static void udp_chr_flush_buffer(UdpChardev *s) · line 61
Quoted 9 lines
chardev/char-udp.c +1
-1} UdpChardev;#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)@@ -58,7 +58,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)Chardev *chr =CHARDEV (s);while (s->max_size >0 && s->bufptr < s->bufcnt) { -int n =MIN (s->max_size, s->bufcnt - s->bufptr); +size_t n =MIN (s->max_size, s->bufcnt - s->bufptr);the
while()condition ensures the value will be > 0. ackchardev/char-win.c line 32
Quoted 13 lines
chardev/char-udp.c +0
-0qemu_chr_be_write (chr, &s->buf[s->bufptr], n); s->bufptr += n; s->max_size =qemu_chr_be_can_write (chr);chardev/char-win.c +1
-1@@ -29,7 +29,7 @@static void win_chr_read (Chardev *chr,DWORD len) {WinChardev *s =WIN_CHARDEV (chr); -int max_size =qemu_chr_be_can_write (chr); +size_t max_size =qemu_chr_be_can_write (chr);unmodified, ack
Quoted 21 lines
chardev/char-win.c +0
-0int ret, err;uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;chardev/char.c +1
-1@@ -156,7 +156,7 @@ 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 receivable_bytes;chardev/msmouse.c +0
-0chardev/msmouse.c typedef struct { · line 41
Quoted 5 lines
chardev/msmouse.c +1
-1@@ -38,7 +38,7 @@ typedef struct {bool btns[INPUT_BUTTON__MAX ];bool btnc[INPUT_BUTTON__MAX ];uint8_t outbuf[32 ]; -int outlen; +size_t outlen;outlen is only used as non-negative buffer size, ack
chardev/msmouse.c typedef struct { · line 53
Quoted 11 lines
chardev/msmouse.c +1
-1} MouseChardev;#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"@@ -48,7 +48,7 @@ typedef struct {static void msmouse_chr_accept_input (Chardev *chr) {MouseChardev *mouse =MOUSE_CHARDEV (chr); -int len; +size_t len; len =qemu_chr_be_can_write (chr);same
chardev/spice.c static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) · line 46
Quoted 11 lines
chardev/msmouse.c +0
-0if (len > mouse->outlen) {chardev/spice.c +1
-1@@ -43,7 +43,7 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (chr); +size_t can_write =qemu_chr_be_can_write (chr);unmodified value, ack
chardev/wctablet.c typedef struct { · line 77
Quoted 13 lines
chardev/spice.c +0
-0last_out =MIN (len, can_write);if (last_out <=0 ) {break ;chardev/wctablet.c +1
-1@@ -74,7 +74,7 @@ typedef struct {/* Command to be sent to serial port */ uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN ]; -int outlen; +size_t outlen;Used as non-negative buffer size only, ack
chardev/wctablet.c static QemuInputHandler wctablet_handler = { · line 189
Quoted 9 lines
chardev/wctablet.c +1
-1int line_speed;bool send_events;@@ -186,7 +186,7 @@ static QemuInputHandler wctablet_handler = {static void wctablet_chr_accept_input (Chardev *chr) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -int len, canWrite; +size_t len, canWrite;Used as non-negative buffer size only, ack
hw/bt/hci-csr.c struct csrhci_s { · line 41
Quoted 13 lines
chardev/wctablet.c +0
-0canWrite =qemu_chr_be_can_write (chr); len = canWrite;hw/bt/hci-csr.c +1
-1@@ -38,7 +38,7 @@ struct csrhci_s {#define FIFO_LEN 4096int out_start;int out_len; -int out_size; +size_t out_size;Used as non-negative buffer size only, ack
include/chardev/char-fd.h typedef struct FDChardev { · line 34
Quoted 13 lines
hw/bt/hci-csr.c +0
-0uint8_t outfifo[FIFO_LEN *2 ];uint8_t inpkt[FIFO_LEN ];enum {include/chardev/char-fd.h +1
-1@@ -31,7 +31,7 @@ typedef struct FDChardev {Chardev parent;QIOChannel *ioc_in, *ioc_out; -int max_size; +size_t max_size;Only set with values returned from
qemu_chr_be_can_write(), ackQuoted 21 lines
include/chardev/char-fd.h +0
-0} FDChardev;#define TYPE_CHARDEV_FD "chardev-fd"include/chardev/char.h +1
-1@@ -173,7 +173,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: ui/console.c +0
-0ui/console.c enum TTYState { · line 65
Quoted 7 lines
ui/console.c +2
-2@@ -61,8 +61,8 @@ enum TTYState { typedef struct QEMUFIFO { uint8_t *buf; - int buf_size; - int count, wptr, rptr; + size_t buf_size, count; + int wptr, rptr;Only used as non-negative buffer size, ack
ui/console.c static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 1113
Quoted 9 lines
ui/console.c +1
-1}QEMUFIFO ;static int qemu_fifo_write (QEMUFIFO *f,const uint8_t *buf,int len1)@@ -1110,7 +1110,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)static void kbd_send_chars (void *opaque) {QemuConsole *s = opaque; -int len; +size_t len;Only used as non-negative buffer size, ack
Quoted 8 lines
Quoted 6 lines
ui/console.c +0
-1uint8_t buf[16 ]; len =qemu_chr_be_can_write (s->chr); --2.20.1
That was painful, hopefully I didn't miss something...
Quoted 8 lines
As is this series and its rebases...
I hope you will still be as willingful to review the follow up series (part #2) which is worst.
I felt this is pointless to write the same detailed review you did in the commit message, because the reviewer still has to go to each patch and verify.
Sure, but it is still better than nothing :) If you systematically review each change, it doesn't take much more time to write it down. And if there are issues later on, there would be a short rationale for it, even if prooved to be wrong/bad.
Quoted 8 lines
Quoted 4 lines
Reviewed-by Marc-André Lureau <[email protected]>Thanks a lot!
Phil.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 04/25] chardev: Let qemu_chr_be_can_write() return a size_t types
In reply to Philippe Mathieu-DaudéHi
Quoted 5 lines · Philippe Mathieu-Daudé
In the previous commit we added an assert to be sure than
qemu_chr_be_can_write()will never return a negative value. We can now change its prototype to return asize_t. Adapt the backends accordingly.
Each variable you change to an unsigned type, we should check it isn't used with negative values.
Quoted 43 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- chardev/baum.c | 6 +++--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 4 ++-- chardev/char-socket.c | 7 ++++--- chardev/char-udp.c | 4 ++-- chardev/char-win.c | 2 +- chardev/char.c | 2 +- chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/wctablet.c | 4 ++-- hw/bt/hci-csr.c | 2 +- include/chardev/char-fd.h | 2 +- include/chardev/char.h | 2 +- ui/console.c | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-)chardev/baum.c +2
-2@@ -265,7 +265,7 @@ static int baum_deferred_init(BaumChardev *baum)static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum =BAUM_CHARDEV (chr); -int room, first; +size_t room, first;if (!baum->out_buf_used)return ;@@ -292,7 +292,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) {Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf; -int room; +size_t room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC )
chardev/baum.c static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) · line 309
Quoted 8 lines
chardev/baum.c +1
-1@@ -303,7 +303,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Fits */ qemu_chr_be_write (chr, io_buf, len); }else { -int first; +size_t first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ qemu_chr_be_write (chr, io_buf, room);
baum room & first are only used for non-negative capacity values. ack
chardev/char-fd.c static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 49
Quoted 13 lines
chardev/char-fd.c +1
-1@@ -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;
fd len is only used for non-negative buffer size. ack
chardev/char-pty.c line 38
Quoted 11 lines
chardev/char-pty.c +1
-1@@ -34,7 +34,7 @@ typedef struct { Chardev parent; QIOChannel *ioc; - int read_bytes; + size_t read_bytes;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-pty.c static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 137
Quoted 10 lines
chardev/char-pty.c +1
-1int connected;GSource *timer_src;@@ -132,7 +132,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); -gsize len; +size_t len;uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret;
pty len is only used for non-negative buffer size. ack
chardev/char-socket.c typedef struct { · line 63
Quoted 10 lines
chardev/char-socket.c +1
-1@@ -60,7 +60,7 @@ typedef struct {GSource *hup_source;QCryptoTLSCreds *tls_creds;TCPChardevState state; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-socket.c static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) · line 496
Quoted 9 lines
chardev/char-socket.c +1
-1int do_telnetopt;int do_nodelay;int *read_msgfds;@@ -493,10 +493,11 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque);uint8_t buf[CHR_READ_BUF_LEN ]; -int len, size; +size_t len;
len is only used for non-negative buffer size. ack
Quoted 13 lines
chardev/char-socket.c +2
-1+int size;if ((s->state !=TCP_CHARDEV_STATE_CONNECTED ) || - s->max_size <=0 ) { + s->max_size ==0 ) {return TRUE; } len =sizeof (buf);chardev/char-udp.c +0
-0
chardev/char-udp.c typedef struct { · line 42
Quoted 5 lines
chardev/char-udp.c +1
-1@@ -39,7 +39,7 @@ typedef struct {uint8_t buf[CHR_READ_BUF_LEN ];int bufcnt;int bufptr; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
chardev/char-udp.c static void udp_chr_flush_buffer(UdpChardev *s) · line 61
Quoted 9 lines
chardev/char-udp.c +1
-1} UdpChardev;#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP)@@ -58,7 +58,7 @@ static void udp_chr_flush_buffer(UdpChardev *s)Chardev *chr =CHARDEV (s);while (s->max_size >0 && s->bufptr < s->bufcnt) { -int n =MIN (s->max_size, s->bufcnt - s->bufptr); +size_t n =MIN (s->max_size, s->bufcnt - s->bufptr);
the while() condition ensures the value will be > 0. ack
chardev/char-win.c line 32
Quoted 13 lines
chardev/char-udp.c +0
-0qemu_chr_be_write (chr, &s->buf[s->bufptr], n); s->bufptr += n; s->max_size =qemu_chr_be_can_write (chr);chardev/char-win.c +1
-1@@ -29,7 +29,7 @@static void win_chr_read (Chardev *chr,DWORD len) {WinChardev *s =WIN_CHARDEV (chr); -int max_size =qemu_chr_be_can_write (chr); +size_t max_size =qemu_chr_be_can_write (chr);
unmodified, ack
Quoted 21 lines
chardev/char-win.c +0
-0int ret, err;uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;chardev/char.c +1
-1@@ -156,7 +156,7 @@ 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 receivable_bytes;chardev/msmouse.c +0
-0
chardev/msmouse.c typedef struct { · line 41
Quoted 5 lines
chardev/msmouse.c +1
-1@@ -38,7 +38,7 @@ typedef struct {bool btns[INPUT_BUTTON__MAX ];bool btnc[INPUT_BUTTON__MAX ];uint8_t outbuf[32 ]; -int outlen; +size_t outlen;
outlen is only used as non-negative buffer size, ack
chardev/msmouse.c typedef struct { · line 53
Quoted 11 lines
chardev/msmouse.c +1
-1} MouseChardev;#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"@@ -48,7 +48,7 @@ typedef struct {static void msmouse_chr_accept_input (Chardev *chr) {MouseChardev *mouse =MOUSE_CHARDEV (chr); -int len; +size_t len; len =qemu_chr_be_can_write (chr);
same
chardev/spice.c static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) · line 46
Quoted 11 lines
chardev/msmouse.c +0
-0if (len > mouse->outlen) {chardev/spice.c +1
-1@@ -43,7 +43,7 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (chr); +size_t can_write =qemu_chr_be_can_write (chr);
unmodified value, ack
chardev/wctablet.c typedef struct { · line 77
Quoted 13 lines
chardev/spice.c +0
-0last_out =MIN (len, can_write);if (last_out <=0 ) {break ;chardev/wctablet.c +1
-1@@ -74,7 +74,7 @@ typedef struct {/* Command to be sent to serial port */ uint8_t outbuf[WC_OUTPUT_BUF_MAX_LEN ]; -int outlen; +size_t outlen;
Used as non-negative buffer size only, ack
chardev/wctablet.c static QemuInputHandler wctablet_handler = { · line 189
Quoted 9 lines
chardev/wctablet.c +1
-1int line_speed;bool send_events;@@ -186,7 +186,7 @@ static QemuInputHandler wctablet_handler = {static void wctablet_chr_accept_input (Chardev *chr) {TabletChardev *tablet =WCTABLET_CHARDEV (chr); -int len, canWrite; +size_t len, canWrite;
Used as non-negative buffer size only, ack
hw/bt/hci-csr.c struct csrhci_s { · line 41
Quoted 13 lines
chardev/wctablet.c +0
-0canWrite =qemu_chr_be_can_write (chr); len = canWrite;hw/bt/hci-csr.c +1
-1@@ -38,7 +38,7 @@ struct csrhci_s {#define FIFO_LEN 4096int out_start;int out_len; -int out_size; +size_t out_size;
Used as non-negative buffer size only, ack
include/chardev/char-fd.h typedef struct FDChardev { · line 34
Quoted 13 lines
hw/bt/hci-csr.c +0
-0uint8_t outfifo[FIFO_LEN *2 ];uint8_t inpkt[FIFO_LEN ];enum {include/chardev/char-fd.h +1
-1@@ -31,7 +31,7 @@ typedef struct FDChardev {Chardev parent;QIOChannel *ioc_in, *ioc_out; -int max_size; +size_t max_size;
Only set with values returned from qemu_chr_be_can_write(), ack
Quoted 21 lines
include/chardev/char-fd.h +0
-0} FDChardev;#define TYPE_CHARDEV_FD "chardev-fd"include/chardev/char.h +1
-1@@ -173,7 +173,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: ui/console.c +0
-0
ui/console.c enum TTYState { · line 65
Quoted 7 lines
ui/console.c +2
-2@@ -61,8 +61,8 @@ enum TTYState { typedef struct QEMUFIFO { uint8_t *buf; - int buf_size; - int count, wptr, rptr; + size_t buf_size, count; + int wptr, rptr;
Only used as non-negative buffer size, ack
ui/console.c static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) · line 1113
Quoted 9 lines
ui/console.c +1
-1}QEMUFIFO ;static int qemu_fifo_write (QEMUFIFO *f,const uint8_t *buf,int len1)@@ -1110,7 +1110,7 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)static void kbd_send_chars (void *opaque) {QemuConsole *s = opaque; -int len; +size_t len;
Only used as non-negative buffer size, ack
Quoted 6 lines
ui/console.c +0
-1uint8_t buf[16 ]; len =qemu_chr_be_can_write (s->chr); --2.20.1
That was painful, hopefully I didn't miss something...
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 5/25 gdbstub: Use size_t for strlen() return value
In reply to Philippe Mathieu-DaudéSince strlen() returns an unsigned value, it is pointless to convert it to a signed one. Use size_t to hold its return value.
--- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub.c +1 -1
@@ -1693,7 +1693,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } #else /* !CONFIG_USER_ONLY */ else if (strncmp(p, "Rcmd,", 5) == 0) { -int len =strlen (p +5 ); +size_t len =strlen (p +5 );if ((len %2 ) !=0 ) {put_packet (s,"E01" );
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 05/25] gdbstub: Use size_t for strlen() return value
Quoted 5 lines · Philippe Mathieu-Daudé
Since
strlen()returns an unsigned value, it is pointless to convert it to a signed one. Usesize_tto hold its return value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
(it looks like the variable is hiding len from outer scope btw)
Quoted 20 lines
--- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)gdbstub.c +1
-2@@ -1693,7 +1693,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } #else /* !CONFIG_USER_ONLY */ else if (strncmp(p, "Rcmd,", 5) == 0) { -int len =strlen (p +5 ); +size_t len =strlen (p +5 );if ((len %2 ) !=0 ) {put_packet (s,"E01" ); --2.20.1
Re: [PATCH v3 05/25] gdbstub: Use size_t for strlen() return value
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Since
strlen()returns an unsigned value, it is pointless to convert it to a signed one. Usesize_tto hold its return value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
(it looks like the variable is hiding len from outer scope btw)
Quoted 18 lines
--- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)gdbstub.c +1
-2@@ -1693,7 +1693,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } #else /* !CONFIG_USER_ONLY */ else if (strncmp(p, "Rcmd,", 5) == 0) { -int len =strlen (p +5 ); +size_t len =strlen (p +5 );if ((len %2 ) !=0 ) {put_packet (s,"E01" ); --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 6/25 gdbstub: Use size_t to hold GDBState::last_packet_len
In reply to Philippe Mathieu-DaudéIn put_packet_binary() we have:
uint8_t *p;
for(;;) {
p = s->last_packet;
*(p++) = ...
s->last_packet_len = p - s->last_packet;
put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);The 'p' pointer start at s->last_packet, then is only incremented. Since we have "p >= s->last_packet", we are sure than "p - s->last_packet >= 0", thus "p - s->last_packet" is positive.
The few other places where s->last_packet_len is set is with constant positive values.
It makes sense to use size_t to hold last_packet_len values.
--- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub.c +1 -1
@@ -323,7 +323,7 @@ typedef struct GDBState {int line_sum;/* running checksum */ int line_csum;/* checksum at the end of the packet */ uint8_t last_packet[MAX_PACKET_LENGTH +4 ]; -int last_packet_len; +size_t last_packet_len;int signal;#ifdef CONFIG_USER_ONLY int fd;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 06/25] gdbstub: Use size_t to hold GDBState::last_packet_len
Quoted 14 lines · Philippe Mathieu-Daudé
In
put_packet_binary()we have:uint8_t *p; for(;;) { p = s->last_packet; *(p++) = ... s->last_packet_len = p - s->last_packet; put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);The 'p' pointer start at
s->last_packet, then is only incremented. Since we have "p >=s->last_packet", we are sure than "p -s->last_packet>= 0", thus "p -s->last_packet" is positive.
Quoted 6 lines
The few other places where
s->last_packet_lenis set is with constant positive values.It makes sense to use
size_tto holdlast_packet_lenvalues.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 18 lines
--- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)gdbstub.c +1
-2@@ -323,7 +323,7 @@ typedef struct GDBState {int line_sum;/* running checksum */ int line_csum;/* checksum at the end of the packet */ uint8_t last_packet[MAX_PACKET_LENGTH +4 ]; -int last_packet_len; +size_t last_packet_len;int signal;#ifdef CONFIG_USER_ONLY int fd; --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 7/25 gdbstub: Let put_buffer() use size_t
In reply to Philippe Mathieu-DaudéAll callers provide a size_t argument, we can safely use size_t for this function.
--- gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
gdbstub.c +2 -2
@@ -475,10 +475,10 @@ static int gdb_continue_partial(GDBState *s, char *newstates)return res; } -static void put_buffer (GDBState *s,const uint8_t *buf,int len) +static void put_buffer (GDBState *s,const uint8_t *buf,size_t len) {#ifdef CONFIG_USER_ONLY -int ret; +ssize_t ret;while (len >0 ) { ret =send (s->fd, buf, len,0 );
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 07/25] gdbstub: Let put_buffer() use size_t
Quoted 5 lines · Philippe Mathieu-Daudé
All callers provide a
size_targument, we can safely usesize_tfor this function.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 22 lines
--- gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)gdbstub.c +2
-3@@ -475,10 +475,10 @@ static int gdb_continue_partial(GDBState *s, char *newstates)return res; } -static void put_buffer (GDBState *s,const uint8_t *buf,int len) +static void put_buffer (GDBState *s,const uint8_t *buf,size_t len) {#ifdef CONFIG_USER_ONLY -int ret; +ssize_t ret;while (len >0 ) { ret =send (s->fd, buf, len,0 ); --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 8/25 ui/gtk: Remove pointless cast
In reply to Philippe Mathieu-DaudéThe 'size' value is of type 'guint' which is already unsigned. Remove the useless cast.
--- ui/gtk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/gtk.c +1 -1
@@ -1764,7 +1764,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, } } -qemu_chr_be_write (vc->vte.chr, (uint8_t *)text, (unsigned int )size); +qemu_chr_be_write (vc->vte.chr, (uint8_t *)text, size);return TRUE; }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 08/25] ui/gtk: Remove pointless cast
Quoted 4 lines · Philippe Mathieu-Daudé
The 'size' value is of type 'guint' which is already unsigned. Remove the useless cast.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH v3 9/25 vhost-user: Express sizeof with size_t
In reply to Philippe Mathieu-DaudéVHOST_USER_HDR_SIZE uses offsetof(), thus is an expression of type size_t. Update the format string accordingly.
--- hw/virtio/vhost-user.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
hw/virtio/vhost-user.c +8 -6
@@ -215,11 +215,12 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr;uint8_t *p = (uint8_t *) msg; -int r, size =VHOST_USER_HDR_SIZE ; +int r; +size_t size =VHOST_USER_HDR_SIZE ; r =qemu_chr_fe_read_all (chr, p, size);if (r != size) { -error_report ("Failed to read msg header. Read %d instead of %d." +error_report ("Failed to read msg header. Read %d instead of %zu." " Original request %d." , r, size, msg->hdr.request); goto fail; }
@@ -235,7 +236,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)/* validate message size is sane */ if (msg->hdr.size >VHOST_USER_PAYLOAD_SIZE ) {error_report ("Failed to read msg header." -" Size %d exceeds the maximum %zu." , msg->hdr.size, +" Size %u exceeds the maximum %zu." , msg->hdr.size,VHOST_USER_PAYLOAD_SIZE ); goto fail; }
@@ -246,7 +247,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) r =qemu_chr_fe_read_all (chr, p, size);if (r != size) {error_report ("Failed to read msg payload." -" Read %d instead of %d." , r, msg->hdr.size); +" Read %d instead of %u." , r, msg->hdr.size); goto fail; } }
@@ -300,7 +301,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, {struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr; -int ret, size =VHOST_USER_HDR_SIZE + msg->hdr.size; +int ret; +size_t size =VHOST_USER_HDR_SIZE + msg->hdr.size;/* * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE,
@@ -320,7 +322,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, ret =qemu_chr_fe_write_all (chr, (const uint8_t *) msg, size);if (ret != size) {error_report ("Failed to write msg." -" Wrote %d instead of %d." , ret, size); +" Wrote %d instead of %zu." , ret, size);return -1 ; }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 09/25] vhost-user: Express sizeof with size_t
Quoted 5 lines · Philippe Mathieu-Daudé
VHOST_USER_HDR_SIZEusesoffsetof(), thus is an expression of typesize_t. Update the format string accordingly.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 61 lines
--- hw/virtio/vhost-user.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)hw/virtio/vhost-user.c +8
-7@@ -215,11 +215,12 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr;uint8_t *p = (uint8_t *) msg; -int r, size =VHOST_USER_HDR_SIZE ; +int r; +size_t size =VHOST_USER_HDR_SIZE ; r =qemu_chr_fe_read_all (chr, p, size);if (r != size) { -error_report ("Failed to read msg header. Read %d instead of %d." +error_report ("Failed to read msg header. Read %d instead of %zu." " Original request %d." , r, size, msg->hdr.request); goto fail; }@@ -235,7 +236,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)/* validate message size is sane */ if (msg->hdr.size >VHOST_USER_PAYLOAD_SIZE ) {error_report ("Failed to read msg header." -" Size %d exceeds the maximum %zu." , msg->hdr.size, +" Size %u exceeds the maximum %zu." , msg->hdr.size,VHOST_USER_PAYLOAD_SIZE ); goto fail; }@@ -246,7 +247,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) r =qemu_chr_fe_read_all (chr, p, size);if (r != size) {error_report ("Failed to read msg payload." -" Read %d instead of %d." , r, msg->hdr.size); +" Read %d instead of %u." , r, msg->hdr.size); goto fail; } }@@ -300,7 +301,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, {struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr; -int ret, size =VHOST_USER_HDR_SIZE + msg->hdr.size; +int ret; +size_t size =VHOST_USER_HDR_SIZE + msg->hdr.size;/* * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE, @@ -320,7 +322,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, ret =qemu_chr_fe_write_all (chr, (const uint8_t *) msg, size);if (ret != size) {error_report ("Failed to write msg." -" Wrote %d instead of %d." , ret, size); +" Wrote %d instead of %zu." , ret, size);return -1 ; } --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 09/25] vhost-user: Express sizeof with size_t
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
VHOST_USER_HDR_SIZEusesoffsetof(), thus is an expression of typesize_t. Update the format string accordingly.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 63 lines
--- hw/virtio/vhost-user.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)hw/virtio/vhost-user.c +8
-7@@ -215,11 +215,12 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr;uint8_t *p = (uint8_t *) msg; -int r, size =VHOST_USER_HDR_SIZE ; +int r; +size_t size =VHOST_USER_HDR_SIZE ; r =qemu_chr_fe_read_all (chr, p, size);if (r != size) { -error_report ("Failed to read msg header. Read %d instead of %d." +error_report ("Failed to read msg header. Read %d instead of %zu." " Original request %d." , r, size, msg->hdr.request); goto fail; }@@ -235,7 +236,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)/* validate message size is sane */ if (msg->hdr.size >VHOST_USER_PAYLOAD_SIZE ) {error_report ("Failed to read msg header." -" Size %d exceeds the maximum %zu." , msg->hdr.size, +" Size %u exceeds the maximum %zu." , msg->hdr.size,VHOST_USER_PAYLOAD_SIZE ); goto fail; }@@ -246,7 +247,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) r =qemu_chr_fe_read_all (chr, p, size);if (r != size) {error_report ("Failed to read msg payload." -" Read %d instead of %d." , r, msg->hdr.size); +" Read %d instead of %u." , r, msg->hdr.size); goto fail; } }@@ -300,7 +301,8 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, {struct vhost_user *u = dev->opaque;CharBackend *chr = u->user->chr; -int ret, size =VHOST_USER_HDR_SIZE + msg->hdr.size; +int ret; +size_t size =VHOST_USER_HDR_SIZE + msg->hdr.size;/* * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE, @@ -320,7 +322,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, ret =qemu_chr_fe_write_all (chr, (const uint8_t *) msg, size);if (ret != size) {error_report ("Failed to write msg." -" Wrote %d instead of %d." , ret, size); +" Wrote %d instead of %zu." , ret, size);return -1 ; } --2.20.1
PATCH v3 10/25 usb-redir: Verify usbredirparser_write get called with positive count
In reply to Philippe Mathieu-DaudéThe usbredirparser_write handler should never be called with a negative size payload, return an error if this is not the case.
Now that we are sure the 'count' value is positive, make it obvious by casting it to a size_t.
--- hw/usb/redirect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/usb/redirect.c +5 -1
@@ -285,7 +285,11 @@ static int usbredir_write(void *priv, uint8_t *data, int count)return 0 ; } - r =qemu_chr_fe_write (&dev->cs, data, count); +if (count <0 ) { +ERROR ("Illegal write count: %i\n" , count); +return 0 ; + } + r =qemu_chr_fe_write (&dev->cs, data, (size_t )count);if (r < count) {if (!dev->watch) { dev->watch = qemu_chr_fe_add_watch(&dev->cs, G_IO_OUT | G_IO_HUP,
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 10/25] usb-redir: Verify usbredirparser_write get called with positive count
Quoted 4 lines · Philippe Mathieu-Daudé
The
usbredirparser_writehandler should never be called with a negative size payload, return an error if this is not the case.
Now that we are sure the 'count' value is positive, make it obvious by casting it to asize_t.
PATCH v3 11/25 xen: Let xencons_send() take a 'size' argument
In reply to Philippe Mathieu-DaudéThe single caller of xencons_send(), con_event() already use the difference 'con->buffer.size - con->buffer.consumed'. Deduplicate by passing the difference as an argument.
--- hw/char/xen_console.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/char/xen_console.c +7 -5
@@ -144,11 +144,10 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len)xen_pv_send_notify (&con->xendev); } -static void xencons_send (struct XenConsole *con) +static void xencons_send (struct XenConsole *con,ssize_t size) { -ssize_t len, size; +ssize_t len; - size = con->buffer.size - con->buffer.consumed;if (qemu_chr_fe_backend_connected (&con->chr)) { len = qemu_chr_fe_write(&con->chr, con->buffer.data + con->buffer.consumed,
@@ -280,10 +279,13 @@ static void con_disconnect(struct XenLegacyDevice *xendev)static void con_event (struct XenLegacyDevice *xendev) { struct XenConsole *con = container_of(xendev, struct XenConsole, xendev); +ssize_t size;buffer_append (con); -if (con->buffer.size - con->buffer.consumed) -xencons_send (con); + size = con->buffer.size - con->buffer.consumed; +if (size) { +xencons_send (con, size); + } }/* -------------------------------------------------------------------- */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 11/25] xen: Let xencons_send() take a 'size' argument
Quoted 6 lines · Philippe Mathieu-Daudé
The single caller of
xencons_send(),con_event()already use the difference 'con->buffer.size-con->buffer.consumed'. Deduplicate by passing the difference as an argument.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 39 lines
--- hw/char/xen_console.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/char/xen_console.c +7
-6@@ -144,11 +144,10 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len)xen_pv_send_notify (&con->xendev); } -static void xencons_send (struct XenConsole *con) +static void xencons_send (struct XenConsole *con,ssize_t size) { -ssize_t len, size; +ssize_t len; - size = con->buffer.size - con->buffer.consumed;if (qemu_chr_fe_backend_connected (&con->chr)) { len = qemu_chr_fe_write(&con->chr, con->buffer.data + con->buffer.consumed,@@ -280,10 +279,13 @@ static void con_disconnect(struct XenLegacyDevice *xendev)static void con_event (struct XenLegacyDevice *xendev) { struct XenConsole *con = container_of(xendev, struct XenConsole, xendev); +ssize_t size;buffer_append (con); -if (con->buffer.size - con->buffer.consumed) -xencons_send (con); + size = con->buffer.size - con->buffer.consumed; +if (size) { +xencons_send (con, size); + } }/* -------------------------------------------------------------------- */ --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 11/25] xen: Let xencons_send() take a 'size' argument
In reply to Philippe Mathieu-DaudéQuoted 53 lines
-----Original Message-----
From: Philippe Mathieu-Daudé [mailto:[email protected]]
Sent: 20 February 2019 01:02
To: [email protected]; Prasad J Pandit <[email protected]>; Marc- André Lureau <[email protected]>; Paolo Bonzini <[email protected]>
Cc: Jason Wang <[email protected]>; Anthony Perard <[email protected]>; [email protected]; Stefan Berger <[email protected]>; David Gibson <[email protected]>; Gerd Hoffmann <[email protected]>; Zhang Chen <[email protected]>; xen- [email protected]; Cornelia Huck <[email protected]>; Samuel Thibault <[email protected]>; Christian Borntraeger <[email protected]>; Amit Shah <[email protected]>; Li Zhijian <[email protected]>; Corey Minyard <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Halil Pasic <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Pavel Dovgalyuk <[email protected]>; Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 11/25] xen: Letxencons_send()take a 'size' argumentThe single caller of
xencons_send(),con_event()already use the difference 'con->buffer.size-con->buffer.consumed'. Deduplicate by passing the difference as an argument.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/xen_console.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/char/xen_console.c +2
-3@@ -144,11 +144,10 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) xen_pv_send_notify(&con->xendev); } -static void xencons_send (struct XenConsole *con) +static void xencons_send (struct XenConsole *con,ssize_t size) { -ssize_t len, size; +ssize_t len; - size = con->buffer.size - con->buffer.consumed;if (qemu_chr_fe_backend_connected (&con->chr)) { len = qemu_chr_fe_write(&con->chr,con->buffer.data + con->buffer.consumed,hw/char/xen_console.c +0
-0@@ -280,10 +279,13 @@ static void con_disconnect(struct XenLegacyDevice *xendev)static void con_event (struct XenLegacyDevice *xendev) { struct XenConsole *con = container_of(xendev, struct XenConsole,
hw/char/xen_console.c static void con_disconnect(struct XenLegacyDevice · line 290
Quoted 10 lines
hw/char/xen_console.c +5
-2xendev); +ssize_t size;buffer_append (con); -if (con->buffer.size - con->buffer.consumed) -xencons_send (con); + size = con->buffer.size - con->buffer.consumed; +if (size) { +xencons_send (con, size); + }
You introduce this here, only to modify it in patch #12. Why not squash the two together?
Paul
Quoted 6 lines
hw/char/xen_console.c +0
-0}/* --------------------------------------------------------------------
*/
--
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 12/25 xen: Let buffer_append() return the size consumed
In reply to Philippe Mathieu-DaudéThe buffer.size and buffer.consumed fields are only updated within the buffer_append() body. We can simply let buffer_append() return the difference (the buffer consumed).
--- hw/char/xen_console.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
hw/char/xen_console.c +8 -5
@@ -48,7 +48,7 @@ struct XenConsole {int backlog; }; -static void buffer_append (struct XenConsole *con) +static ssize_t buffer_append (struct XenConsole *con) {struct buffer *buffer = &con->buffer;XENCONS_RING_IDX cons, prod, size;
@@ -59,8 +59,9 @@ static void buffer_append(struct XenConsole *con)xen_mb (); size = prod - cons; -if ((size ==0 ) || (size >sizeof (intf->out))) -return ; +if ((size ==0 ) || (size >sizeof (intf->out))) { + goto out; + }if ((buffer->capacity - buffer->size) < size) { buffer->capacity += (size +1024 );
@@ -89,6 +90,9 @@ static void buffer_append(struct XenConsole *con)if (buffer->consumed > buffer->max_capacity - over) buffer->consumed = buffer->max_capacity - over; } + + out: +return buffer->size - buffer->consumed; }static void buffer_advance (struct buffer *buffer,size_t len)
@@ -281,8 +285,7 @@ static void con_event(struct XenLegacyDevice *xendev) struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);ssize_t size; -buffer_append (con); - size = con->buffer.size - con->buffer.consumed; + size =buffer_append (con);if (size) {xencons_send (con, size); }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 12/25] xen: Let buffer_append() return the size consumed
Hi
Quoted 6 lines · Philippe Mathieu-Daudé
The buffer.size and buffer.consumed fields are only updated within the
buffer_append()body. We can simply letbuffer_append()return the difference (the buffer consumed).Signed-off-by Philippe Mathieu-Daudé <[email protected]>
This is weird, why not introduce a buffer_size() function instead?
Quoted 50 lines
--- hw/char/xen_console.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)hw/char/xen_console.c +8
-6@@ -48,7 +48,7 @@ struct XenConsole {int backlog; }; -static void buffer_append (struct XenConsole *con) +static ssize_t buffer_append (struct XenConsole *con) {struct buffer *buffer = &con->buffer;XENCONS_RING_IDX cons, prod, size;@@ -59,8 +59,9 @@ static void buffer_append(struct XenConsole *con)xen_mb (); size = prod - cons; -if ((size ==0 ) || (size >sizeof (intf->out))) -return ; +if ((size ==0 ) || (size >sizeof (intf->out))) { + goto out; + }if ((buffer->capacity - buffer->size) < size) { buffer->capacity += (size +1024 );@@ -89,6 +90,9 @@ static void buffer_append(struct XenConsole *con)if (buffer->consumed > buffer->max_capacity - over) buffer->consumed = buffer->max_capacity - over; } + + out: +return buffer->size - buffer->consumed; }static void buffer_advance (struct buffer *buffer,size_t len)@@ -281,8 +285,7 @@ static void con_event(struct XenLegacyDevice *xendev) struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);ssize_t size; -buffer_append (con); - size = con->buffer.size - con->buffer.consumed; + size =buffer_append (con);if (size) {xencons_send (con, size); } --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH v3 13/25 xen: Let buffer_append() return a size_t
In reply to Philippe Mathieu-DaudéTo the Xen team: this is not trivial to me to demonstrate this assertion can never happen, but then the whole series is justified and I can convert qemu_chr_fe_write() to use size_t argument.
Can you help me here?
--- hw/char/xen_console.c | 1 + 1 file changed, 1 insertion(+)
hw/char/xen_console.c +1 -0
@@ -92,6 +92,7 @@ static ssize_t buffer_append(struct XenConsole *con) } out: +assert (buffer->size >= buffer->consumed);return buffer->size - buffer->consumed; }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [RFC PATCH v3 13/25] xen: Let buffer_append() return a size_t
Quoted 22 lines
-----Original Message-----
From: Philippe Mathieu-Daudé [mailto:[email protected]]
Sent: 20 February 2019 01:02
To: [email protected]; Prasad J Pandit <[email protected]>; Marc- André Lureau <[email protected]>; Paolo Bonzini <[email protected]>
Cc: Jason Wang <[email protected]>; Anthony Perard <[email protected]>; [email protected]; Stefan Berger <[email protected]>; David Gibson <[email protected]>; Gerd Hoffmann <[email protected]>; Zhang Chen <[email protected]>; xen- [email protected]; Cornelia Huck <[email protected]>; Samuel Thibault <[email protected]>; Christian Borntraeger <[email protected]>; Amit Shah <[email protected]>; Li Zhijian <[email protected]>; Corey Minyard <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Halil Pasic <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Pavel Dovgalyuk <[email protected]>; Philippe Mathieu-Daudé <[email protected]>
Subject: [RFC PATCH v3 13/25] xen: Letbuffer_append()return asize_t
Quoted 5 lines
To the Xen team: this is not trivial to me to demonstrate this assertion can never happen, but then the whole series is justified and I can convert
qemu_chr_fe_write()to usesize_targument.
Can you help me here?
I'm not particularly familiar with this bit of code but I can try...
Quoted 11 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/xen_console.c | 1 + 1 file changed, 1 insertion(+)hw/char/xen_console.c +0
-0
hw/char/xen_console.c static ssize_t buffer_append(struct XenConsole *con) · line 96
Quoted 5 lines
hw/char/xen_console.c +1
-0@@ -92,6 +92,7 @@ static ssize_t buffer_append(struct XenConsole *con) } out: +assert (buffer->size >= buffer->consumed);return buffer->size - buffer->consumed;
I think this assertion is reasonable as:
- buffer_advance() appears to hit a termination condition when buffer->consumed == buffer->size. (Nothing checks for overflow which is bad, but that fact also lends weight to the assertion that consumed > size is a bug).
- if buffer->size ever exceeds buffer->max_capacity then both size and consumed are re-calculated such that consumed <= size.
Paul
Quoted 4 lines
hw/char/xen_console.c +0
-1} --2.20.1
PATCH v3 14/25 virtio-serial: Let VirtIOSerialPortClass::have_data() use size_t
In reply to Philippe Mathieu-DaudéBoth callers in hw/char/virtio-serial-bus.c provide unsigned values, even the trace event display an unsigned value.
Convert the have_data() handler to take an unsigned value.
---
It is funny/scary that there are big comments about how to treat errors to set the return value, then the return value is simply ignored by the caller.
--- hw/char/virtio-console.c | 2 +- include/hw/virtio/virtio-serial.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/char/virtio-console.c +1 -1
@@ -45,7 +45,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,/* Callback function that's called when the guest sends us data */ static ssize_t flush_buf (VirtIOSerialPort *port, -const uint8_t *buf,ssize_t len) +const uint8_t *buf,size_t len) {VirtConsole *vcon =VIRTIO_CONSOLE (port);ssize_t ret;
include/hw/virtio/virtio-serial.h +1 -1
@@ -81,7 +81,7 @@ typedef struct VirtIOSerialPortClass {* 'len'. In this case, throttling will be enabled for this port. */ ssize_t (*have_data)(VirtIOSerialPort *port,const uint8_t *buf, -ssize_t len); +size_t len); } VirtIOSerialPortClass;/*
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 14/25] virtio-serial: Let VirtIOSerialPortClass::have_data() use size_t
Quoted 6 lines · Philippe Mathieu-Daudé
Both callers in
hw/char/virtio-serial-bus.cprovide unsigned values, even the trace event display an unsigned value.
Convert thehave_data()handler to take an unsigned value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 4 lines
---
It is funny/scary that there are big comments about how to treat errors to set the return value, then the return value is simply ignored by the caller.
have_data() return value? yes, the code may have change and the comment doesn't seem to reflect accurately what's going on.
Quoted 32 lines
--- hw/char/virtio-console.c | 2 +- include/hw/virtio/virtio-serial.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/char/virtio-console.c +1
-1@@ -45,7 +45,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,/* Callback function that's called when the guest sends us data */ static ssize_t flush_buf (VirtIOSerialPort *port, -const uint8_t *buf,ssize_t len) +const uint8_t *buf,size_t len) {VirtConsole *vcon =VIRTIO_CONSOLE (port);ssize_t ret;include/hw/virtio/virtio-serial.h +1
-2@@ -81,7 +81,7 @@ typedef struct VirtIOSerialPortClass {* 'len'. In this case, throttling will be enabled for this port. */ ssize_t (*have_data)(VirtIOSerialPort *port,const uint8_t *buf, -ssize_t len); +size_t len); } VirtIOSerialPortClass;/* --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 15/25 spapr-vty: Let vty_putchars() use size_t
In reply to Philippe Mathieu-DaudéBoth callers (h_put_term_char and rtas_display_character) use an unsigned value.
--- hw/char/spapr_vty.c | 2 +- include/hw/ppc/spapr_vio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/char/spapr_vty.c +1 -1
@@ -83,7 +83,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)return n; } -void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len) +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,size_t len) {VIOsPAPRVTYDevice *dev =VIO_SPAPR_VTY_DEVICE (sdev);
include/hw/ppc/spapr_vio.h +1 -1
@@ -126,7 +126,7 @@ static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,int spapr_vio_send_crq (VIOsPAPRDevice *dev,uint8_t *crq);VIOsPAPRDevice *vty_lookup (sPAPRMachineState *spapr,target_ulong reg); -void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,size_t len);void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev);void spapr_vlan_create (VIOsPAPRBus *bus,NICInfo *nd);void spapr_vscsi_create (VIOsPAPRBus *bus);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 15/25] spapr-vty: Let vty_putchars() use size_t
Quoted 4 lines · Philippe Mathieu-Daudé
Both callers (
h_put_term_charandrtas_display_character) use an unsigned value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 31 lines
--- hw/char/spapr_vty.c | 2 +- include/hw/ppc/spapr_vio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/char/spapr_vty.c +1
-1@@ -83,7 +83,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)return n; } -void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len) +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,size_t len) {VIOsPAPRVTYDevice *dev =VIO_SPAPR_VTY_DEVICE (sdev);include/hw/ppc/spapr_vio.h +1
-1@@ -126,7 +126,7 @@ static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,int spapr_vio_send_crq (VIOsPAPRDevice *dev,uint8_t *crq);VIOsPAPRDevice *vty_lookup (sPAPRMachineState *spapr,target_ulong reg); -void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,size_t len);void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev);void spapr_vlan_create (VIOsPAPRBus *bus,NICInfo *nd);void spapr_vscsi_create (VIOsPAPRBus *bus);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 16/25 tpm: Use size_t to hold sizes
In reply to Philippe Mathieu-DaudéAvoid to use a signed type to hold an unsigned value.
--- hw/tpm/tpm_emulator.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/tpm/tpm_emulator.c +4 -3
@@ -87,17 +87,18 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg, {CharBackend *dev = &tpm->ctrl_chr;uint32_t cmd_no =cpu_to_be32 (cmd); -ssize_t n =sizeof (uint32_t ) + msg_len_in; +size_t sz =sizeof (uint32_t ) + msg_len_in; +ssize_t n;uint8_t *buf =NULL ;int ret =-1 ;qemu_mutex_lock (&tpm->mutex); - buf =g_alloca (n); + buf =g_alloca (sz);memcpy (buf, &cmd_no,sizeof (cmd_no));memcpy (buf +sizeof (cmd_no), msg, msg_len_in); - n =qemu_chr_fe_write_all (dev, buf, n); + n =qemu_chr_fe_write_all (dev, buf, sz);if (n <=0 ) { goto end; }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 16/25] tpm: Use size_t to hold sizes
Quoted 4 lines · Philippe Mathieu-Daudé
Avoid to use a signed type to hold an unsigned value.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 31 lines
--- hw/tpm/tpm_emulator.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/tpm/tpm_emulator.c +4
-4@@ -87,17 +87,18 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg, {CharBackend *dev = &tpm->ctrl_chr;uint32_t cmd_no =cpu_to_be32 (cmd); -ssize_t n =sizeof (uint32_t ) + msg_len_in; +size_t sz =sizeof (uint32_t ) + msg_len_in; +ssize_t n;uint8_t *buf =NULL ;int ret =-1 ;qemu_mutex_lock (&tpm->mutex); - buf =g_alloca (n); + buf =g_alloca (sz);memcpy (buf, &cmd_no,sizeof (cmd_no));memcpy (buf +sizeof (cmd_no), msg, msg_len_in); - n =qemu_chr_fe_write_all (dev, buf, n); + n =qemu_chr_fe_write_all (dev, buf, sz);if (n <=0 ) { goto end; } --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 17/25 net/filter-mirror: Use size_t
In reply to Philippe Mathieu-DaudéSince iov_size() returns a size_t, no need to use a signed type.
--- net/filter-mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/filter-mirror.c +1 -1
@@ -48,7 +48,7 @@ static int filter_send(MirrorState *s, {NetFilterState *nf =NETFILTER (s);int ret =0 ; -ssize_t size =0 ; +size_t size =0 ;uint32_t len =0 ;char *buf;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 17/25] net/filter-mirror: Use size_t
Hi
Quoted 2 lines · Philippe Mathieu-Daudé
Since
iov_size()returns asize_t, no need to use a signed type.
And it is the variable only purpose.
Quoted 2 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 20 lines
--- net/filter-mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/filter-mirror.c +1
-2@@ -48,7 +48,7 @@ static int filter_send(MirrorState *s, {NetFilterState *nf =NETFILTER (s);int ret =0 ; -ssize_t size =0 ; +size_t size =0 ;uint32_t len =0 ;char *buf; --2.20.1
PATCH v3 18/25 s390x/3270: Let insert_IAC_escape_char() use size_t
In reply to Philippe Mathieu-DaudéThis function takes size_t argument and return a size_t.
--- hw/char/terminal3270.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/terminal3270.c +4 -3
@@ -199,9 +199,10 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) }/* TN3270 uses binary transmission, which needs escape IAC to IAC IAC */ -static int insert_IAC_escape_char (uint8_t *outv,int out_len) +static size_t insert_IAC_escape_char (uint8_t *outv,size_t out_len) { -int IAC_num =0 , new_out_len, i, j; +size_t new_out_len; +int IAC_num =0 , i, j;for (i =0 ; i < out_len; i++) {if (outv[i] ==IAC ) {
@@ -232,7 +233,7 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd)int count =ccw_dstream_avail (get_cds (t));int bound = (OUTPUT_BUFFER_SIZE -3 ) /2 ;int len =MIN (count, bound); -int out_len =0 ; +size_t out_len =0 ;if (!t->handshake_done) {if (!(t->outv[0 ] ==IAC && t->outv[1 ] !=IAC )) {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 18/25] s390x/3270: Let insert_IAC_escape_char() use size_t
Quoted 6 lines · On Wed, 20 Feb 2019 02:02:25 +0100 Philippe Mathieu-Daudé <[email protected]>…
This function takes
size_targument and return asize_t.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/terminal3270.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 18/25] s390x/3270: Let insert_IAC_escape_char() use size_t
In reply to Philippe Mathieu-DaudéQuoted 6 lines · On Wed, 20 Feb 2019 02:02:25 +0100 Philippe Mathieu-Daudé <[email protected]>…
This function takes
size_targument and return asize_t.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/terminal3270.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
PATCH v3 19/25 s390/ebcdic: Use size_t to iterate over arrays
In reply to Philippe Mathieu-Daudé--- include/hw/s390x/ebcdic.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/s390x/ebcdic.h +4 -4
@@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = { 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF }; -static inline void ebcdic_put (uint8_t *p,const char *ascii,int len) +static inline void ebcdic_put (uint8_t *p,const char *ascii,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ascii2ebcdic[(uint8_t )ascii[i]]; } } -static inline void ascii_put (uint8_t *p,const char *ebcdic,int len) +static inline void ascii_put (uint8_t *p,const char *ebcdic,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ebcdic2ascii[(uint8_t )ebcdic[i]];
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
Quoted 22 lines · On Wed, 20 Feb 2019 02:02:26 +0100 Philippe Mathieu-Daudé <[email protected]>…
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/s390x/ebcdic.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/hw/s390x/ebcdic.h +2
-2@@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = { 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF }; -static inline void ebcdic_put (uint8_t *p,const char *ascii,int len) +static inline void ebcdic_put (uint8_t *p,const char *ascii,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ascii2ebcdic[(uint8_t )ascii[i]]; }
include/hw/s390x/ebcdic.h static const uint8_t ascii2ebcdic[] = { · line 100
Quoted 10 lines
include/hw/s390x/ebcdic.h +2
-2} -static inline void ascii_put (uint8_t *p,const char *ebcdic,int len) +static inline void ascii_put (uint8_t *p,const char *ebcdic,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ebcdic2ascii[(uint8_t )ebcdic[i]];
Making the passed len parameter a size_t makes sense; but using a size_t as an array iterator looks a bit unidiomatic... it's not wrong, though.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
Quoted 33 lines · Cornelia Huck
Quoted 30 lines · On Wed, 20 Feb 2019 02:02:26 +0100 Philippe Mathieu-Daudé <[email protected]>…
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/s390x/ebcdic.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/hw/s390x/ebcdic.h +4
-4@@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = { 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF }; -static inline void ebcdic_put (uint8_t *p,const char *ascii,int len) +static inline void ebcdic_put (uint8_t *p,const char *ascii,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ascii2ebcdic[(uint8_t )ascii[i]]; } } -static inline void ascii_put (uint8_t *p,const char *ebcdic,int len) +static inline void ascii_put (uint8_t *p,const char *ebcdic,size_t len) { -int i; +size_t i;
Quoted 6 lines
include/hw/s390x/ebcdic.h static const uint8_t ascii2ebcdic[] = { · line 100
Quoted 2 lines
include/hw/s390x/ebcdic.h +0
-0for (i =0 ; i < len; i++) { p[i] = ebcdic2ascii[(uint8_t )ebcdic[i]];Making the passed len parameter a
size_tmakes sense; but using asize_tas an array iterator looks a bit unidiomatic... it's not wrong, though.
This is to silent the "-Wsign-conversion -Wsign-compare" warnings... I am still not sure what is the best to do.
Quoted 1 line
Acked-by Cornelia Huck <[email protected]>
Thanks!
Phil.
Re: [PATCH v3 19/25] s390/ebcdic: Use size_t to iterate over arrays
In reply to Cornelia HuckQuoted 33 lines · Cornelia Huck
Quoted 30 lines · On Wed, 20 Feb 2019 02:02:26 +0100 Philippe Mathieu-Daudé <[email protected]>…
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/s390x/ebcdic.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)include/hw/s390x/ebcdic.h +4
-4@@ -83,18 +83,18 @@ static const uint8_t ascii2ebcdic[] = { 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF }; -static inline void ebcdic_put (uint8_t *p,const char *ascii,int len) +static inline void ebcdic_put (uint8_t *p,const char *ascii,size_t len) { -int i; +size_t i;for (i =0 ; i < len; i++) { p[i] = ascii2ebcdic[(uint8_t )ascii[i]]; } } -static inline void ascii_put (uint8_t *p,const char *ebcdic,int len) +static inline void ascii_put (uint8_t *p,const char *ebcdic,size_t len) { -int i; +size_t i;
Quoted 6 lines
include/hw/s390x/ebcdic.h static const uint8_t ascii2ebcdic[] = { · line 100
Quoted 2 lines
include/hw/s390x/ebcdic.h +0
-0for (i =0 ; i < len; i++) { p[i] = ebcdic2ascii[(uint8_t )ebcdic[i]];Making the passed len parameter a
size_tmakes sense; but using asize_tas an array iterator looks a bit unidiomatic... it's not wrong, though.
This is to silent the "-Wsign-conversion -Wsign-compare" warnings... I am still not sure what is the best to do.
Quoted 1 line
Acked-by Cornelia Huck <[email protected]>
Thanks!
Phil.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 20/25 s390x/sclp: Use a const variable to improve readability
In reply to Philippe Mathieu-DaudéWe will reuse this variable in the next patch.
--- hw/char/sclpconsole-lm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/sclpconsole-lm.c +4 -3
@@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)int rc;int len;uint8_t buffer[SIZE_BUFFER ]; - - len =be16_to_cpu (mdbo->length); - len -=sizeof (mdbo->length) +sizeof (mdbo->type) +const size_t hlen =sizeof (mdbo->length) + +sizeof (mdbo->type) +sizeof (mdbo->mto.line_type_flags) +sizeof (mdbo->mto.alarm_control) +sizeof (mdbo->mto._reserved); + len =be16_to_cpu (mdbo->length); + len -= hlen;assert (len <=SIZE_BUFFER );/* convert EBCDIC SCLP contents to ASCII console message */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability
Quoted 19 lines · On Wed, 20 Feb 2019 02:02:27 +0100 Philippe Mathieu-Daudé <[email protected]>…
We will reuse this variable in the next patch.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/sclpconsole-lm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/char/sclpconsole-lm.c +1
-3@@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)int rc;int len;uint8_t buffer[SIZE_BUFFER ]; - - len =be16_to_cpu (mdbo->length); - len -=sizeof (mdbo->length) +sizeof (mdbo->type) +const size_t hlen =sizeof (mdbo->length)
hw/char/sclpconsole-lm.c static int process_mdb(SCLPEvent *event, MDBO *mdbo) · line 223
Quoted 10 lines
hw/char/sclpconsole-lm.c +3
-0+ +sizeof (mdbo->type) +sizeof (mdbo->mto.line_type_flags) +sizeof (mdbo->mto.alarm_control) +sizeof (mdbo->mto._reserved); + len =be16_to_cpu (mdbo->length); + len -= hlen;assert (len <=SIZE_BUFFER );/* convert EBCDIC SCLP contents to ASCII console message */
I'd probably merge this with the next patch, though.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability
Quoted 27 lines · Cornelia Huck
Quoted 24 lines · On Wed, 20 Feb 2019 02:02:27 +0100 Philippe Mathieu-Daudé <[email protected]>…
We will reuse this variable in the next patch.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/sclpconsole-lm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/char/sclpconsole-lm.c +2
-3@@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)int rc;int len;uint8_t buffer[SIZE_BUFFER ]; - - len =be16_to_cpu (mdbo->length); - len -=sizeof (mdbo->length) +sizeof (mdbo->type) +const size_t hlen =sizeof (mdbo->length) + +sizeof (mdbo->type) +sizeof (mdbo->mto.line_type_flags) +sizeof (mdbo->mto.alarm_control) +sizeof (mdbo->mto._reserved);
Quoted 7 lines
hw/char/sclpconsole-lm.c static int process_mdb(SCLPEvent *event, MDBO *mdbo) · line 223
Quoted 5 lines
hw/char/sclpconsole-lm.c +2
-0+ len =be16_to_cpu (mdbo->length); + len -= hlen;assert (len <=SIZE_BUFFER );/* convert EBCDIC SCLP contents to ASCII console message */ I'd probably merge this with the next patch, though.
The context is easier to review in 2 different patches IMHO.
Quoted 2 lines
Reviewed-by Cornelia Huck <[email protected]>
Thanks!
Phil.
PATCH v3 21/25 s390x/sclp: Use size_t in process_mdb()
In reply to Philippe Mathieu-DaudéSince it is unlikely we have sizeof(mdbo->mto.message) < 0, we can convert this variable to an unsigned type.
--- hw/char/sclpconsole-lm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/char/sclpconsole-lm.c +2 -1
@@ -208,7 +208,7 @@ static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len)static int process_mdb (SCLPEvent *event,MDBO *mdbo) {int rc; -int len; +uint16_t len;uint8_t buffer[SIZE_BUFFER ];const size_t hlen =sizeof (mdbo->length) +sizeof (mdbo->type)
@@ -217,6 +217,7 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo) +sizeof (mdbo->mto._reserved); len =be16_to_cpu (mdbo->length); +assert (len >= hlen); len -= hlen;assert (len <=SIZE_BUFFER );
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 21/25] s390x/sclp: Use size_t in process_mdb()
Quoted 7 lines · On Wed, 20 Feb 2019 02:02:28 +0100 Philippe Mathieu-Daudé <[email protected]>…
Since it is unlikely we have
sizeof(mdbo->mto.message)< 0, we can convert this variable to an unsigned type.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/sclpconsole-lm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 22/25 s390x/sclp: Let write_console_data() take a size_t
In reply to Philippe Mathieu-DaudéSince all callers provide an unsigned value, we can safely use a size_t argument.
--- hw/char/sclpconsole-lm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/char/sclpconsole-lm.c +1 -1
@@ -191,7 +191,7 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,* - write console data to character layer * returns < 0 if an error occurred */ -static int write_console_data (SCLPEvent *event,const uint8_t *buf,int len) +static int write_console_data (SCLPEvent *event,const uint8_t *buf,size_t len) {SCLPConsoleLM *scon =SCLPLM_CONSOLE (event);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 22/25] s390x/sclp: Let write_console_data() take a size_t
Quoted 7 lines · On Wed, 20 Feb 2019 02:02:29 +0100 Philippe Mathieu-Daudé <[email protected]>…
Since all callers provide an unsigned value, we can safely use a
size_targument.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/char/sclpconsole-lm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 23/25 hw/ipmi: Assert outlen > outpos
In reply to Philippe Mathieu-DaudéA througfull audit show that all time data is added to outbuf[], 'outlen' is incremented. Then at creation and each time continue_send() returns it pass thru check_reset which resets 'outpos', thus we always have 'outlen >= outpos'.
Also due to the check on entry, we know outlen != 0. We can then add an assertion on 'outlen > outpos', which will helps the next patch to safely convert 'outlen - outpos' as an unsigned type (size_t).
Make this assertion explicit by casting 'outlen - outpos' size_t.
--- hw/ipmi/ipmi_bmc_extern.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_extern.c +2 -1
@@ -107,8 +107,9 @@ static void continue_send(IPMIBmcExtern *ibe) goto check_reset; } send: +assert (ibe->outlen > ibe->outpos); ret =qemu_chr_fe_write (&ibe->chr, ibe->outbuf + ibe->outpos, - ibe->outlen - ibe->outpos); + (size_t )(ibe->outlen - ibe->outpos));if (ret >0 ) { ibe->outpos += ret; }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 23/25] hw/ipmi: Assert outlen > outpos
Quoted 4 lines · Philippe Mathieu-Daudé
A througfull audit show that all time data is added to outbuf[], 'outlen' is incremented. Then at creation and each time
continue_send()returns it pass thrucheck_resetwhich resets 'outpos', thus we always have 'outlen >= outpos'.
Perhaps: "A thorough audit shows that outlen is always incremented when data is always added to outbuf[]. Then at creation and each time continus_send() returns it assures if outpos reaches outlen, both values are reset to zero, except in the case of sending a reset where a new command is added."
This is certainly the design intent, thank you for the thorough audit.
Quoted 3 lines
Also due to the check on entry, we know outlen != 0. We can then add an assertion on 'outlen > outpos', which will helps the next patch to safely convert 'outlen - outpos' as an
I was a little confused by "next patch", there is no following patch in the series for this. Maybe "next part of the patch"?
Quoted 5 lines
unsigned type (
size_t).Make this assertion explicit by casting 'outlen - outpos'
size_t.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Outside of the minor grammer issues, this looks good. I have noticed the inconsistent signed/unsigned usage in qemu and IMHO it's likely to lead to very bad bugs at some point. There have been studies that show that unsigned values tend to be more buggy in usage due to underflows, but for a length value that will eventually be converted to an unsigned value, what is here is better, I think.
Both outpos and outlen are unsigned, so the size_t() cast is not really necessary, but I guess it makes it clear.
Quoted 22 lines
--- hw/ipmi/ipmi_bmc_extern.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/ipmi/ipmi_bmc_extern.c +2
-1@@ -107,8 +107,9 @@ static void continue_send(IPMIBmcExtern *ibe) goto check_reset; } send: +assert (ibe->outlen > ibe->outpos); ret =qemu_chr_fe_write (&ibe->chr, ibe->outbuf + ibe->outpos, - ibe->outlen - ibe->outpos); + (size_t )(ibe->outlen - ibe->outpos));if (ret >0 ) { ibe->outpos += ret; }Signature · 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 23/25] hw/ipmi: Assert outlen > outpos
In reply to Philippe Mathieu-DaudéHi
Quoted 2 lines · Philippe Mathieu-Daudé
A througfull audit show that all time data is added to outbuf[],
througfull? :) thorough?
Quoted 5 lines
'outlen' is incremented. Then at creation and each time
continue_send()returns it pass thrucheck_resetwhich resets 'outpos', thus we always have 'outlen >= outpos'. Also due to the check on entry, we know outlen != 0. We can then add an assertion on 'outlen > outpos', which will
hmm, I think you could assert 'outlen >= outpos' only. I don't buy your argument about 'outlen > outpos' (because outlen != 0?)
Quoted 26 lines
helps the next patch to safely convert 'outlen - outpos' as an unsigned type (
size_t).Make this assertion explicit by casting 'outlen - outpos'
size_t.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ipmi/ipmi_bmc_extern.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/ipmi/ipmi_bmc_extern.c +2
-2@@ -107,8 +107,9 @@ static void continue_send(IPMIBmcExtern *ibe) goto check_reset; } send: +assert (ibe->outlen > ibe->outpos); ret =qemu_chr_fe_write (&ibe->chr, ibe->outbuf + ibe->outpos, - ibe->outlen - ibe->outpos); + (size_t )(ibe->outlen - ibe->outpos));if (ret >0 ) { ibe->outpos += ret; } --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 24/25 chardev: Let qemu_chr_fe_write[_all] use size_t type argument
In reply to Philippe Mathieu-DaudéAll caller have been audited and call these functions with unsigned arguments.
Most of them use a size_t argument, or directly pass sizeof().
One case is unclear: the mux_chr_write() call in chardev/char-mux.c. There we add an assert (which will be removed in few patches) and cast the parameter as size_t to make explicit this value is unsigned.
--- chardev/char-fe.c | 4 ++-- chardev/char-mux.c | 3 ++- include/chardev/char-fe.h | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)
chardev/char-fe.c +2 -2
@@ -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) +int 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) +int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,size_t len) {Chardev *s = be->chr;
chardev/char-mux.c +2 -1
@@ -38,7 +38,8 @@ static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len)MuxChardev *d =MUX_CHARDEV (chr);int ret;if (!d->timestamps) { - ret =qemu_chr_fe_write (&d->chr, buf, len); +assert (len >=0 ); + ret =qemu_chr_fe_write (&d->chr, buf, (size_t )len); }else {int i;
include/chardev/char-fe.h +2 -2
@@ -203,7 +203,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); +int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,size_t len);/** * qemu_chr_fe_write_all:
@@ -217,7 +217,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); +int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,size_t len);/** * qemu_chr_fe_read_all:
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 24/25] chardev: Let qemu_chr_fe_write[_all] use size_t type argument
Quoted 9 lines · Philippe Mathieu-Daudé
All caller have been audited and call these functions with unsigned arguments.
Most of them use a
size_targument, or directly passsizeof().One case is unclear: the
mux_chr_write()call inchardev/char-mux.c. There we add an assert (which will be removed in few patches) and cast the parameter assize_tto make explicit this value is unsigned.
mux_chr_write() is called indirectly from qemu_chr_fe_write(), so the same argument applies here. Fine with or without the assert().
Quoted 3 lines
Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 65 lines
--- chardev/char-fe.c | 4 ++-- chardev/char-mux.c | 3 ++- include/chardev/char-fe.h | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)chardev/char-fe.c +2
-2@@ -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) +int 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) +int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,size_t len) {Chardev *s = be->chr;chardev/char-mux.c +2
-1@@ -38,7 +38,8 @@ static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len)MuxChardev *d =MUX_CHARDEV (chr);int ret;if (!d->timestamps) { - ret =qemu_chr_fe_write (&d->chr, buf, len); +assert (len >=0 ); + ret =qemu_chr_fe_write (&d->chr, buf, (size_t )len); }else {int i;include/chardev/char-fe.h +2
-3@@ -203,7 +203,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); +int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,size_t len);/** * qemu_chr_fe_write_all: @@ -217,7 +217,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); +int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,size_t len);/** * qemu_chr_fe_read_all: --
Quoted 2 lines
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 25/25 chardev: Let qemu_chr_write[_all] use size_t
In reply to Philippe Mathieu-DaudéWe now know all callers use a size_t argument. We can convert qemu_chr_write() and qemu_chr_write_all() to use a size_t argument.
--- chardev/char.c | 8 ++++---- include/chardev/char.h | 2 +- include/sysemu/replay.h | 2 +- replay/replay-char.c | 2 +- stubs/replay.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)
chardev/char.c +4 -4
@@ -99,8 +99,8 @@ 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) +const uint8_t *buf,size_t len, +size_t *offset,bool write_all) {ChardevClass *cc =CHARDEV_GET_CLASS (s);int res =0 ;
@@ -132,9 +132,9 @@ 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) +int 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 ) {
include/chardev/char.h +1 -1
@@ -221,7 +221,7 @@ 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); +int 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);
include/sysemu/replay.h +1 -1
@@ -158,7 +158,7 @@ void replay_chr_be_write(struct Chardev *s, uint8_t *buf, int len);/*! Writes char write return value to the replay log. */ void replay_char_write_event_save (int res,int 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. */
replay/replay-char.c +1 -1
@@ -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 ());
stubs/replay.c +1 -1
@@ -44,7 +44,7 @@ void replay_char_write_event_save(int res, int offset)abort (); } -void replay_char_write_event_load (int *res,int *offset) +void replay_char_write_event_load (int *res,size_t *offset) {abort (); }
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 25/25] chardev: Let qemu_chr_write[_all] use size_t
include/chardev/char.h void qemu_chr_set_feature(Chardev *chr, · line 224
Quoted 10 lines · Philippe Mathieu-Daudé
include/chardev/char.h +1
-1@@ -221,7 +221,7 @@ 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); +int qemu_chr_write (Chardev *s,const uint8_t *buf,size_t len,bool write_all);
Seeing this cleanup reminds me that I think we ought to change the chardev read & write functions to take "void *buf" instead. as is done for regular libc read/write functions. This would avoid casts in the callers between char */uint8_t *
Something to think about for a future cleanup job....same applies for the QIOChannel APIs which take a 'char *buf', annoyingly different from the chardev APIs :-( Both ought to have void *buf
Regards,
Daniel
Signature · 8 lines
|: 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 :| _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 25/25] chardev: Let qemu_chr_write[_all] use size_t
In reply to Philippe Mathieu-Daudéinclude/chardev/char.h void qemu_chr_set_feature(Chardev *chr, · line 224
Quoted 10 lines · Philippe Mathieu-Daudé
include/chardev/char.h +1
-1@@ -221,7 +221,7 @@ 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); +int qemu_chr_write (Chardev *s,const uint8_t *buf,size_t len,bool write_all);
Seeing this cleanup reminds me that I think we ought to change the chardev read & write functions to take "void *buf" instead. as is done for regular libc read/write functions. This would avoid casts in the callers between char */uint8_t *
Something to think about for a future cleanup job....same applies for the QIOChannel APIs which take a 'char *buf', annoyingly different from the chardev APIs :-( Both ought to have void *buf
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Re: [Qemu-devel] [PATCH v3 25/25] chardev: Let qemu_chr_write[_all] use size_t
Hi
Quoted 19 lines · Daniel P. Berrangé
include/chardev/char.h void qemu_chr_set_feature(Chardev *chr, · line 224
Quoted 10 lines · Philippe Mathieu-Daudé
include/chardev/char.h +1
-1@@ -221,7 +221,7 @@ 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); +int qemu_chr_write (Chardev *s,const uint8_t *buf,size_t len,bool write_all);Seeing this cleanup reminds me that I think we ought to change the chardev read & write functions to take "void *buf" instead. as is done for regular libc read/write functions. This would avoid casts in the callers between char */uint8_t *
Quoted 3 lines
Something to think about for a future cleanup job....same applies for the QIOChannel APIs which take a 'char *buf', annoyingly different from the chardev APIs :-( Both ought to have void *buf
I fully agree, and I started that conversion some time ago, and lost it somewhere. That should be easier than changing the sign of return values though!
Quoted 8 lines
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 :|
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 25/25] chardev: Let qemu_chr_write[_all] use size_t
Quoted 22 lines · Marc-André Lureau
Hi
Quoted 19 lines · Daniel P. Berrangé
include/chardev/char.h void qemu_chr_set_feature(Chardev *chr, · line 224
Quoted 10 lines · Philippe Mathieu-Daudé
include/chardev/char.h +1
-1@@ -221,7 +221,7 @@ 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); +int qemu_chr_write (Chardev *s,const uint8_t *buf,size_t len,bool write_all);Seeing this cleanup reminds me that I think we ought to change the chardev read & write functions to take "void *buf" instead. as is done for regular libc read/write functions. This would avoid casts in the callers between char */uint8_t *
Quoted 7 lines
Quoted 3 lines
Something to think about for a future cleanup job....same applies for the QIOChannel APIs which take a 'char *buf', annoyingly different from the chardev APIs :-( Both ought to have void *buf
I fully agree, and I started that conversion some time ago, and lost it somewhere. That should be easier than changing the sign of return values though!
I thought about it too and am happy both of you agree.
The "part #3" update the prototypes to return ssize_t instead of int. I can do this change there.
Quoted 8 lines
Quoted 8 lines
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 :|
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi
Quoted 6 lines · Philippe Mathieu-Daudé
Hi,
This series convert the
chardev::qemu_chr_write()to take unsigned length argument. To do so I went through all caller and checked if there are no negative value possible.
Changing signedness is problematic and can easily introduce bugs that are easy to miss during review.
I agree with Cornelia about idiomatic use of int. Changing "int" for "size_t" isn't systematically a clear win.
Even Google C++ style recommends to avoid unsigned types "(except for representing bitfields or modular arithmetic). Do not use an unsigned type merely to assert that a variable is non-negative."
https://google.github.io/styleguide/cppguide.html#Integer_Types - see rationale
Since Paolo you suggested the change, could you give some convincing arguments that it's worth taking the plunge?
thanks
Quoted 93 lines
I'm having headaches with the Xen backend, talking with Marc-André he suggested I ask help to the Xen maintainers.
Since the series is becoming quite big, I splitted it:
- part 1: convertqemu_chr_write()
- part 2: convert IOReadHandlerpart 1 can be reviewed and merged without part 2.
The git diffstat is not huge, but there are various chardev subsystems so many maintainers to ask for Ack.
v2: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02396.html
v1: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02200.html
(from Prasad J Pandit)
Changes requested by Paolo:
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02294.htmlPlease review,
Phil.
Philippe Mathieu-Daudé (25):
chardev: SimplifyIOWatchPoll::fd_can_readas a GSourceFunc
chardev: Assert IOCanReadHandler can not be negative chardev/wctablet: Use unsigned type to hold unsigned value
chardev: Letqemu_chr_be_can_write()return asize_ttypes
gdbstub: Usesize_tforstrlen()return value
gdbstub: Usesize_tto holdGDBState::last_packet_len
gdbstub: Letput_buffer()usesize_t
ui/gtk: Remove pointless cast
vhost-user: Express sizeof withsize_t
usb-redir: Verifyusbredirparser_writeget called with positive count
xen: Letxencons_send()take a 'size' argument
xen: Letbuffer_append()return the size consumed
RFC xen: Letbuffer_append()return asize_t
virtio-serial: LetVirtIOSerialPortClass::have_data()usesize_t
spapr-vty: Letvty_putchars()usesize_t
tpm: Usesize_tto hold sizes
net/filter-mirror: Usesize_t
s390x/3270: Letinsert_IAC_escape_char()usesize_ts390/ebcdic: Usesize_tto iterate over arrays
s390x/sclp: Use a const variable to improve readability s390x/sclp: Usesize_tinprocess_mdb()
s390x/sclp: Letwrite_console_data()take asize_thw/ipmi: Assert outlen > outpos
chardev: Let qemu_chr_fe_write[_all] usesize_ttype argument
chardev: Let qemu_chr_write[_all] usesize_tchardev/baum.c | 6 +++--- chardev/char-fd.c | 6 +++--- chardev/char-fe.c | 4 ++-- chardev/char-io.c | 6 +++--- chardev/char-mux.c | 3 ++- chardev/char-pty.c | 8 ++++---- chardev/char-socket.c | 13 +++++++------ chardev/char-udp.c | 8 ++++---- chardev/char-win.c | 2 +- chardev/char.c | 15 +++++++++------ chardev/msmouse.c | 4 ++-- chardev/spice.c | 2 +- chardev/trace-events | 2 +- chardev/wctablet.c | 9 +++++---- gdbstub.c | 8 ++++---- hw/bt/hci-csr.c | 2 +- hw/char/sclpconsole-lm.c | 12 +++++++----- hw/char/spapr_vty.c | 2 +- hw/char/terminal3270.c | 7 ++++--- hw/char/virtio-console.c | 2 +- hw/char/xen_console.c | 24 +++++++++++++++--------- hw/ipmi/ipmi_bmc_extern.c | 3 ++- hw/tpm/tpm_emulator.c | 7 ++++--- hw/usb/redirect.c | 6 +++++- hw/virtio/vhost-user.c | 14 ++++++++------ include/chardev/char-fd.h | 2 +- include/chardev/char-fe.h | 4 ++-- include/chardev/char-io.h | 2 +- include/chardev/char.h | 4 ++-- include/hw/ppc/spapr_vio.h | 2 +- include/hw/s390x/ebcdic.h | 8 ++++---- include/hw/virtio/virtio-serial.h | 2 +- include/sysemu/replay.h | 2 +- net/filter-mirror.c | 2 +- replay/replay-char.c | 2 +- stubs/replay.c | 2 +- ui/console.c | 6 +++--- ui/gtk.c | 2 +- 38 files changed, 119 insertions(+), 96 deletions(-)--
2.20.1
Quoted 18 lines · On Wed, 20 Feb 2019 11:53:42 +0100 Marc-André Lureau…
Hi
Quoted 6 lines · Philippe Mathieu-Daudé
Hi,
This series convert the
chardev::qemu_chr_write()to take unsigned length argument. To do so I went through all caller and checked if there are no negative value possible.Changing signedness is problematic and can easily introduce bugs that are easy to miss during review.
I agree with Cornelia about idiomatic use of int. Changing "int" for "
size_t" isn't systematically a clear win.
Quoted 7 lines
Even Google C++ style recommends to avoid unsigned types "(except for representing bitfields or modular arithmetic). Do not use an unsigned type merely to assert that a variable is non-negative."
https://google.github.io/styleguide/cppguide.html#Integer_Types - see rationaleSince Paolo you suggested the change, could you give some convincing arguments that it's worth taking the plunge?
FWIW, using an explicitly unsigned type for a length sounds fine; but not all conversions are really convincing (albeit not wrong).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 18 lines · Marc-André Lureau
Hi
Quoted 6 lines · Philippe Mathieu-Daudé
Hi,
This series convert the
chardev::qemu_chr_write()to take unsigned length argument. To do so I went through all caller and checked if there are no negative value possible.Changing signedness is problematic and can easily introduce bugs that are easy to miss during review.
I agree with Cornelia about idiomatic use of int. Changing "int" for "
size_t" isn't systematically a clear win.
Quoted 7 lines
Even Google C++ style recommends to avoid unsigned types "(except for representing bitfields or modular arithmetic). Do not use an unsigned type merely to assert that a variable is non-negative."
https://google.github.io/styleguide/cppguide.html#Integer_Types - see rationaleSince Paolo you suggested the change, could you give some convincing arguments that it's worth taking the plunge?
The chardev write/read methods will end up calling libc read/write methods, whose parameters are "size_t count".
Thus if there is QEMU code that could currently (mistakenly) pass a negative value for length to qemu_chr_write, unless something stops it, this is going to be cast to a size_t when we finally call read/ write on the FD, leading to a large positive value & array out of bounds read/write.
IOW we already have inconsistent use of signed vs unsigned in our code which has potential to cause bugs. Converting chardev to use size_t we get rid fo the mismatch with the underlying libc APIs we call, which ultimately eliminates an area of risk longer term. There is a chance it could uncover some pre-existing dormant bugs, but provided we do due diligence to check callers I think its a win to be consistent with libc APIs in size_t usage for read/write.
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Quoted 5 lines · Daniel P. Berrangé
Quoted 2 lines
Since Paolo you suggested the change, could you give some convincing arguments that it's worth taking the plunge?
The chardev write/read methods will end up calling libc read/write methods, whose parameters are "
size_tcount".
In my mind, that's the convincing reason. We should model our read/write after the libc read/write, which means size_t input and ssize_t returns.
Quoted 7 lines
Thus if there is QEMU code that could currently (mistakenly) pass a negative value for length to
qemu_chr_write, unless something stops it, this is going to be cast to asize_twhen we finally call read/ write on the FD, leading to a large positive value & array out of bounds read/write.
Quoted 7 lines
IOW we already have inconsistent use of signed vs unsigned in our code which has potential to cause bugs. Converting chardev to use
size_twe get rid fo the mismatch with the underlying libc APIs we call, which ultimately eliminates an area of risk longer term. There is a chance it could uncover some pre-existing dormant bugs, but provided we do due diligence to check callers I think its a win to be consistent with libc APIs insize_tusage for read/write.
And hopefully this exercise of making the conversion serves as a good audit to help us gain confidence in our code and/or fix bugs it uncovers.
Signature · 8 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel