Skip to contentSkip to conversation

usb patch queue

GIT PULL Applied Gerd Hoffmann 2 participants 8 messages Mar 21, 2016 – Mar 22, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

Here comes the usb patch queue, with a bunch of usb bugixes accumulated over the last weeks.

If you have anything outstanding usb patches which are not in here, please resend (exception: the xen host adapter patches which are waiting for review from xen people).

please pull,
Gerd

The following changes since commit 6741d38ad0f2405a6e999ebc9550801b01aca479:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2016-03-17 15:59:42 +0000)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-usb-20160321-1

for you to fetch changes up to dff0367cf66f489aa772320fa2937a8cac1ca30d:

usb: ehci: add capability mmio write function (2016-03-18 14:20:39 +0100)

----------------------------------------------------------------
usb: bugfix collection.

----------------------------------------------------------------
Matthew Fortune (1):
hw/usb/dev-mtp: Guard inotify usage with CONFIG_INOTIFY1

Peter Xu (3):
usb: fix unbounded stack warning for xhci_dma_write_u32s
usb: fix unbound stack usage for usb_mtp_add_str
usb: fix unbound stack warning for inotify_watchfn

Prasad J Pandit (1):
usb: ehci: add capability mmio write function

Stefan Weil (1):
usb: Fix compilation for Windows

 hw/usb/dev-mtp.c  | 29 +++++++++++++++--------------
 hw/usb/hcd-ehci.c |  6 ++++++
 hw/usb/hcd-xhci.c |  6 ++++--
 hw/usb/redirect.c |  4 +++-
 4 files changed, 28 insertions(+), 17 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 1/6] usb: Fix compilation for Windows

From: Stefan Weil <[email protected]>

Mingw-w64 does not provide sys/ioctl.h and Linux builds don't need it, so remove that include statement.

ERROR is defined by wingdi.h (included via windows.h). Undefine it before it is redefined to avoid a compiler warning / error.

Message-id: [email protected]

---
 hw/usb/redirect.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/usb/redirect.c +3 -1
index 38a5393..cbcc218 100644
@@ -34,12 +34,14 @@
 #include "qemu/iov.h"
 #include "sysemu/char.h"
 
-#include <sys/ioctl.h>
 #include <usbredirparser.h>
 #include <usbredirfilter.h>
 
 #include "hw/usb.h"
 
+/* ERROR is defined below. Remove any previous definition. */
+#undef ERROR
+
 #define MAX_ENDPOINTS 32
 #define NO_INTERFACE_INFO 255 /* Valid interface_count always <= 32 */
 #define EP2I(ep_address) (((ep_address & 0x80) >> 3) | (ep_address & 0x0f))
Signature · 1 line
1.8.3.1
#2 lore raw

[Qemu-devel] [PULL 2/6] usb: fix unbounded stack warning for xhci_dma_write_u32s

In reply to Gerd Hoffmann

From: Peter Xu <[email protected]>

All the callers for xhci_dma_write_u32s() are using mostly 5 * uint32_t in len. To avoid unbound stack warning for the function, make it statically allocated, and assert when it's not big enough in the future.

Message-id: [email protected]

---
 hw/usb/hcd-xhci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci.c +4 -2
index 44b6f8c..bcde8a2 100644
@@ -698,11 +698,13 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,
                                        uint32_t *buf, size_t len)
 {
     int i;
-    uint32_t tmp[len / sizeof(uint32_t)];
+    uint32_t tmp[5];
+    uint32_t n = len / sizeof(uint32_t);
 
     assert((len % sizeof(uint32_t)) == 0);
+    assert(n <= ARRAY_SIZE(tmp));
 
-    for (i = 0; i < (len / sizeof(uint32_t)); i++) {
+    for (i = 0; i < n; i++) {
         tmp[i] = cpu_to_le32(buf[i]);
     }
     pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len);
Signature · 1 line
1.8.3.1
#3 lore raw

[Qemu-devel] [PULL 3/6] usb: fix unbound stack usage for usb_mtp_add_str

In reply to Gerd Hoffmann

From: Peter Xu <[email protected]>

Use heap instead of stack.

---
 hw/usb/dev-mtp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/usb/dev-mtp.c +3 -1
index 7391783..62fb7cd 100644
@@ -718,7 +718,7 @@ static void usb_mtp_add_wstr(MTPData *data, const wchar_t *str)
 static void usb_mtp_add_str(MTPData *data, const char *str)
 {
     uint32_t len = strlen(str)+1;
-    wchar_t wstr[len];
+    wchar_t *wstr = g_new(wchar_t, len);
     size_t ret;
 
     ret = mbstowcs(wstr, str, len);
@@ -727,6 +727,8 @@ static void usb_mtp_add_str(MTPData *data, const char *str)
     } else {
         usb_mtp_add_wstr(data, wstr);
     }
+
+    g_free(wstr);
 }
 
 static void usb_mtp_add_time(MTPData *data, time_t time)
Signature · 1 line
1.8.3.1
#4 lore raw

[Qemu-devel] [PULL 4/6] usb: fix unbound stack warning for inotify_watchfn

In reply to Gerd Hoffmann

From: Peter Xu <[email protected]>

Message-id: [email protected]

---
 hw/usb/dev-mtp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/dev-mtp.c +2 -3
index 62fb7cd..01c5e51 100644
@@ -433,12 +433,11 @@ static void inotify_watchfn(void *arg)
     MTPState *s = arg;
     ssize_t bytes;
     /* From the man page: atleast one event can be read */
-    int len = sizeof(struct inotify_event) + NAME_MAX + 1;
     int pos;
