Index: uspace/lib/graph/graph.c
===================================================================
--- uspace/lib/graph/graph.c	(revision 921f3935056b347f8d7b93459df10706e2809b28)
+++ uspace/lib/graph/graph.c	(revision df2e621c24f26d06158dbd519ce22ee6c3cd0775)
@@ -58,10 +58,5 @@
 visualizer_t *graph_alloc_visualizer(void)
 {
-	visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t));
-	if (vs == NULL) {
-		return NULL;
-	}
-	
-	return vs;
+	return ((visualizer_t *) malloc(sizeof(visualizer_t)));
 }
 
@@ -69,10 +64,5 @@
 {
 	// TODO
-	renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t));
-	if (rnd == NULL) {
-		return NULL;
-	}
-
-	return rnd;
+	return ((renderer_t *) malloc(sizeof(renderer_t)));
 }
 
@@ -98,21 +88,17 @@
 int graph_register_visualizer(visualizer_t *vs)
 {
-	int rc = EOK;
-	
 	char node[LOC_NAME_MAXLEN + 1];
 	snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
 	    namespace_idx, VISUALIZER_NAME, visualizer_idx++);
-
+	
 	category_id_t cat;
-	rc = loc_category_get_id("visualizer", &cat, 0);
-	if (rc != EOK) {
+	int rc = loc_category_get_id("visualizer", &cat, 0);
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	rc = loc_service_register(node, &vs->reg_svc_handle);
-	if (rc != EOK) {
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
 	if (rc != EOK) {
@@ -120,9 +106,9 @@
 		return rc;
 	}
-
+	
 	fibril_mutex_lock(&visualizer_list_mtx);
 	list_append(&vs->link, &visualizer_list);
 	fibril_mutex_unlock(&visualizer_list_mtx);
-
+	
 	return rc;
 }
@@ -130,21 +116,17 @@
 int graph_register_renderer(renderer_t *rnd)
 {
-	int rc = EOK;
-
 	char node[LOC_NAME_MAXLEN + 1];
 	snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
 	    namespace_idx, RENDERER_NAME, renderer_idx++);
-
+	
 	category_id_t cat;
-	rc = loc_category_get_id("renderer", &cat, 0);
-	if (rc != EOK) {
+	int rc = loc_category_get_id("renderer", &cat, 0);
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	rc = loc_service_register(node, &rnd->reg_svc_handle);
-	if (rc != EOK) {
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
 	if (rc != EOK) {
@@ -152,9 +134,9 @@
 		return rc;
 	}
-
+	
 	fibril_mutex_lock(&renderer_list_mtx);
 	list_append(&rnd->link, &renderer_list);
 	fibril_mutex_unlock(&renderer_list_mtx);
-
+	
 	return rc;
 }
@@ -163,6 +145,7 @@
 {
 	visualizer_t *vs = NULL;
-
+	
 	fibril_mutex_lock(&visualizer_list_mtx);
+	
 	list_foreach(visualizer_list, link, visualizer_t, vcur) {
 		if (vcur->reg_svc_handle == handle) {
@@ -171,6 +154,7 @@
 		}
 	}
+	
 	fibril_mutex_unlock(&visualizer_list_mtx);
-
+	
 	return vs;
 }
@@ -179,6 +163,7 @@
 {
 	renderer_t *rnd = NULL;
-
+	
 	fibril_mutex_lock(&renderer_list_mtx);
+	
 	list_foreach(renderer_list, link, renderer_t, rcur) {
 		if (rcur->reg_svc_handle == handle) {
@@ -187,6 +172,7 @@
 		}
 	}
+	
 	fibril_mutex_unlock(&renderer_list_mtx);
-
+	
 	return rnd;
 }
@@ -194,11 +180,9 @@
 int graph_unregister_visualizer(visualizer_t *vs)
 {
-	int rc = EOK;
-
 	fibril_mutex_lock(&visualizer_list_mtx);
-	rc = loc_service_unregister(vs->reg_svc_handle);
+	int rc = loc_service_unregister(vs->reg_svc_handle);
 	list_remove(&vs->link);
 	fibril_mutex_unlock(&visualizer_list_mtx);
-
+	
 	return rc;
 }
@@ -206,11 +190,9 @@
 int graph_unregister_renderer(renderer_t *rnd)
 {
-	int rc = EOK;
-
 	fibril_mutex_lock(&renderer_list_mtx);
-	rc = loc_service_unregister(rnd->reg_svc_handle);
+	int rc = loc_service_unregister(rnd->reg_svc_handle);
 	list_remove(&rnd->link);
 	fibril_mutex_unlock(&renderer_list_mtx);
-
+	
 	return rc;
 }
@@ -225,5 +207,5 @@
 	assert(vs->cells.data == NULL);
 	assert(vs->dev_ctx == NULL);
-
+	
 	free(vs);
 }
@@ -233,5 +215,5 @@
 	// TODO
 	assert(atomic_get(&rnd->ref_cnt) == 0);
-
+	
 	free(rnd);
 }
