Index: uspace/drv/uhci-hcd/main.c
===================================================================
--- uspace/drv/uhci-hcd/main.c	(revision dced52af3bee58828a4b524068bd68da26c46c60)
+++ uspace/drv/uhci-hcd/main.c	(revision 86341e250e53daae8e228df98df953c885145b1f)
@@ -70,13 +70,15 @@
 }
 /*----------------------------------------------------------------------------*/
-#define CHECK_RET_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	return ret; \
-}
-
 static int uhci_add_device(ddf_dev_t *device)
 {
 	assert(device);
+	uhci_t *hcd = NULL;
+#define CHECK_RET_FREE_HC_RETURN(ret, message...) \
+if (ret != EOK) { \
+	usb_log_error(message); \
+	if (hcd != NULL) \
+		free(hcd); \
+	return ret; \
+}
 
 	usb_log_info("uhci_add_device() called\n");
@@ -88,6 +90,5 @@
 	int ret =
 	    pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
-
-	CHECK_RET_RETURN(ret,
+	CHECK_RET_FREE_HC_RETURN(ret,
 	    "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
 	usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
@@ -95,51 +96,51 @@
 
 //	ret = pci_enable_interrupts(device);
-//	CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
+//	CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
 
-	uhci_t *uhci_hc = malloc(sizeof(uhci_t));
-	ret = (uhci_hc != NULL) ? EOK : ENOMEM;
-	CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
+	hcd = malloc(sizeof(uhci_t));
+	ret = (hcd != NULL) ? EOK : ENOMEM;
+	CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to allocate memory for uhci hcd.\n",
+	    ret);
 
-	ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
-	if (ret != EOK) {
-		usb_log_error("Failed to init uhci-hcd.\n");
-		free(uhci_hc);
-		return ret;
-	}
+	ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size);
+	CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n",
+	    ret);
+#undef CHECK_RET_FREE_HC_RETURN
 
 	/*
-	 * We might free uhci_hc, but that does not matter since no one
+	 * We might free hcd, but that does not matter since no one
 	 * else would access driver_data anyway.
 	 */
-	device->driver_data = uhci_hc;
+	device->driver_data = hcd;
+
+	ddf_fun_t *rh = NULL;
+#define CHECK_RET_FINI_FREE_RETURN(ret, message...) \
+if (ret != EOK) { \
+	usb_log_error(message); \
+	if (hcd != NULL) {\
+		uhci_fini(hcd); \
+		free(hcd); \
+	} \
+	if (rh != NULL) \
+		free(rh); \
+	return ret; \
+}
+
 	ret = register_interrupt_handler(device, irq, irq_handler,
-	    &uhci_hc->interrupt_code);
-	if (ret != EOK) {
-		usb_log_error("Failed to register interrupt handler.\n");
-		uhci_fini(uhci_hc);
-		free(uhci_hc);
-		return ret;
-	}
+	    &hcd->interrupt_code);
+	CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to register interrupt handler.\n",
+	    ret);
 
-	ddf_fun_t *rh;
 	ret = setup_root_hub(&rh, device);
-	if (ret != EOK) {
-		usb_log_error("Failed to setup uhci root hub.\n");
-		uhci_fini(uhci_hc);
-		free(uhci_hc);
-		return ret;
-	}
-	rh->driver_data = uhci_hc->ddf_instance;
+	CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to setup UHCI root hub.\n",
+	    ret);
+	rh->driver_data = hcd->ddf_instance;
 
 	ret = ddf_fun_bind(rh);
-	if (ret != EOK) {
-		usb_log_error("Failed to register root hub.\n");
-		uhci_fini(uhci_hc);
-		free(uhci_hc);
-		free(rh);
-		return ret;
-	}
+	CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to register UHCI root hub.\n",
+	    ret);
 
 	return EOK;
+#undef CHECK_RET_FINI_FREE_RETURN
 }
 /*----------------------------------------------------------------------------*/
