qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 00/10] usb patch queue
@ 2014-05-05 11:12 Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 01/10] usb-ohci: Add vmstate descriptor Gerd Hoffmann
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Here comes the next usb patch queue pull, featuring a bunch of mtp
bugfixes and ohci live migration support.

please pull,
  Gerd

The following changes since commit fdaad4715ae9e998fd0595bedfb16fdaf0c68ccc:

  Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20140501' into staging (2014-05-02 11:32:00 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-usb-6

for you to fetch changes up to 8ebb87635790e7033e19e9a26e8c5eef22560bcc:

  usb: mtp: reply INCOMPLETE_TRANSFER on read errors (2014-05-05 12:58:02 +0200)

----------------------------------------------------------------
ohci live migration.
mtp bugfixes.

----------------------------------------------------------------
Alexey Kardashevskiy (1):
      usb-ohci: Add vmstate descriptor

Gerd Hoffmann (9):
      usb: mtp: replace debug printfs with trace points
      usb: mtp: fix usb_mtp_add_u64
      usb: mtp: fix version (is decimal not bcd)
      usb: mtp: fix serial (must be exact 32 chars)
      usb: mtp: fix error path memory leak
      usb: mtp: avoid empty description string
      usb: mtp: drop data-out hexdump
      usb: mtp: fix possible buffer overflow
      usb: mtp: reply INCOMPLETE_TRANSFER on read errors

 hw/usb/dev-mtp.c  |  35 ++++++++++------
 hw/usb/hcd-ohci.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 trace-events      |   3 ++
 3 files changed, 137 insertions(+), 20 deletions(-)

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

* [Qemu-devel] [PULL 01/10] usb-ohci: Add vmstate descriptor
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 02/10] usb: mtp: replace debug printfs with trace points Gerd Hoffmann
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexey Kardashevskiy, Peter Maydell, Gerd Hoffmann

From: Alexey Kardashevskiy <aik@ozlabs.ru>

This adds migration support for OHCI.

This defines a descriptor for OHCIState.
This changes some OHCIState field types to be migration compatible.
This adds a descriptor for OHCIPort.
This migrates the EOF timer if the USB was started at the time of
migration.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/hcd-ohci.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 111 insertions(+), 8 deletions(-)

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 93f186f..cd87074 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -80,13 +80,13 @@ typedef struct {
     uint32_t bulk_head, bulk_cur;
     uint32_t per_cur;
     uint32_t done;
-    int done_count;
+    int32_t done_count;
 
     /* Frame counter partition */
-    uint32_t fsmps:15;
-    uint32_t fit:1;
-    uint32_t fi:14;
-    uint32_t frt:1;
+    uint16_t fsmps;
+    uint8_t fit;
+    uint16_t fi;
+    uint8_t frt;
     uint16_t frame_number;
     uint16_t padding;
     uint32_t pstart;
@@ -111,7 +111,7 @@ typedef struct {
     USBPacket usb_packet;
     uint8_t usb_buf[8192];
     uint32_t async_td;
-    int async_complete;
+    bool async_complete;
 
 } OHCIState;
 
@@ -693,7 +693,7 @@ static void ohci_async_complete_packet(USBPort *port, USBPacket *packet)
 #ifdef DEBUG_PACKET
     DPRINTF("Async packet complete\n");
 #endif
-    ohci->async_complete = 1;
+    ohci->async_complete = true;
     ohci_process_lists(ohci, 1);
 }
 