@@ -242,5 +224,5 @@
 	int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
 	async_exchange_end(exch);
-
+	
 	return ret;
 }
@@ -251,7 +233,7 @@
 	int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
 	async_exchange_end(exch);
-
+	
 	async_hangup(sess);
-
+	
 	return ret;
 }
@@ -273,14 +255,13 @@
 		}
 	}
-
+	
 	/* Driver might also deallocate resources for the current mode. */
 	int rc = vs->ops.yield(vs);
-
+	
 	/* Now that the driver was given a chance to deallocate resources,
 	 * current mode can be unset. */
-	if (vs->mode_set) {
+	if (vs->mode_set)
 		vs->mode_set = false;
-	}
-
+	
 	async_answer_0(iid, rc);
 }
@@ -288,37 +269,44 @@
 static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
 {
+	ipc_callid_t callid;
+	size_t len;
+	
+	if (!async_data_read_receive(&callid, &len)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
+		return;
+	}
+	
 	fibril_mutex_lock(&vs->mode_mtx);
 	link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
-
+	
 	if (link != NULL) {
 		vslmode_list_element_t *mode_elem =
 		    list_get_instance(link, vslmode_list_element_t, link);
-		vslmode_t mode = mode_elem->mode;
-		fibril_mutex_unlock(&vs->mode_mtx);
-
-		ipc_callid_t callid;
-		size_t len;
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(iid, EINVAL);
-			return;
-		}
-		int rc = async_data_read_finalize(callid, &mode, len);
-		if (rc != EOK) {
-			async_answer_0(iid, ENOMEM);
-			return;
-		}
-
-		async_answer_0(iid, EOK);
+		
+		int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
+		async_answer_0(iid, rc);
 	} else {
-		fibril_mutex_unlock(&vs->mode_mtx);
+		async_answer_0(callid, ENOENT);
 		async_answer_0(iid, ENOENT);
 	}
+	
+	fibril_mutex_unlock(&vs->mode_mtx);
 }
 
 static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
 {
+	ipc_callid_t callid;
+	size_t len;
+	
+	if (!async_data_read_receive(&callid, &len)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
+		return;
+	}
+	
 	fibril_mutex_lock(&vs->mode_mtx);
 	vslmode_list_element_t *mode_elem = NULL;
+	
 	list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
 		if (cur->mode.index == vs->def_mode_idx) {
@@ -327,47 +315,33 @@
 		}
 	}
-
-	vslmode_t mode;
+	
 	if (mode_elem != NULL) {
-		mode = mode_elem->mode;
-		fibril_mutex_unlock(&vs->mode_mtx);
-
-		ipc_callid_t callid;
-		size_t len;
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(iid, EINVAL);
-			return;
-		}
-		int rc = async_data_read_finalize(callid, &mode, len);
-		if (rc != EOK) {
-			async_answer_0(iid, ENOMEM);
-			return;
-		}
-		async_answer_0(iid, EOK);
+		int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
+		async_answer_0(iid, rc);
 	} else {
 		fibril_mutex_unlock(&vs->mode_mtx);
+		async_answer_0(callid, ENOENT);
 		async_answer_0(iid, ENOENT);
 	}
