/* Config descriptors must agree with the code that sets configurations and with code managing interfaces and their altsettings. They must also handle different speeds and other-speed requests.  */
static int populate_config_buf(struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
/* Config descriptors must agree with the code that sets configurations and with code managing interfaces and their altsettings. They must also handle different speeds and other-speed requests.  */
static int populate_config_buf(struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
{
	enum usb_device_speed			speed = gadget->speed;
	int					len;
	const struct usb_descriptor_header	**function;
	if (index > 0)
		return -EINVAL;
	if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
		speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
	function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
		? (const struct usb_descriptor_header **)fsg_hs_function
		: (const struct usb_descriptor_header **)fsg_fs_function;
	if (!gadget_is_otg(gadget))
		function++;
	len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
	((struct usb_config_descriptor *) buf)->bDescriptorType = type;
	return len;
}