[SLOF] [PATCH v2 1/2] virtio-serial: Make read and write methods report failure

Jordan Niethe jniethe5 at gmail.com
Mon Sep 4 15:19:28 AEST 2023


On Mon, Sep 4, 2023 at 3:08 PM Alexey Kardashevskiy <aik at ozlabs.ru> wrote:
>
>
> On 29/08/2023 10:12, Jordan Niethe wrote:
> > From: Kautuk Consul <kconsul at linux.vnet.ibm.com>
> >
> > The read and write methods return successfully even if the virtio device
> > is closed (virtiodev is 0) and it is not able to send or receive any
> > characters.
> >
> > Make the read and write methods return 0 to indicate they did not
> > succeed in this case.
> >
> > This also fixes an invalid stack access in the read method.
> >
> > Fixes: 8174acd ("virtio-serial: Close device completely")
> > Signed-off-by: Kautuk Consul <kconsul at linux.vnet.ibm.com>
> > Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
> > ---
> > v2:
> >     - Rework commit message slightly
> > ---
> >   board-qemu/slof/virtio-serial.fs | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/board-qemu/slof/virtio-serial.fs b/board-qemu/slof/virtio-serial.fs
> > index 82868e2..41e2e04 100644
> > --- a/board-qemu/slof/virtio-serial.fs
> > +++ b/board-qemu/slof/virtio-serial.fs
> > @@ -67,7 +67,7 @@ virtiodev virtio-serial-init drop
> >   ;
> >
> >   : write ( addr len -- actual )
> > -    virtiodev 0= IF nip EXIT THEN
> > +    virtiodev 0= IF 2drop 0 EXIT THEN
> >       tuck
> >       0 ?DO
> >           dup c@ virtiodev SWAP virtio-serial-putchar
> > @@ -78,7 +78,7 @@ virtiodev virtio-serial-init drop
> >
> >   : read ( addr len -- actual )
> >       0= IF drop 0 EXIT THEN
> > -    virtiodev 0= IF nip EXIT THEN
> > +    virtiodev 0= IF drop 0 EXIT THEN
>
>
> This is going to leave @addr on stack, no? The write gets it right though.

The read method begins with 0= which consumes top of stack.
The write method does not have that which is why they are different.

>
>
> >       virtiodev virtio-serial-haschar 0= IF 0 swap c! -2 EXIT THEN
> >       virtiodev virtio-serial-getchar swap c! 1
> >   ;
>
> --
> Alexey
>
>


More information about the SLOF mailing list