+	
+	fibril_mutex_unlock(&vs->mode_mtx);
 }
 
 static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
 {
+	ipc_callid_t callid;
+	size_t len;
+	
+	if (!async_data_read_receive(&callid, &len)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
+		return;
+	}
+	
 	if (vs->mode_set) {
-		ipc_callid_t callid;
-		size_t len;
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(iid, EINVAL);
-			return;
-		}
 		int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
-		if (rc != EOK) {
-			async_answer_0(iid, ENOMEM);
-			return;
-		}
-
-		async_answer_0(iid, EOK);
+		async_answer_0(iid, rc);
 	} else {
+		async_answer_0(callid, ENOENT);
 		async_answer_0(iid, ENOENT);
 	}
@@ -376,8 +350,18 @@
 static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
 {
+	ipc_callid_t callid;
+	size_t len;
+	
+	if (!async_data_read_receive(&callid, &len)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
+		return;
+	}
+	
 	sysarg_t mode_idx = IPC_GET_ARG1(*icall);
-
+	
 	fibril_mutex_lock(&vs->mode_mtx);
 	vslmode_list_element_t *mode_elem = NULL;
+	
 	list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
 		if (cur->mode.index == mode_idx) {
@@ -386,40 +370,37 @@
 		}
 	}
-
-	vslmode_t mode;
+	
 	if (mode_elem != NULL) {
-		mode = mode_elem->mode;
-		fibril_mutex_unlock(&vs->mode_mtx);
-
-		ipc_callid_t callid;
-		size_t len;
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(iid, EINVAL);
-			return;
-		}
-		int rc = async_data_read_finalize(callid, &mode, len);
-		if (rc != EOK) {
-			async_answer_0(iid, ENOMEM);
-			return;
-		}
-		async_answer_0(iid, EOK);
+		int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
+		async_answer_0(iid, rc);
 	} else {
-		fibril_mutex_unlock(&vs->mode_mtx);
+		async_answer_0(callid, ENOENT);
 		async_answer_0(iid, ENOENT);
 	}
+	
+	fibril_mutex_unlock(&vs->mode_mtx);
 }
 
 static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
 {
-	int rc = EOK;
-
+	ipc_callid_t callid;
+	size_t size;
+	unsigned int flags;
+	
+	/* Retrieve the shared cell storage for the new mode. */
+	if (!async_share_out_receive(&callid, &size, &flags)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
+		return;
+	}
+	
 	/* Retrieve mode index and version. */
 	sysarg_t mode_idx = IPC_GET_ARG1(*icall);
 	sysarg_t mode_version = IPC_GET_ARG2(*icall);
-
+	
 	/* Find mode in the list. */
 	fibril_mutex_lock(&vs->mode_mtx);
 	vslmode_list_element_t *mode_elem = NULL;
+	
 	list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
 		if (cur->mode.index == mode_idx) {
@@ -428,41 +409,33 @@
 		}
 	}
-
+	
+	if (mode_elem == NULL) {
+		fibril_mutex_unlock(&vs->mode_mtx);
+		async_answer_0(callid, ENOENT);
+		async_answer_0(iid, ENOENT);
+		return;
+	}
+	
 	/* Extract mode description from the list node. */
-	vslmode_t new_mode;
-	if (mode_elem != NULL) {
-		new_mode = mode_elem->mode;
-		fibril_mutex_unlock(&vs->mode_mtx);
-	} else {
-		fibril_mutex_unlock(&vs->mode_mtx);
-		async_answer_0(iid, ENOENT);
-		return;
-	}
-
+	vslmode_t new_mode = mode_elem->mode;
+	fibril_mutex_unlock(&vs->mode_mtx);
+	
 	/* Check whether the mode is still up-to-date. */
 	if (new_mode.version != mode_version) {
+		async_answer_0(callid, EINVAL);
 		async_answer_0(iid, EINVAL);
 		return;
 	}
