Commit 7947cefa authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[PATCH] USB: usb_get_descriptor, more error checks

I've had different versions of this floating around for a while;
basically, the goal is to be more robust against devices that
misbehave by returning garbage descriptors in certain cases.

Add an extra check when fetching descriptors:  the type must be
correct.  This guards against different types of firmware (or maybe
hardware) errors than the two checks already being made.
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 4a2daf2d
......@@ -577,8 +577,13 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
(type << 8) + index, 0, buf, size,
HZ * USB_CTRL_GET_TIMEOUT);
if (!(result == 0 || result == -EPIPE))
break;
if (result == 0 || result == -EPIPE)
continue;
if (result > 1 && ((u8 *)buf)[1] != type) {
retval = -EPROTO;
continue;
}
break;
}
return result;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment