Index: uspace/drv/uhci-hcd/uhci.c
===================================================================
--- uspace/drv/uhci-hcd/uhci.c	(revision 4abc304ad9746878e6ac0f52927611953d8ac861)
+++ uspace/drv/uhci-hcd/uhci.c	(revision 8c877b2a07198dee060be64f23ea473d6374b372)
@@ -90,5 +90,5 @@
 	.interfaces[USBHC_DEV_IFACE] = &uhci_iface,
 };
-
+/*----------------------------------------------------------------------------*/
 static int uhci_init_transfer_lists(uhci_t *instance);
 static int uhci_init_mem_structures(uhci_t *instance);
@@ -115,10 +115,9 @@
 	} else (void) 0
 
-	/*
-	 * Create UHCI function.
-	 */
+	/* Create UHCI function. */
 	instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci");
 	ret = (instance->ddf_instance == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_FUN_RETURN(ret, "Failed to create UHCI device function.\n");
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed to create UHCI device function.\n");
 
 	instance->ddf_instance->ops = &uhci_ops;
@@ -126,5 +125,6 @@
 
 	ret = ddf_fun_bind(instance->ddf_instance);
-	CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to bind UHCI device function: %s.\n",
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed(%d) to bind UHCI device function: %s.\n",
 	    ret, str_error(ret));
 
@@ -132,15 +132,18 @@
 	regs_t *io;
 	ret = pio_enable(regs, reg_size, (void**)&io);
-	CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to gain access to registers at %p: %s.\n",
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed(%d) to gain access to registers at %p: %s.\n",
 	    ret, str_error(ret), io);
 	instance->registers = io;
-	usb_log_debug("Device registers at %p(%u) accessible.\n", io, reg_size);
+	usb_log_debug("Device registers at %p(%u) accessible.\n",
+	    io, reg_size);
 
 	ret = uhci_init_mem_structures(instance);
-	CHECK_RET_DEST_FUN_RETURN(ret, "Failed to initialize UHCI memory structures.\n");
+	CHECK_RET_DEST_FUN_RETURN(ret,
+	    "Failed to initialize UHCI memory structures.\n");
 
 	uhci_init_hw(instance);
-
-	instance->cleaner = fibril_create(uhci_interrupt_emulator, instance);
+	instance->cleaner =
+	    fibril_create(uhci_interrupt_emulator, instance);
 	fibril_add_ready(instance->cleaner);
 
@@ -155,4 +158,6 @@
 void uhci_init_hw(uhci_t *instance)
 {
+	assert(instance);
+
 	/* reset everything, who knows what touched it before us */
 	pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
@@ -171,5 +176,5 @@
 	/* enable all interrupts, but resume interrupt */
 	pio_write_16(&instance->registers->usbintr,
-		  UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
+	    UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
 
 	/* Start the hc with large(64B) packet FSBR */
@@ -200,5 +205,5 @@
 		interrupt_commands[1].addr = (void*)&instance->registers->usbsts;
 		instance->interrupt_code.cmdcount =
-				sizeof(uhci_cmds) / sizeof(irq_cmd_t);
+		    sizeof(uhci_cmds) / sizeof(irq_cmd_t);
 	}
 
@@ -249,8 +254,11 @@
 	ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");
+
 	ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");
+
 	ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");
+
 	ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init INTERRUPT list.");
@@ -292,5 +300,5 @@
 	    low_speed, batch->transfer_type, batch->max_packet_size)) {
 		usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n",
-			  low_speed ? "LOW" : "FULL" , batch->transfer_type,
+		    low_speed ? "LOW" : "FULL" , batch->transfer_type,
 		    batch->max_packet_size);
 		return ENOTSUP;
