/* Returns a pointer to a kmalloc'ed buffer containing the descriptor string, or NULL if the index is 0 or the string could not be read.  */
char* usb_cache_string(struct usb_device *udev, int index)
/* Returns a pointer to a kmalloc'ed buffer containing the descriptor string, or NULL if the index is 0 or the string could not be read.  */
char* usb_cache_string(struct usb_device *udev, int index)
{
	char *buf;
	char *smallbuf = NULL;
	int len;
	if (index <= 0)
		return NULL;
	buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
	if (buf) {
		len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
		if (len > 0) {
			smallbuf = kmalloc(++len, GFP_NOIO);
			if (!smallbuf)
				return buf;
			memcpy(smallbuf, buf, len);
		}
		kfree(buf);
	}
	return smallbuf;
}