@@ -1058,7 +1058,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)
 #endif
     if (completion) {
         ohci->async_td = 0;
-        ohci->async_complete = 0;
+        ohci->async_complete = false;
     } else {
         if (ohci->async_td) {
             /* ??? The hardware should allow one active packet per
@@ -1984,6 +1984,108 @@ static Property ohci_pci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static const VMStateDescription vmstate_ohci_state_port = {
+    .name = "ohci-core/port",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField []) {
+        VMSTATE_UINT32(ctrl, OHCIPort),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+static bool ohci_eof_timer_needed(void *opaque)
+{
+    OHCIState *ohci = opaque;
+
+    return ohci->eof_timer != NULL;
+}
+
+static int ohci_eof_timer_pre_load(void *opaque)
+{
+    OHCIState *ohci = opaque;
+
+    ohci_bus_start(ohci);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_ohci_eof_timer = {
+    .name = "ohci-core/eof-timer",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .pre_load = ohci_eof_timer_pre_load,
+    .fields = (VMStateField []) {
+        VMSTATE_TIMER(eof_timer, OHCIState),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+const VMStateDescription vmstate_ohci_state = {
+    .name = "ohci-core",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_INT64(sof_time, OHCIState),
+        VMSTATE_UINT32(ctl, OHCIState),
+        VMSTATE_UINT32(status, OHCIState),
+        VMSTATE_UINT32(intr_status, OHCIState),
+        VMSTATE_UINT32(intr, OHCIState),
+        VMSTATE_UINT32(hcca, OHCIState),
+        VMSTATE_UINT32(ctrl_head, OHCIState),
+        VMSTATE_UINT32(ctrl_cur, OHCIState),
+        VMSTATE_UINT32(bulk_head, OHCIState),
+        VMSTATE_UINT32(bulk_cur, OHCIState),
+        VMSTATE_UINT32(per_cur, OHCIState),
+        VMSTATE_UINT32(done, OHCIState),
+        VMSTATE_INT32(done_count, OHCIState),
+        VMSTATE_UINT16(fsmps, OHCIState),
+        VMSTATE_UINT8(fit, OHCIState),
+        VMSTATE_UINT16(fi, OHCIState),
+        VMSTATE_UINT8(frt, OHCIState),
+        VMSTATE_UINT16(frame_number, OHCIState),
+        VMSTATE_UINT16(padding, OHCIState),
+        VMSTATE_UINT32(pstart, OHCIState),
+        VMSTATE_UINT32(lst, OHCIState),
+        VMSTATE_UINT32(rhdesc_a, OHCIState),
+        VMSTATE_UINT32(rhdesc_b, OHCIState),
+        VMSTATE_UINT32(rhstatus, OHCIState),
+        VMSTATE_STRUCT_ARRAY(rhport, OHCIState, OHCI_MAX_PORTS, 0,
+                             vmstate_ohci_state_port, OHCIPort),
+        VMSTATE_UINT32(hstatus, OHCIState),
+        VMSTATE_UINT32(hmask, OHCIState),
+        VMSTATE_UINT32(hreset, OHCIState),
+        VMSTATE_UINT32(htest, OHCIState),
+        VMSTATE_UINT32(old_ctl, OHCIState),
+        VMSTATE_UINT8_ARRAY(usb_buf, OHCIState, 8192),
+        VMSTATE_UINT32(async_td, OHCIState),
+        VMSTATE_BOOL(async_complete, OHCIState),
+        VMSTATE_END_OF_LIST()
+    },
+    .subsections = (VMStateSubsection []) {
+        {
+            .vmsd = &vmstate_ohci_eof_timer,
+            .needed = ohci_eof_timer_needed,
+        } , {
+            /* empty */
+        }
+    }
+};
+
+static const VMStateDescription vmstate_ohci = {
+    .name = "ohci",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(parent_obj, OHCIPCIState),
+        VMSTATE_STRUCT(state, OHCIPCIState, 1, vmstate_ohci_state, OHCIState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void ohci_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -1997,6 +2099,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data)
     dc->desc = "Apple USB Controller";
     dc->props = ohci_pci_properties;
     dc->hotpluggable = false;
+    dc->vmsd = &vmstate_ohci;
 }
 
 static const TypeInfo ohci_pci_info = {
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 02/10] usb: mtp: replace debug printfs with trace points
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 01/10] usb-ohci: Add vmstate descriptor Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 03/10] usb: mtp: fix usb_mtp_add_u64 Gerd Hoffmann
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 8 ++++----
 trace-events     | 3 +++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 8b44032..17df447 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -294,7 +294,7 @@ static MTPObject *usb_mtp_object_alloc(MTPState *s, uint32_t handle,
         goto ignore;
     }
 
