Skip to contentSkip to conversation

usb: increase buffer for USB control requests

PATCH RESEND Applied Christian Krause 3 participants 4 messages Jan 24, 2010 – Feb 6, 2010

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 usb: increase buffer for USB control requests

Resend. The patch was already sent to the list on 2009-12-11. It would be great if it could be reviewed and applied. Thank you very much in advance.

The WLAN USB stick ZyXEL NWD271N (0586:3417) uses very large usb control transfers of more than 2048 bytes which won't fit into the buffer of the ctrl_struct. This results in an error message "husb: ctrl buffer too small" and a non-working device. Increasing the buffer size to 8192 seems to be a safe choice.

---
 usb-linux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
usb-linux.c +1 -1
index 285ac22..d205bd3 100644
@@ -113,7 +113,7 @@ struct ctrl_struct {
     uint16_t offset;
     uint8_t  state;
     struct   usb_ctrlrequest req;
-    uint8_t  buffer[2048];
+    uint8_t  buffer[8192];
 };
 
 struct USBAutoFilter {
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 11 lines · Christian Krause

Resend. The patch was already sent to the list on 2009-12-11. It would be great if it could be reviewed and applied. Thank you very much in advance.

The WLAN USB stick ZyXEL NWD271N (0586:3417) uses very large usb control transfers of more than 2048 bytes which won't fit into the buffer of the ctrl_struct. This results in an error message "husb: ctrl buffer too small" and a non-working device. Increasing the buffer size to 8192 seems to be a safe choice.

Are there any drawbacks to make\ing the buffer larger? If no, let's just make it 64K? IIUC that's a maximum length for control transfers as length is a 16 bit field.

Quoted 21 lines
---
 usb-linux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
usb-linux.c +1 -1
index 285ac22..d205bd3 100644
@@ -113,7 +113,7 @@ struct ctrl_struct {
     uint16_t offset;
     uint8_t  state;
     struct   usb_ctrlrequest req;
-    uint8_t  buffer[2048];
+    uint8_t  buffer[8192];
 };
 
 struct USBAutoFilter {
Signature · 1 line
1.6.2.5
#2 lore raw

Hello Michael,

Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Christian Krause

Resend. The patch was already sent to the list on 2009-12-11. It would be great if it could be reviewed and applied. Thank you very much in advance.

The WLAN USB stick ZyXEL NWD271N (0586:3417) uses very large usb control transfers of more than 2048 bytes which won't fit into the buffer of the ctrl_struct. This results in an error message "husb: ctrl buffer too small" and a non-working device. Increasing the buffer size to 8192 seems to be a safe choice.

Quoted 3 lines
Quoted 1 line

Are there any drawbacks to make\ing the buffer larger?

I've roughly looked into the source code of usb-linux.c and I don't see an issue if the buffer would be larger:

- if the buffer is used to get data via USBDEVFS_SUBMITURB from the kernel then the check:

    if (buffer_len > sizeof(s->ctrl.buffer)) {
        fprintf(stderr, "husb: ctrl buffer too small (%u > %zu)\n",
                buffer_len, sizeof(s->ctrl.buffer));
        return USB_RET_STALL;
    }

already ensures that the we only supply a buffer_len which matches the buffer

- on the other hand, when we copy data out of the buffer into the data structures from the HC, then there is also a check that we only copy as much data as the HC requests:

            if (len > p->len)
                len = p->len;
            memcpy(p->data, s->ctrl.buffer + s->ctrl.offset, len);
Quoted 2 lines

If no, let's just make it 64K? IIUC that's a maximum length for control transfers as length is a 16 bit field.

I think that's OK since it looks like that the increase of memory would only be 64k per usb host device.

Best regards,
Christian

Quoted 22 lines
Quoted 21 lines
---
 usb-linux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
usb-linux.c +1 -1
index 285ac22..d205bd3 100644
@@ -113,7 +113,7 @@ struct ctrl_struct {
     uint16_t offset;
     uint8_t  state;
     struct   usb_ctrlrequest req;
-    uint8_t  buffer[2048];
+    uint8_t  buffer[8192];
 };
 
 struct USBAutoFilter {
Signature · 1 line
1.6.2.5
#3 lore raw
In reply to Christian Krause
Quoted 9 lines · Christian Krause

Resend. The patch was already sent to the list on 2009-12-11. It would be great if it could be reviewed and applied. Thank you very much in advance.

The WLAN USB stick ZyXEL NWD271N (0586:3417) uses very large usb control transfers of more than 2048 bytes which won't fit into the buffer of the ctrl_struct. This results in an error message "husb: ctrl buffer too small" and a non-working device. Increasing the buffer size to 8192 seems to be a safe choice.

Thanks, applied.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net