Index: uspace/drv/uhci-hcd/transfer_list.c
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.c	(revision a7e2f0dab29fadc4ae66c44ba1629b177fd6679d)
+++ uspace/drv/uhci-hcd/transfer_list.c	(revision 1b0b86e6d0d35593a47a74325a9086d70705ef94)
@@ -47,12 +47,11 @@
  * @return Error code
  *
- * Allocates memory for internat queue_head_t structure.
+ * Allocates memory for internal qh_t structure.
  */
 int transfer_list_init(transfer_list_t *instance, const char *name)
 {
 	assert(instance);
-	instance->next = NULL;
 	instance->name = name;
-	instance->queue_head = malloc32(sizeof(queue_head_t));
+	instance->queue_head = malloc32(sizeof(qh_t));
 	if (!instance->queue_head) {
 		usb_log_error("Failed to allocate queue head.\n");
@@ -61,5 +60,5 @@
 	instance->queue_head_pa = addr_to_phys(instance->queue_head);
 
-	queue_head_init(instance->queue_head);
+	qh_init(instance->queue_head);
 	list_initialize(&instance->batch_list);
 	fibril_mutex_initialize(&instance->guard);
@@ -72,4 +71,6 @@
  * @param[in] next List to append.
  * @return Error code
+ *
+ * Does not check whether there was a next list already.
  */
 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
@@ -79,6 +80,7 @@
 	if (!instance->queue_head)
 		return;
-	queue_head_append_qh(instance->queue_head, next->queue_head_pa);
-	instance->queue_head->element = instance->queue_head->next_queue;
+	/* set both next and element to point to the same QH */
+	qh_set_next_qh(instance->queue_head, next->queue_head_pa);
+	qh_set_element_qh(instance->queue_head, next->queue_head_pa);
 }
 /*----------------------------------------------------------------------------*/
@@ -93,43 +95,42 @@
 	assert(instance);
 	assert(batch);
-	usb_log_debug2(
-	    "Adding batch(%p) to queue %s.\n", batch, instance->name);
+	usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
 
-	uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
+	const uint32_t pa = addr_to_phys(batch->qh);
 	assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
-	pa |= LINK_POINTER_QUEUE_HEAD_FLAG;
 
-	batch->qh->next_queue = instance->queue_head->next_queue;
+	/* New batch will be added to the end of the current list
+	 * so set the link accordingly */
+	qh_set_next_qh(batch->qh, instance->queue_head->next);
 
 	fibril_mutex_lock(&instance->guard);
 
-	if (instance->queue_head->element == instance->queue_head->next_queue) {
-		/* there is nothing scheduled */
-		list_append(&batch->link, &instance->batch_list);
-		instance->queue_head->element = pa;
-		usb_log_debug("Batch(%p) added to queue %s first.\n",
-			batch, instance->name);
-		fibril_mutex_unlock(&instance->guard);
-		return;
+	if (list_empty(&instance->batch_list)) {
+		/* There is nothing scheduled */
+		qh_t *qh = instance->queue_head;
+		assert(qh->element == qh->next);
+		qh_set_element_qh(qh, pa);
+	} else {
+		/* There is something scheduled */
+		batch_t *last = list_get_instance(
+		    instance->batch_list.prev, batch_t, link);
+		qh_set_next_qh(last->qh, pa);
 	}
-	/* now we can be sure that there is someting scheduled */
-	assert(!list_empty(&instance->batch_list));
-	batch_t *first = list_get_instance(
-	          instance->batch_list.next, batch_t, link);
-	batch_t *last = list_get_instance(
-	    instance->batch_list.prev, batch_t, link);
-	queue_head_append_qh(last->qh, pa);
 	list_append(&batch->link, &instance->batch_list);
 
-	usb_log_debug("Batch(%p) added to queue %s last, first is %p.\n",
+	batch_t *first = list_get_instance(
+	    instance->batch_list.next, batch_t, link);
+	usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
 		batch, instance->name, first);
 	fibril_mutex_unlock(&instance->guard);
 }
 /*----------------------------------------------------------------------------*/
-/** Removes a transfer batch from list and queue.
+/** Removes a transfer batch from the list and queue.
  *
  * @param[in] instance List to use.
  * @param[in] batch Transfer batch to remove.
  * @return Error code
+ *
+ * Does not lock the transfer list, caller is responsible for that.
  */
 void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
@@ -140,24 +141,23 @@
 	assert(batch->qh);
 	usb_log_debug2(
-	    "Removing batch(%p) from queue %s.\n", batch, instance->name);
+	    "Queue %s: removing batch(%p).\n", instance->name, batch);
 
+	const char * pos = NULL;
 	if (batch->link.prev == &instance->batch_list) {
 		/* I'm the first one here */
-		usb_log_debug(
-		    "Batch(%p) removed (FIRST) from %s, next element %x.\n",
-		    batch, instance->name, batch->qh->next_queue);
-		instance->queue_head->element = batch->qh->next_queue;
+		qh_set_element_qh(instance->queue_head, batch->qh->next);
+		pos = "FIRST";
 	} else {
-		usb_log_debug(
-		    "Batch(%p) removed (FIRST:NO) from %s, next element %x.\n",
-		    batch, instance->name, batch->qh->next_queue);
 		batch_t *prev =
 		    list_get_instance(batch->link.prev, batch_t, link);
-		prev->qh->next_queue = batch->qh->next_queue;
+		qh_set_next_qh(prev->qh, batch->qh->next);
+		pos = "NOT FIRST";
 	}
 	list_remove(&batch->link);
+	usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
+	    batch, pos, instance->name, batch->qh->next);
 }
 /*----------------------------------------------------------------------------*/
-/** Checks list for finished transfers.
+/** Checks list for finished batches.
  *
  * @param[in] instance List to use.