-    fprintf(stderr, "%s: 0x%x %s\n", __func__, o->handle, o->path);
+    trace_usb_mtp_object_alloc(s->dev.addr, o->handle, o->path);
 
     QTAILQ_INSERT_TAIL(&s->objects, o, next);
     return o;
@@ -310,7 +310,7 @@ static void usb_mtp_object_free(MTPState *s, MTPObject *o)
 {
     int i;
 
-    fprintf(stderr, "%s: 0x%x %s\n", __func__, o->handle, o->path);
+    trace_usb_mtp_object_free(s->dev.addr, o->handle, o->path);
 
     QTAILQ_REMOVE(&s->objects, o, next);
     for (i = 0; i < o->nchildren; i++) {
@@ -843,8 +843,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
         res0 = data_in->length;
         break;
     default:
-        fprintf(stderr, "%s: unknown command code 0x%04x\n",
-                __func__, c->code);
+        trace_usb_mtp_op_unknown(s->dev.addr, c->code);
         usb_mtp_queue_result(s, RES_OPERATION_NOT_SUPPORTED,
                              c->trans, 0, 0, 0);
         return;
@@ -892,6 +891,7 @@ static void usb_mtp_handle_control(USBDevice *dev, USBPacket *p,
 
 static void usb_mtp_cancel_packet(USBDevice *dev, USBPacket *p)
 {
+    /* we don't use async packets, so this should never be called */
     fprintf(stderr, "%s\n", __func__);
 }
 
diff --git a/trace-events b/trace-events
index a5218ba..af4449d 100644
--- a/trace-events
+++ b/trace-events
@@ -453,6 +453,9 @@ usb_mtp_op_get_object_handles(int dev, uint32_t handle, const char *path) "dev %
 usb_mtp_op_get_object_info(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s"
 usb_mtp_op_get_object(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s"
 usb_mtp_op_get_partial_object(int dev, uint32_t handle, const char *path, uint32_t offset, uint32_t length) "dev %d, handle 0x%x, path %s, off %d, len %d"
+usb_mtp_op_unknown(int dev, uint32_t code) "dev %d, command code 0x%x"
+usb_mtp_object_alloc(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s"
+usb_mtp_object_free(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s"
 
 # hw/usb/host-libusb.c
 usb_host_open_started(int bus, int addr) "dev %d:%d"
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 03/10] usb: mtp: fix usb_mtp_add_u64
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 01/10] usb-ohci: Add vmstate descriptor Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 02/10] usb: mtp: replace debug printfs with trace points Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 04/10] usb: mtp: fix version (is decimal not bcd) Gerd Hoffmann
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 17df447..063a426 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -416,7 +416,7 @@ static void usb_mtp_add_u32(MTPData *data, uint32_t val)
 
 static void usb_mtp_add_u64(MTPData *data, uint64_t val)
 {
-    usb_mtp_realloc(data, 4);
+    usb_mtp_realloc(data, 8);
     data->data[data->length++] = (val >>  0) & 0xff;
     data->data[data->length++] = (val >>  8) & 0xff;
     data->data[data->length++] = (val >> 16) & 0xff;
@@ -424,7 +424,7 @@ static void usb_mtp_add_u64(MTPData *data, uint64_t val)
     data->data[data->length++] = (val >> 32) & 0xff;
     data->data[data->length++] = (val >> 40) & 0xff;
     data->data[data->length++] = (val >> 48) & 0xff;
-    data->data[data->length++] = (val >> 54) & 0xff;
+    data->data[data->length++] = (val >> 56) & 0xff;
 }
 
 static void usb_mtp_add_u16_array(MTPData *data, uint32_t len,
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 04/10] usb: mtp: fix version (is decimal not bcd)
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 03/10] usb: mtp: fix usb_mtp_add_u64 Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 05/10] usb: mtp: fix serial (must be exact 32 chars) Gerd Hoffmann
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 063a426..dff2618 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -533,7 +533,7 @@ static MTPData *usb_mtp_get_device_info(MTPState *s, MTPControl *c)
 
     trace_usb_mtp_op_get_device_info(s->dev.addr);
 
-    usb_mtp_add_u16(d, 0x0100);
+    usb_mtp_add_u16(d, 100);
     usb_mtp_add_u32(d, 0xffffffff);
     usb_mtp_add_u16(d, 0x0101);
     usb_mtp_add_wstr(d, L"");
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 05/10] usb: mtp: fix serial (must be exact 32 chars)
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 04/10] usb: mtp: fix version (is decimal not bcd) Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 06/10] usb: mtp: fix error path memory leak Gerd Hoffmann
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index dff2618..775dc8d 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -548,7 +548,7 @@ static MTPData *usb_mtp_get_device_info(MTPState *s, MTPControl *c)
     usb_mtp_add_wstr(d, L"" MTP_MANUFACTURER);
     usb_mtp_add_wstr(d, L"" MTP_PRODUCT);
     usb_mtp_add_wstr(d, L"0.1");
