From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Prasad J Pandit <ppandit@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Sagar Karandikar" <sagark@eecs.berkeley.edu>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jan Kiszka" <jan.kiszka@siemens.com>,
"Jason Wang" <jasowang@redhat.com>,
"Palmer Dabbelt" <palmer@sifive.com>,
qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Michael Clark" <mjc@sifive.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Alberto Garcia" <berto@igalia.com>,
"Li Zhijian" <lizhijian@cn.fujitsu.com>,
"Alexander Graf" <agraf@suse.de>,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
"Antony Pavlov" <antonynpavlov@gmail.com>,
"Anthony Perard" <anthony.perard@citrix.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Corey Minyard" <minyard@acm.org>, "Amit Shah" <amit@kernel.org>,
"Alistair Francis" <alistair@alistair23.me>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Fabien Chouteau" <chouteau@adacore.com>,
"Zhang Chen" <zhangckid@gmail.com>,
"open list:PXA2XX" <qemu-arm@nongnu.org>,
"Peter Chubb" <peter.chubb@nicta.com.au>,
"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
"open list:X86" <xen-devel@lists.xenproject.org>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Igor Mitsyanko" <i.mitsyanko@gmail.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"open list:S390 Virtio-ccw" <qemu-s390x@nongnu.org>,
"Thomas Huth" <huth@tuxfamily.org>,
"Michael Walle" <michael@walle.cc>,
"open list:sPAPR" <qemu-ppc@nongnu.org>,
"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>
Subject: Re: [Qemu-devel] [PATCH] chardev: Convert IOReadHandler to read an unsigned number of bytes
Date: Thu, 11 Oct 2018 17:53:20 +0200 [thread overview]
Message-ID: <f670390d-7409-1989-6ed3-7b31d64e583d@redhat.com> (raw)
In-Reply-To: <8d285029-2b6f-a841-2489-c6761e62c02c@redhat.com>
On 11/10/2018 17:34, Paolo Bonzini wrote:
> On 11/10/2018 17:24, Philippe Mathieu-Daudé wrote:
>>> On the other hand, fd_chr_read_poll is not an IOCanReadHandler, and this
>>> patch therefore probably doesn't compile?
>> It does compile.
>>
>> fd_chr_update_read_handler() uses fd_chr_read_poll with io_add_watch_poll():
>>
>> GSource *io_add_watch_poll(Chardev *chr,
>> QIOChannel *ioc,
>> IOCanReadHandler *fd_can_read,
>> QIOChannelFunc fd_read,
>> gpointer user_data,
>> GMainContext *context);
>
> Oh, that's somewhat weird. It could just as well return a bool.
>
> However, this made me notice that you need to change e.g. s->max_size's
> declaration (in include/chardev/char-fd.h) from int to size_t, and
> likewise for: 1) all users of s->max_size, such as len in fd_chr_read;
> 2) all the similar variables in other char backends.
>
> So it's probably best to structure the series as follows:
>
> 1) change fd_can_read from IOCanReadHandler to a GSourceFunc (which
> returns a boolean value), changing all "return s->foo" to "return s->foo
>> 0;". Then you can remove the > 0 from
>
> bool now_active = iwp->fd_can_read(iwp->opaque) > 0;
>
> (Having the > 0 repeated in all backends is now a bit ugly, but there
> are future cleanup opportunities here to move the qemu_chr_be_can_write
> call to qemu_chr_be_can_write; this way most chardev backends can skip
> defining a read_poll function. But I digress).
>
> 2) assert in qemu_chr_be_can_write that the returned value is >= 0
>
> 3) for each backend, change the assigned variable from int to size_t
>
> 4) now the rest of your patch, touching all front-ends. The assertion
> from (2) now does not make sense anymore, since ->can_read returns an
> unsigned value, but perhaps you can keep a "fail-safe" assertion that
> (ssize_t)returned_value >= 0 to catch undesired overflows.
OK! thanks for sorting this :)
prev parent reply other threads:[~2018-10-11 15:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-11 13:14 [Qemu-devel] [PATCH] chardev: Convert IOReadHandler to read an unsigned number of bytes Philippe Mathieu-Daudé
2018-10-11 14:08 ` Alberto Garcia
2018-10-11 15:14 ` Paolo Bonzini
2018-10-11 15:24 ` Philippe Mathieu-Daudé
2018-10-11 15:34 ` Paolo Bonzini
2018-10-11 15:53 ` Philippe Mathieu-Daudé [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f670390d-7409-1989-6ed3-7b31d64e583d@redhat.com \
--to=philmd@redhat.com \
--cc=agraf@suse.de \
--cc=alistair@alistair23.me \
--cc=amit@kernel.org \
--cc=anthony.perard@citrix.com \
--cc=antonynpavlov@gmail.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=borntraeger@de.ibm.com \
--cc=chouteau@adacore.com \
--cc=cohuck@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=dgilbert@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=huth@tuxfamily.org \
--cc=i.mitsyanko@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=jasowang@redhat.com \
--cc=jcmvbkbc@gmail.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=kraxel@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael@walle.cc \
--cc=minyard@acm.org \
--cc=mjc@sifive.com \
--cc=mst@redhat.com \
--cc=palmer@sifive.com \
--cc=pbonzini@redhat.com \
--cc=peter.chubb@nicta.com.au \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=sagark@eecs.berkeley.edu \
--cc=samuel.thibault@ens-lyon.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
--cc=zhangckid@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).