/* parse descriptor buffer and return the pointer starting the given descriptor type.  */
void* snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype)
/* parse descriptor buffer and return the pointer starting the given descriptor type.  */
void* snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype)
{
	u8 *p, *end, *next;
	p = descstart;
	end = p + desclen;
	for (; p < end;) {
		if (p[0] < 2)
			return NULL;
		next = p + p[0];
		if (next > end)
			return NULL;
		if (p[1] == dtype && (!after || (void *)p > after)) {
			return p;
		}
		p = next;
	}
	return NULL;
}