Index: kernel/generic/include/cap/cap.h
===================================================================
--- kernel/generic/include/cap/cap.h	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/include/cap/cap.h	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -121,5 +121,5 @@
     bool (*)(cap_t *, void *), void *);
 
-extern cap_handle_t cap_alloc(struct task *);
+extern int cap_alloc(struct task *, cap_handle_t *);
 extern void cap_publish(struct task *, cap_handle_t, kobject_t *);
 extern kobject_t *cap_unpublish(struct task *, cap_handle_t, kobject_type_t);
Index: kernel/generic/include/ipc/ipcrsc.h
===================================================================
--- kernel/generic/include/ipc/ipcrsc.h	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/include/ipc/ipcrsc.h	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -40,5 +40,5 @@
 #include <cap/cap.h>
 
-extern cap_handle_t phone_alloc(task_t *);
+extern int phone_alloc(task_t *, cap_handle_t *);
 extern bool phone_connect(cap_handle_t, answerbox_t *);
 extern void phone_dealloc(cap_handle_t);
Index: kernel/generic/src/cap/cap.c
===================================================================
--- kernel/generic/src/cap/cap.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/cap/cap.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -257,11 +257,11 @@
  * @param task  Task for which to allocate the new capability.
  *
- * @return New capability handle on success.
+ * @param[out] handle  New capability handle on success.
+ *
  * @return Negative error code in case of error.
  */
-cap_handle_t cap_alloc(task_t *task)
+int cap_alloc(task_t *task, cap_handle_t *handle)
 {
 	cap_t *cap = NULL;
-	cap_handle_t handle;
 
 	/*
@@ -293,8 +293,8 @@
 
 	cap->state = CAP_STATE_ALLOCATED;
-	handle = cap->handle;
-	mutex_unlock(&task->cap_info->lock);
-
-	return handle;
+	*handle = cap->handle;
+	mutex_unlock(&task->cap_info->lock);
+
+	return EOK;
 }
 
Index: kernel/generic/src/ipc/ipcrsc.c
===================================================================
--- kernel/generic/src/ipc/ipcrsc.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/ipcrsc.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -166,11 +166,13 @@
  * @param task  Task for which to allocate a new phone.
  *
- * @return  New phone capability handle.
+ * @param[out] out_handle  New phone capability handle.
+ *
  * @return  Negative error code if a new capability cannot be allocated.
  */
-cap_handle_t phone_alloc(task_t *task)
-{
-	cap_handle_t handle = cap_alloc(task);
-	if (handle >= 0) {
+int phone_alloc(task_t *task, cap_handle_t *out_handle)
+{
+	cap_handle_t handle;
+	int rc = cap_alloc(task, &handle);
+	if (rc == EOK) {
 		phone_t *phone = slab_alloc(phone_cache, FRAME_ATOMIC);
 		if (!phone) {
@@ -193,7 +195,8 @@
 		
 		cap_publish(task, handle, kobject);
+
+		*out_handle = handle;
 	}
-	
-	return handle;
+	return rc;
 }
 
Index: kernel/generic/src/ipc/irq.c
===================================================================
--- kernel/generic/src/ipc/irq.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/irq.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -330,9 +330,10 @@
 	 * Allocate and populate the IRQ kernel object.
 	 */
-	cap_handle_t handle = cap_alloc(TASK);
-	if (handle < 0)
-		return handle;
-	
-	int rc = copy_to_uspace(uspace_handle, &handle, sizeof(cap_handle_t));
+	cap_handle_t handle;
+	int rc = cap_alloc(TASK, &handle);
+	if (rc != EOK)
+		return rc;
+	
+	rc = copy_to_uspace(uspace_handle, &handle, sizeof(cap_handle_t));
 	if (rc != EOK) {
 		cap_free(TASK, handle);
Index: kernel/generic/src/ipc/kbox.c
===================================================================
--- kernel/generic/src/ipc/kbox.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/kbox.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -252,8 +252,9 @@
 	
 	/* Allocate a new phone. */
-	cap_handle_t phone_handle = phone_alloc(TASK);
-	if (phone_handle < 0) {
+	cap_handle_t phone_handle;
+	int rc = phone_alloc(TASK, &phone_handle);
+	if (rc != EOK) {
 		mutex_unlock(&task->kb.cleanup_lock);
-		return phone_handle;
+		return rc;
 	}
 	
Index: kernel/generic/src/ipc/ops/conctmeto.c
===================================================================
--- kernel/generic/src/ipc/ops/conctmeto.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/ops/conctmeto.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -42,10 +42,13 @@
 static int request_preprocess(call_t *call, phone_t *phone)
 {
-	cap_handle_t phone_handle = phone_alloc(TASK);
+	cap_handle_t phone_handle;
+	int rc = phone_alloc(TASK, &phone_handle);
 
-	/* Remember the phone capability or the error. */
-	call->priv = phone_handle;
-	if (phone_handle < 0)
-		return phone_handle;
+	/* Remember the phone capability or that an error occured. */
+	call->priv = (rc == EOK) ? phone_handle : -1;
+
+	if (rc != EOK) {
+		return rc;
+	}
 
 	/* Set arg5 for server */
@@ -61,4 +64,9 @@
 {
 	cap_handle_t phone_handle = (cap_handle_t) call->priv;
+
+	if (phone_handle < 0) {
+		return EOK;
+	}
+
 	phone_dealloc(phone_handle);
 	/* Hand over reference from ARG5 to phone->kobject */
Index: kernel/generic/src/ipc/ops/concttome.c
===================================================================
--- kernel/generic/src/ipc/ops/concttome.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/ops/concttome.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -42,9 +42,8 @@
 static int request_process(call_t *call, answerbox_t *box)
 {
-	cap_handle_t phone_handle = phone_alloc(TASK);
-
-	IPC_SET_ARG5(call->data, phone_handle);
-	
-	return EOK;
+	cap_handle_t phone_handle;
+	int rc = phone_alloc(TASK, &phone_handle);
+	IPC_SET_ARG5(call->data, (rc == EOK) ? phone_handle : -1);
+	return 0;
 }
 
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/ipc/sysipc.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -804,8 +804,7 @@
 		goto restart;
 	
-	int rc;
-	cap_handle_t handle = cap_alloc(TASK);
-	if (handle < 0) {
-		rc = handle;
+	cap_handle_t handle;
+	int rc = cap_alloc(TASK, &handle);
+	if (rc != EOK) {
 		goto error;
 	}
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 6a32cc5f9f405da0c7afb110e787059cfec044b8)
+++ kernel/generic/src/proc/task.c	(revision 23d45152e0fb1fe800c3d2feff9821e9e25265da)
@@ -245,6 +245,7 @@
 	if ((ipc_phone_0) &&
 	    (container_check(ipc_phone_0->task->container, task->container))) {
-		cap_handle_t phone_handle = phone_alloc(task);
-		if (phone_handle < 0) {
+		cap_handle_t phone_handle;
+		int rc = phone_alloc(task, &phone_handle);
+		if (rc != EOK) {
 			task->as = NULL;
 			task_destroy_arch(task);