@@ -309,7 +317,4 @@
 {
 	assert(instance);
-//	if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)
-//		return;
-//	usb_log_debug2("UHCI interrupt: %X.\n", status);
 	transfer_list_remove_finished(&instance->transfers_interrupt);
 	transfer_list_remove_finished(&instance->transfers_control_slow);
@@ -340,8 +345,14 @@
 	uhci_t *instance = (uhci_t*)arg;
 	assert(instance);
+
+#define QH(queue) \
+	instance->transfers_##queue.queue_head
+
 	while (1) {
 		const uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
 		const uint16_t sts = pio_read_16(&instance->registers->usbsts);
-		const uint16_t intr = pio_read_16(&instance->registers->usbintr);
+		const uint16_t intr =
+		    pio_read_16(&instance->registers->usbintr);
+
 		if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) {
 			usb_log_debug2("Command: %X Status: %X Intr: %x\n",
@@ -353,58 +364,57 @@
 		if (frame_list != addr_to_phys(instance->frame_list)) {
 			usb_log_debug("Framelist address: %p vs. %p.\n",
-				frame_list, addr_to_phys(instance->frame_list));
-		}
+			    frame_list, addr_to_phys(instance->frame_list));
+		}
+
 		int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff;
 		usb_log_debug2("Framelist item: %d \n", frnum );
 
-		queue_head_t* qh = instance->transfers_interrupt.queue_head;
-
-		if ((instance->frame_list[frnum] & (~0xf)) != (uintptr_t)addr_to_phys(qh)) {
+		uintptr_t expected_pa = instance->frame_list[frnum] & (~0xf);
+		uintptr_t real_pa = addr_to_phys(QH(interrupt));
+		if (expected_pa != real_pa) {
 			usb_log_debug("Interrupt QH: %p vs. %p.\n",
-				instance->frame_list[frnum] & (~0xf), addr_to_phys(qh));
-		}
-
-		if ((qh->next_queue & (~0xf))
-		  != (uintptr_t)addr_to_phys(instance->transfers_control_slow.queue_head)) {
-			usb_log_debug("Control Slow QH: %p vs. %p.\n", qh->next_queue & (~0xf),
-				addr_to_phys(instance->transfers_control_slow.queue_head));
-		}
-		qh = instance->transfers_control_slow.queue_head;
-
-		if ((qh->next_queue & (~0xf))
-		  != (uintptr_t)addr_to_phys(instance->transfers_control_full.queue_head)) {
-			usb_log_debug("Control Full QH: %p vs. %p.\n", qh->next_queue & (~0xf),
-				addr_to_phys(instance->transfers_control_full.queue_head));\
-		}
-		qh = instance->transfers_control_full.queue_head;
-
-		if ((qh->next_queue & (~0xf))
-		  != (uintptr_t)addr_to_phys(instance->transfers_bulk_full.queue_head)) {
-			usb_log_debug("Bulk QH: %p vs. %p.\n", qh->next_queue & (~0xf),
-				addr_to_phys(instance->transfers_bulk_full.queue_head));
-		}
-/*
-	uint16_t cmd = pio_read_16(&instance->registers->usbcmd);
-	cmd |= UHCI_CMD_RUN_STOP;
-	pio_write_16(&instance->registers->usbcmd, cmd);
-*/
+			    expected_pa, real_pa);
+		}
+
+		expected_pa = QH(interrupt)->next_queue & (~0xf);
+		real_pa = addr_to_phys(QH(control_slow));
+		if (expected_pa != real_pa) {
+			usb_log_debug("Control Slow QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
+
+		expected_pa = QH(control_slow)->next_queue & (~0xf);
+		real_pa = addr_to_phys(QH(control_full));
+		if (expected_pa != real_pa) {
+			usb_log_debug("Control Full QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
+
+		expected_pa = QH(control_full)->next_queue & (~0xf);
+		real_pa = addr_to_phys(QH(bulk_full));
+		if (expected_pa != real_pa ) {
+			usb_log_debug("Bulk QH: %p vs. %p.\n",
+			    expected_pa, real_pa);
+		}
 		async_usleep(UHCI_DEBUGER_TIMEOUT);
 	}
 	return 0;
+#undef QH
 }
 /*----------------------------------------------------------------------------*/
 bool allowed_usb_packet(
-	bool low_speed, usb_transfer_type_t transfer, size_t size)
+    bool low_speed, usb_transfer_type_t transfer, size_t size)
 {
 	/* see USB specification chapter 5.5-5.8 for magic numbers used here */
-	switch(transfer) {
-		case USB_TRANSFER_ISOCHRONOUS:
-			return (!low_speed && size < 1024);
-		case USB_TRANSFER_INTERRUPT:
-			return size <= (low_speed ? 8 : 64);
-		case USB_TRANSFER_CONTROL: /* device specifies its own max size */
-			return (size <= (low_speed ? 8 : 64));
-		case USB_TRANSFER_BULK: /* device specifies its own max size */
-			return (!low_speed && size <= 64);
+	switch(transfer)
+	{
+	case USB_TRANSFER_ISOCHRONOUS:
+		return (!low_speed && size < 1024);
+	case USB_TRANSFER_INTERRUPT:
+		return size <= (low_speed ? 8 : 64);
+	case USB_TRANSFER_CONTROL: /* device specifies its own max size */
+		return (size <= (low_speed ? 8 : 64));
+	case USB_TRANSFER_BULK: /* device specifies its own max size */
+		return (!low_speed && size <= 64);
 	}
 	return false;
