Index: uspace/lib/ata/src/ata.c
===================================================================
--- uspace/lib/ata/src/ata.c	(revision 3d2d455b9b9a276c54f7c38d42ca2788290046b3)
+++ uspace/lib/ata/src/ata.c	(revision afb4025d4713e789ff8d0f4543e68d297744e702)
@@ -260,5 +260,6 @@
 		if (rc != EOK) {
 			ata_msg_error(chan, "Unable to remove device %d.", i);
-			break;
+			fibril_mutex_unlock(&chan->lock);
+			return rc;
 		}
 	}
@@ -266,4 +267,5 @@
 	ata_bd_fini_irq(chan);
 	fibril_mutex_unlock(&chan->lock);
+	free(chan);
 
 	return rc;
