/* Copy configuration data to urb transfer buffer if there is room for it.  */
void copy_config(struct urb *urb, void *data, int max_length, int max_buf)
/* Copy configuration data to urb transfer buffer if there is room for it.  */
void copy_config(struct urb *urb, void *data, int max_length, int max_buf)
{
	int available;
	int length;
	if (!data) {
		dbg_ep0 (1, "data is NULL");
		return;
	}
	length = max_length;
	if (length > max_length) {
		dbg_ep0 (1, "length: %d >= max_length: %d", length,
			 max_length);
		return;
	}
	if ((available = max_buf - urb->actual_length) <= 0) {
		return;
	}
	if (length > available) {
		length = available;
	}
	memcpy (urb->buffer + urb->actual_length, data, length);
	urb->actual_length += length;
	dbg_ep0 (3,
		 "copy_config: <- actual: %d buf: %d max_buf: %d max_length: %d available: %d",
		 urb->actual_length, urb->buffer_length, max_buf, max_length,
		 available);
}