Index: uspace/drv/bus/usb/ehci/res.c
===================================================================
--- uspace/drv/bus/usb/ehci/res.c	(revision 7de1988cde59f3ad2459d423b31be5ea19d7df75)
+++ uspace/drv/bus/usb/ehci/res.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -142,14 +142,17 @@
 		return ENOMEM;
 
+#define CHECK_RET_HANGUP_RETURN(ret, message...) \
+	if (ret != EOK) { \
+		usb_log_error(message); \
+		async_hangup(parent_sess); \
+		return ret; \
+	} else (void)0
+
 	/* Read the first EEC. i.e. Legacy Support register */
 	uint32_t usblegsup;
-	int rc = pci_config_space_read_32(parent_sess,
+	int ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret,
+	    "Failed to read USBLEGSUP: %s.\n", str_error(ret));
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
 
@@ -157,31 +160,17 @@
 	 * byte. (OS Control semaphore)*/
 	usb_log_debug("Requesting OS control.\n");
-	rc = pci_config_space_write_8(parent_sess,
+	ret = pci_config_space_write_8(parent_sess,
 	    eecp + USBLEGSUP_OFFSET + 3, 1);
-	if (rc != EOK) {
-		usb_log_error("Failed to request OS EHCI control: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n",
+	    str_error(ret));
 
 	size_t wait = 0;
 	/* Wait for BIOS to release control. */
-	rc = pci_config_space_read_32(
+	ret = pci_config_space_read_32(
 	    parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed reading PCI config space: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
 	while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
 		async_usleep(WAIT_STEP);
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGSUP_OFFSET, &usblegsup);
-		if (rc != EOK) {
-			usb_log_error("Failed reading PCI config space: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
 		wait += WAIT_STEP;
 	}
@@ -196,12 +185,8 @@
 	usb_log_warning( "BIOS failed to release control after "
 	    "%zu usecs, force it.\n", wait);
-	rc = pci_config_space_write_32(parent_sess,
+	ret = pci_config_space_write_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
-	if (rc != EOK) {
-		usb_log_error("Failed to force OS control: "
-		    "%s.\n", str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: "
+	    "%s.\n", str_error(ret));
 	/*
 	 * Check capability type here, value of 01h identifies the capability
@@ -213,12 +198,8 @@
 		/* Read the second EEC Legacy Support and Control register */
 		uint32_t usblegctlsts;
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
-			usb_log_error("Failed to get USBLEGCTLSTS: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n",
+		    str_error(ret));
 		usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts);
 		/*
@@ -227,20 +208,12 @@
 		 * interfering. NOTE: Three upper bits are WC
 		 */
-		rc = pci_config_space_write_32(parent_sess,
+		ret = pci_config_space_write_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
-		if (rc != EOK) {
-			usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc);
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret);
 		udelay(10);
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
-			usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n",
+		    str_error(ret));
 		usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n",
 		    usblegctlsts);
@@ -248,18 +221,12 @@
 
 	/* Read again Legacy Support register */
-	rc = pci_config_space_read_32(parent_sess,
+	ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n",
+	    str_error(ret));
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
 	async_hangup(parent_sess);
 	return EOK;
-error:
-	async_hangup(parent_sess);
-	return rc;
+#undef CHECK_RET_HANGUP_RETURN
 }
 
@@ -271,9 +238,9 @@
 	/* Map EHCI registers */
 	void *regs = NULL;
-	int rc = pio_enable_range(reg_range, &regs);
-	if (rc != EOK) {
+	int ret = pio_enable_range(reg_range, &regs);
+	if (ret != EOK) {
 		usb_log_error("Failed to map registers %p: %s.\n",
-		    RNGABSPTR(*reg_range), str_error(rc));
-		return rc;
+		    RNGABSPTR(*reg_range), str_error(ret));
+		return ret;
 	}
 
@@ -290,10 +257,11 @@
 	usb_log_debug("Value of EECP: %x.\n", eecp);
 
-	rc = disable_extended_caps(device, eecp);
-	if (rc != EOK) {
+	ret = disable_extended_caps(device, eecp);
+	if (ret != EOK) {
 		usb_log_error("Failed to disable extended capabilities: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
+		    str_error(ret));
+		return ret;
+	}
+
 
 	/*
@@ -334,5 +302,5 @@
 	    usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf);
 
-	return rc;
+	return ret;
 }
 