-    char buf[len];
+    char buf[sizeof(struct inotify_event) + NAME_MAX + 1];
 
     for (;;) {
-        bytes = read(s->inotifyfd, buf, len);
+        bytes = read(s->inotifyfd, buf, sizeof(buf));
         pos = 0;
 
         if (bytes <= 0) {
Signature · 1 line
1.8.3.1
#5 lore raw

[Qemu-devel] [PULL 5/6] hw/usb/dev-mtp: Guard inotify usage with CONFIG_INOTIFY1

In reply to Gerd Hoffmann

From: Matthew Fortune <[email protected]>

inotify_init1 usage was guarded by a check for linux but does not exist on older distributions like CentOS 5 resulting in build failures.

Message-id: [email protected]

---
 hw/usb/dev-mtp.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
hw/usb/dev-mtp.c +10 -10
index 01c5e51..ee2071f 100644
@@ -14,7 +14,7 @@
 #include <dirent.h>
 
 #include <sys/statvfs.h>
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
 #include <sys/inotify.h>
 #include "qemu/main-loop.h"
 #endif
@@ -92,7 +92,7 @@ enum {
     EP_EVENT,
 };
 
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
 typedef struct MTPMonEntry MTPMonEntry;
 
 struct MTPMonEntry {
@@ -127,7 +127,7 @@ struct MTPObject {
     char         *name;
     char         *path;
     struct stat  stat;
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
     /* inotify watch cookie */
     int          watchfd;
 #endif
@@ -152,7 +152,7 @@ struct MTPState {
     uint32_t     next_handle;
 
     QTAILQ_HEAD(, MTPObject) objects;
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
     /* inotify descriptor */
     int          inotifyfd;
     QTAILQ_HEAD(events, MTPMonEntry) events;
@@ -400,7 +400,7 @@ static MTPObject *usb_mtp_add_child(MTPState *s, MTPObject *o,
     return child;
 }
 
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
 static MTPObject *usb_mtp_object_lookup_name(MTPObject *parent,
                                              char *name, int len)
 {
@@ -592,7 +592,7 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)
     if (!dir) {
         return;
     }
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
     int watchfd = usb_mtp_add_watch(s->inotifyfd, o->path);
     if (watchfd == -1) {
         fprintf(stderr, "usb-mtp: failed to add watch for %s\n", o->path);
@@ -996,7 +996,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
         trace_usb_mtp_op_open_session(s->dev.addr);
         s->session = c->argv[0];
         usb_mtp_object_alloc(s, s->next_handle++, NULL, s->root);
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
         if (usb_mtp_inotify_init(s)) {
             fprintf(stderr, "usb-mtp: file monitoring init failed\n");
         }
@@ -1006,7 +1006,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
         trace_usb_mtp_op_close_session(s->dev.addr);
         s->session = 0;
         s->next_handle = 0;
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
         usb_mtp_inotify_cleanup(s);
 #endif
         usb_mtp_object_free(s, QTAILQ_FIRST(&s->objects));
@@ -1134,7 +1134,7 @@ static void usb_mtp_handle_reset(USBDevice *dev)
 
     trace_usb_mtp_reset(s->dev.addr);
 
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
     usb_mtp_inotify_cleanup(s);
 #endif
     usb_mtp_object_free(s, QTAILQ_FIRST(&s->objects));
@@ -1297,7 +1297,7 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
         }
         break;
     case EP_EVENT:
-#ifdef __linux__
+#ifdef CONFIG_INOTIFY1
         if (!QTAILQ_EMPTY(&s->events)) {
             struct MTPMonEntry *e = QTAILQ_LAST(&s->events, events);
             uint32_t handle;
Signature · 1 line
1.8.3.1
#6 lore raw

[Qemu-devel] [PULL 6/6] usb: ehci: add capability mmio write function

In reply to Gerd Hoffmann

From: Prasad J Pandit <[email protected]>

USB Ehci emulation supports host controller capability registers. But its mmio '.write' function was missing, which lead to a null pointer dereference issue. Add a do nothing 'ehci_caps_write' definition to avoid it; Do nothing because capability registers are Read Only(RO).

Message-id: [email protected]

---
 hw/usb/hcd-ehci.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/usb/hcd-ehci.c +6 -0
index 1b50601..0f95d0d 100644
@@ -895,6 +895,11 @@ static uint64_t ehci_caps_read(void *ptr, hwaddr addr,
     return s->caps[addr];
 }
 
+static void ehci_caps_write(void *ptr, hwaddr addr,
+                             uint64_t val, unsigned size)
+{
+}
+
 static uint64_t ehci_opreg_read(void *ptr, hwaddr addr,
                                 unsigned size)
 {
@@ -2315,6 +2320,7 @@ static void ehci_frame_timer(void *opaque)
 
 static const MemoryRegionOps ehci_mmio_caps_ops = {
     .read = ehci_caps_read,
+    .write = ehci_caps_write,
     .valid.min_access_size = 1,
     .valid.max_access_size = 4,
     .impl.min_access_size = 1,
Signature · 1 line
1.8.3.1
#7 lore raw
In reply to Gerd Hoffmann
Quoted 21 lines · Gerd Hoffmann

Hi,

Here comes the usb patch queue, with a bunch of usb bugixes accumulated over the last weeks.

If you have anything outstanding usb patches which are not in here, please resend (exception: the xen host adapter patches which are waiting for review from xen people).

please pull,
Gerd

The following changes since commit 6741d38ad0f2405a6e999ebc9550801b01aca479:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2016-03-17 15:59:42 +0000)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-usb-20160321-1

Quoted 8 lines

for you to fetch changes up to dff0367cf66f489aa772320fa2937a8cac1ca30d:

usb: ehci: add capability mmio write function (2016-03-18 14:20:39 +0100)

----------------------------------------------------------------
usb: bugfix collection.

----------------------------------------------------------------

Applied, thanks.

-- PMM