-
-	ipc_callid_t callid;
-	size_t size;
-	unsigned int flags;
-
-	/* Retrieve the shared cell storage for the new mode. */
-	if (!async_share_out_receive(&callid, &size, &flags)) {
-		async_answer_0(iid, EINVAL);
-		return;
-	}
+	
 	void *new_cell_storage;
-	rc = async_share_out_finalize(callid, &new_cell_storage);
+	int rc = async_share_out_finalize(callid, &new_cell_storage);
 	if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
 		async_answer_0(iid, ENOMEM);
 		return;
 	}
-
+	
 	/* Change device internal state. */
 	rc = vs->ops.change_mode(vs, new_mode);
-
+	
 	/* Device driver could not establish new mode. Rollback. */
 	if (rc != EOK) {
@@ -471,7 +444,10 @@
 		return;
 	}
-
-	/* Because resources for the new mode were successfully claimed,
-	 * it is finally possible to free resources allocated for the old mode. */
+	
+	/*
+	 * Because resources for the new mode were successfully
+	 * claimed, it is finally possible to free resources
+	 * allocated for the old mode.
+	 */
 	if (vs->mode_set) {
 		if (vs->cells.data != NULL) {
@@ -480,5 +456,5 @@
 		}
 	}
-
+	
 	/* Insert new mode into the visualizer. */
 	vs->cells.width = new_mode.screen_width;
@@ -487,5 +463,5 @@
 	vs->cur_mode = new_mode;
 	vs->mode_set = true;
-
+	
 	async_answer_0(iid, EOK);
 }
@@ -500,9 +476,9 @@
 	sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
 #endif
-
+	
 	int rc = vs->ops.handle_damage(vs,
 	    IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
 	    IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
-		x_offset, y_offset);
+	    x_offset, y_offset);
 	async_answer_0(iid, rc);
 }
@@ -525,5 +501,5 @@
 	ipc_call_t call;
 	ipc_callid_t callid;
-
+	
 	/* Claim the visualizer. */
 	if (!cas(&vs->ref_cnt, 0, 1)) {
@@ -531,26 +507,25 @@
 		return;
 	}
-
+	
 	/* Accept the connection. */
 	async_answer_0(iid, EOK);
-
+	
 	/* Establish callback session. */
 	callid = async_get_call(&call);
 	vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
-	if (vs->notif_sess != NULL) {
+	if (vs->notif_sess != NULL)
 		async_answer_0(callid, EOK);
-	} else {
+	else
 		async_answer_0(callid, ELIMIT);
-	}
-
+	
 	/* Enter command loop. */
 	while (true) {
 		callid = async_get_call(&call);
-
+		
 		if (!IPC_GET_IMETHOD(call)) {
 			async_answer_0(callid, EINVAL);
 			break;
 		}
-
+		
 		switch (IPC_GET_IMETHOD(call)) {
 		case VISUALIZER_CLAIM:
@@ -589,5 +564,5 @@
 		}
 	}
-
+	
 terminate:
 	async_hangup(vs->notif_sess);
@@ -600,21 +575,21 @@
 {
 	// TODO
-
+	
 	ipc_call_t call;
 	ipc_callid_t callid;
-
+	
 	/* Accept the connection. */
 	atomic_inc(&rnd->ref_cnt);
 	async_answer_0(iid, EOK);
-
+	
 	/* Enter command loop. */
 	while (true) {
 		callid = async_get_call(&call);
-
+		
 		if (!IPC_GET_IMETHOD(call)) {
 			async_answer_0(callid, EINVAL);
 			break;
 		}
-
+		
 		switch (IPC_GET_IMETHOD(call)) {
 		default:
@@ -623,5 +598,5 @@
 		}
 	}
-
+	
 terminate:
 	atomic_dec(&rnd->ref_cnt);
@@ -633,12 +608,11 @@
 	visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
 	renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
-
-	if (vs != NULL) {
+	
+	if (vs != NULL)
 		graph_visualizer_connection(vs, iid, icall, arg);
-	} else if (rnd != NULL) {
+	else if (rnd != NULL)
 		graph_renderer_connection(rnd, iid, icall, arg);
-	} else {
+	else
 		async_answer_0(iid, ENOENT);
-	}
 }
 
