Skip to content

Commit

Permalink
usb-serial: only expose device in guest when the chardev is open
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
kraxel authored and Anthony Liguori committed Oct 22, 2012
1 parent 70330fb commit da124e6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions hw/usb/dev-serial.c
Expand Up @@ -427,6 +427,10 @@ static void usb_serial_handle_destroy(USBDevice *dev)
static int usb_serial_can_read(void *opaque)
{
USBSerialState *s = opaque;

if (!s->dev.attached) {
return 0;
}
return RECV_BUF - s->recv_used;
}

Expand Down Expand Up @@ -469,8 +473,14 @@ static void usb_serial_event(void *opaque, int event)
case CHR_EVENT_FOCUS:
break;
case CHR_EVENT_OPENED:
usb_serial_reset(s);
/* TODO: Reset USB port */
if (!s->dev.attached) {
usb_device_attach(&s->dev);
}
break;
case CHR_EVENT_CLOSED:
if (s->dev.attached) {
usb_device_detach(&s->dev);
}
break;
}
}
Expand All @@ -481,6 +491,7 @@ static int usb_serial_initfn(USBDevice *dev)

usb_desc_create_serial(dev);
usb_desc_init(dev);
dev->auto_attach = 0;

if (!s->cs) {
error_report("Property chardev is required");
Expand All @@ -490,6 +501,10 @@ static int usb_serial_initfn(USBDevice *dev)
qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
usb_serial_event, s);
usb_serial_handle_reset(dev);

if (s->cs->opened && !dev->attached) {
usb_device_attach(dev);
}
return 0;
}

Expand Down

0 comments on commit da124e6

Please sign in to comment.