* [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors
@ 2012-11-15 8:23 Jan Kiszka
2012-11-15 8:28 ` Gerd Hoffmann
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2012-11-15 8:23 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel
The Linux is more tolerant here as well: Just stop parsing the device
descriptors when an error is detected but do not reset what was found
so far. This allows to run buggy devices with partially invalid
descriptors.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
hw/usb/host-linux.c | 31 +++++++++++--------------------
1 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index 3a258b4..b8127e1 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -135,7 +135,7 @@ static int parse_filter(const char *spec, struct USBAutoFilter *f);
static void usb_host_auto_check(void *unused);
static int usb_host_read_file(char *line, size_t line_size,
const char *device_file, const char *device_name);
-static int usb_linux_update_endp_table(USBHostDevice *s);
+static void usb_linux_update_endp_table(USBHostDevice *s);
static int usb_host_usbfs_type(USBHostDevice *s, USBPacket *p)
{
@@ -1122,8 +1122,7 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p,
return USB_RET_ASYNC;
}
-/* returns 1 on problem encountered or 0 for success */
-static int usb_linux_update_endp_table(USBHostDevice *s)
+static void usb_linux_update_endp_table(USBHostDevice *s)
{
static const char *tname[] = {
[USB_ENDPOINT_XFER_CONTROL] = "control",
@@ -1149,23 +1148,23 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (d->bLength < 2) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"descriptor too short");
- goto error;
+ return;
}
if (i + d->bLength > s->descr_len) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"descriptor too long");
- goto error;
+ return;
}
switch (d->bDescriptorType) {
case 0:
trace_usb_host_parse_error(s->bus_num, s->addr,
"invalid descriptor type");
- goto error;
+ return;
case USB_DT_DEVICE:
if (d->bLength < 0x12) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"device descriptor too short");
- goto error;
+ return;
}
v = (d->u.device.idVendor_hi << 8) | d->u.device.idVendor_lo;
p = (d->u.device.idProduct_hi << 8) | d->u.device.idProduct_lo;
@@ -1175,7 +1174,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (d->bLength < 0x09) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"config descriptor too short");
- goto error;
+ return;
}
configuration = d->u.config.bConfigurationValue;
active = (configuration == s->dev.configuration);
@@ -1186,7 +1185,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (d->bLength < 0x09) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"interface descriptor too short");
- goto error;
+ return;
}
interface = d->u.interface.bInterfaceNumber;
altsetting = d->u.interface.bAlternateSetting;
@@ -1199,7 +1198,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (d->bLength < 0x07) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"endpoint descriptor too short");
- goto error;
+ return;
}
devep = d->u.endpoint.bEndpointAddress;
pid = (devep & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT;
@@ -1207,7 +1206,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (ep == 0) {
trace_usb_host_parse_error(s->bus_num, s->addr,
"invalid endpoint address");
- goto error;
+ return;
}
type = d->u.endpoint.bmAttributes & 0x3;
@@ -1240,11 +1239,6 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
break;
}
}
- return 0;
-
-error:
- usb_ep_reset(&s->dev);
- return 1;
}
/*
@@ -1331,10 +1325,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
}
usb_ep_init(&dev->dev);
- ret = usb_linux_update_endp_table(dev);
- if (ret) {
- goto fail;
- }
+ usb_linux_update_endp_table(dev);
if (speed == -1) {
struct usbdevfs_connectinfo ci;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors
2012-11-15 8:23 [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors Jan Kiszka
@ 2012-11-15 8:28 ` Gerd Hoffmann
2012-11-15 8:31 ` Jan Kiszka
0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2012-11-15 8:28 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
On 11/15/12 09:23, Jan Kiszka wrote:
> The Linux is more tolerant here as well: Just stop parsing the device
> descriptors when an error is detected but do not reset what was found
> so far. This allows to run buggy devices with partially invalid
> descriptors.
> -error:
> - usb_ep_reset(&s->dev);
> - return 1;
I'd prefer to keep the error jump target to handle the parse error here.
Dumping the reset there is fine with me, but I'd prefer this event being
logged (trace point or stderr message or both) to ease trouble shooting
in case a device doesn't behave as expected.
thanks,
Gerd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors
2012-11-15 8:28 ` Gerd Hoffmann
@ 2012-11-15 8:31 ` Jan Kiszka
2012-11-15 9:00 ` Gerd Hoffmann
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2012-11-15 8:31 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel
On 2012-11-15 09:28, Gerd Hoffmann wrote:
> On 11/15/12 09:23, Jan Kiszka wrote:
>> The Linux is more tolerant here as well: Just stop parsing the device
>> descriptors when an error is detected but do not reset what was found
>> so far. This allows to run buggy devices with partially invalid
>> descriptors.
>
>> -error:
>> - usb_ep_reset(&s->dev);
>> - return 1;
>
> I'd prefer to keep the error jump target to handle the parse error here.
> Dumping the reset there is fine with me, but I'd prefer this event being
> logged (trace point or stderr message or both) to ease trouble shooting
> in case a device doesn't behave as expected.
That would be "over-logging" as we already record the individual
reasons. There is simply no code to jump to after the refactoring.
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors
2012-11-15 8:31 ` Jan Kiszka
@ 2012-11-15 9:00 ` Gerd Hoffmann
0 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2012-11-15 9:00 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
On 11/15/12 09:31, Jan Kiszka wrote:
>> > I'd prefer to keep the error jump target to handle the parse error here.
>> > Dumping the reset there is fine with me, but I'd prefer this event being
>> > logged (trace point or stderr message or both) to ease trouble shooting
>> > in case a device doesn't behave as expected.
> That would be "over-logging" as we already record the individual
> reasons. There is simply no code to jump to after the refactoring.
Oh, right, we trace that already. Ok then.
Patch added to usb patch queue.
thanks,
Gerd
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-15 9:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-15 8:23 [Qemu-devel] [PATCH] usb: host-linux: Ignore parsing errors of the device descriptors Jan Kiszka
2012-11-15 8:28 ` Gerd Hoffmann
2012-11-15 8:31 ` Jan Kiszka
2012-11-15 9:00 ` Gerd Hoffmann
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).