-    usb_mtp_add_wstr(d, L"123456789abcdef123456789abcdef");
+    usb_mtp_add_wstr(d, L"0123456789abcdef0123456789abcdef");
 
     return d;
 }
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 06/10] usb: mtp: fix error path memory leak
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 05/10] usb: mtp: fix serial (must be exact 32 chars) Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 07/10] usb: mtp: avoid empty description string Gerd Hoffmann
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 775dc8d..45f9562 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -669,6 +669,7 @@ static MTPData *usb_mtp_get_object(MTPState *s, MTPControl *c,
 
     d->fd = open(o->path, O_RDONLY);
     if (d->fd == -1) {
+        usb_mtp_data_free(d);
         return NULL;
     }
     d->length = o->stat.st_size;
@@ -688,6 +689,7 @@ static MTPData *usb_mtp_get_partial_object(MTPState *s, MTPControl *c,
 
     d->fd = open(o->path, O_RDONLY);
     if (d->fd == -1) {
+        usb_mtp_data_free(d);
         return NULL;
     }
 
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 07/10] usb: mtp: avoid empty description string
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 06/10] usb: mtp: fix error path memory leak Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 08/10] usb: mtp: drop data-out hexdump Gerd Hoffmann
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 45f9562..a30a886 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1046,7 +1046,7 @@ static int usb_mtp_initfn(USBDevice *dev)
     QTAILQ_INIT(&s->objects);
     if (s->desc == NULL) {
         s->desc = strrchr(s->root, '/');
-        if (s->desc) {
+        if (s->desc && s->desc[0]) {
             s->desc = g_strdup(s->desc + 1);
         } else {
             s->desc = g_strdup("none");
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 08/10] usb: mtp: drop data-out hexdump
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 07/10] usb: mtp: avoid empty description string Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 09/10] usb: mtp: fix possible buffer overflow Gerd Hoffmann
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index a30a886..b6eaeae 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1011,8 +1011,7 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
             usb_mtp_command(s, &cmd);
             break;
         default:
-            iov_hexdump(p->iov.iov, p->iov.niov, stderr, "mtp-out", 32);
-            trace_usb_mtp_stall(s->dev.addr, "TODO: implement data-out");
+            /* not needed as long as the mtp device is read-only */
             p->status = USB_RET_STALL;
             return;
         }
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 09/10] usb: mtp: fix possible buffer overflow
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 08/10] usb: mtp: drop data-out hexdump Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-05 11:12 ` [Qemu-devel] [PULL 10/10] usb: mtp: reply INCOMPLETE_TRANSFER on read errors Gerd Hoffmann
  2014-05-07 12:36 ` [Qemu-devel] [PULL 00/10] usb patch queue Peter Maydell
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index b6eaeae..62428d8 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -998,6 +998,14 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
             cmd.argc = (le32_to_cpu(container.length) - sizeof(container))
                 / sizeof(uint32_t);
             cmd.trans = le32_to_cpu(container.trans);
