Index: uspace/lib/c/generic/devman.c
===================================================================
--- uspace/lib/c/generic/devman.c	(revision 4a4c8bcf0ce34cbf901b7d7d1d02ef84f5b04d48)
+++ uspace/lib/c/generic/devman.c	(revision 15e54f5a4722e870a6c517c286a0f18e7aa1054d)
@@ -231,17 +231,4 @@
 	}
 	
-	async_wait_for(req, &retval);
-	if (retval != EOK) {
-		devman_exchange_end(exch);
-		
-		if (funh != NULL)
-			*funh = -1;
-		
-		return retval;
-	}
-	
-	if (funh != NULL)
-		*funh = (int) IPC_GET_ARG1(answer);
-	
 	link_t *link = match_ids->ids.next;
 	match_id_t *match_id = NULL;
@@ -250,9 +237,17 @@
 		match_id = list_get_instance(link, match_id_t, link);
 		
-		ipc_call_t answer;
-		aid_t req = async_send_1(exch, DEVMAN_ADD_MATCH_ID,
-		    match_id->score, &answer);
+		ipc_call_t answer2;
+		aid_t req2 = async_send_1(exch, DEVMAN_ADD_MATCH_ID,
+		    match_id->score, &answer2);
 		retval = async_data_write_start(exch, match_id->id,
 		    str_size(match_id->id));
+		if (retval != EOK) {
+			devman_exchange_end(exch);
+			async_wait_for(req2, NULL);
+			async_wait_for(req, NULL);
+			return retval;
+		}
+		
+		async_wait_for(req2, &retval);
 		if (retval != EOK) {
 			devman_exchange_end(exch);
@@ -261,15 +256,19 @@
 		}
 		
-		async_wait_for(req, &retval);
-		if (retval != EOK) {
-			devman_exchange_end(exch);
-			return retval;
-		}
-		
 		link = link->next;
 	}
 	
 	devman_exchange_end(exch);
-	return EOK;
+	
+	async_wait_for(req, &retval);
+	if (retval != EOK) {
+		if (funh != NULL)
+			*funh = (int) IPC_GET_ARG1(answer);
+	} else {
+		if (funh != NULL)
+			*funh = -1;
+	}
+	
+	return retval;
 }
 