+            if (cmd.argc > ARRAY_SIZE(cmd.argv)) {
+                cmd.argc = ARRAY_SIZE(cmd.argv);
+            }
+            if (p->iov.size < sizeof(container) + cmd.argc * sizeof(uint32_t)) {
+                trace_usb_mtp_stall(s->dev.addr, "packet too small");
+                p->status = USB_RET_STALL;
+                return;
+            }
             usb_packet_copy(p, &params, cmd.argc * sizeof(uint32_t));
             for (i = 0; i < cmd.argc; i++) {
                 cmd.argv[i] = le32_to_cpu(params[i]);
-- 
1.8.3.1

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

* [Qemu-devel] [PULL 10/10] usb: mtp: reply INCOMPLETE_TRANSFER on read errors
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (8 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 09/10] usb: mtp: fix possible buffer overflow Gerd Hoffmann
@ 2014-05-05 11:12 ` Gerd Hoffmann
  2014-05-07 12:36 ` [Qemu-devel] [PULL 00/10] usb patch queue Peter Maydell
  10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2014-05-05 11:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/usb/dev-mtp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 62428d8..943f930 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -50,6 +50,7 @@ enum mtp_code {
     RES_INVALID_TRANSACTION_ID     = 0x2004,
     RES_OPERATION_NOT_SUPPORTED    = 0x2005,
     RES_PARAMETER_NOT_SUPPORTED    = 0x2006,
+    RES_INCOMPLETE_TRANSFER        = 0x2007,
     RES_INVALID_STORAGE_ID         = 0x2008,
     RES_INVALID_OBJECT_HANDLE      = 0x2009,
     RES_SPEC_BY_FORMAT_UNSUPPORTED = 0x2014,
@@ -946,7 +947,8 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
                 }
                 rc = read(d->fd, d->data, dlen);
                 if (rc != dlen) {
-                    fprintf(stderr, "%s: TODO: handle read error\n", __func__);
+                    memset(d->data, 0, dlen);
+                    s->result->code = RES_INCOMPLETE_TRANSFER;
                 }
                 usb_packet_copy(p, d->data, dlen);
             }
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PULL 00/10] usb patch queue
  2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
                   ` (9 preceding siblings ...)
  2014-05-05 11:12 ` [Qemu-devel] [PULL 10/10] usb: mtp: reply INCOMPLETE_TRANSFER on read errors Gerd Hoffmann
@ 2014-05-07 12:36 ` Peter Maydell
  10 siblings, 0 replies; 12+ messages in thread
From: Peter Maydell @ 2014-05-07 12:36 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU Developers

On 5 May 2014 12:12, Gerd Hoffmann <kraxel@redhat.com> wrote:
>   Hi,
>
> Here comes the next usb patch queue pull, featuring a bunch of mtp
> bugfixes and ohci live migration support.
>
> please pull,
>   Gerd
>
> The following changes since commit fdaad4715ae9e998fd0595bedfb16fdaf0c68ccc:
>
>   Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20140501' into staging (2014-05-02 11:32:00 +0100)
>
> are available in the git repository at:
>
>
>   git://git.kraxel.org/qemu tags/pull-usb-6
>
> for you to fetch changes up to 8ebb87635790e7033e19e9a26e8c5eef22560bcc:
>
>   usb: mtp: reply INCOMPLETE_TRANSFER on read errors (2014-05-05 12:58:02 +0200)
>
> ----------------------------------------------------------------
> ohci live migration.
> mtp bugfixes.
>

Applied, thanks.

-- PMM

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

end of thread, other threads:[~2014-05-07 12:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-05 11:12 [Qemu-devel] [PULL 00/10] usb patch queue Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 01/10] usb-ohci: Add vmstate descriptor Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 02/10] usb: mtp: replace debug printfs with trace points Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 03/10] usb: mtp: fix usb_mtp_add_u64 Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 04/10] usb: mtp: fix version (is decimal not bcd) Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 05/10] usb: mtp: fix serial (must be exact 32 chars) Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 06/10] usb: mtp: fix error path memory leak Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 07/10] usb: mtp: avoid empty description string Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 08/10] usb: mtp: drop data-out hexdump Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 09/10] usb: mtp: fix possible buffer overflow Gerd Hoffmann
2014-05-05 11:12 ` [Qemu-devel] [PULL 10/10] usb: mtp: reply INCOMPLETE_TRANSFER on read errors Gerd Hoffmann
2014-05-07 12:36 ` [Qemu-devel] [PULL 00/10] usb patch queue Peter Maydell

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).