Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision bf31e3f1ebd6e88e0c8425f109e42ccd92b6c9b3)
+++ uspace/lib/drv/generic/driver.c	(revision e6a78b92c73a6d50e0688a60ed8c28a6022f5aa2)
@@ -125,19 +125,17 @@
 static void driver_dev_add(ipc_callid_t iid, ipc_call_t *icall)
 {
-	char *dev_name = NULL;
-	int res;
-	
 	devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
 	devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
 	
 	ddf_dev_t *dev = create_device();
-
+	
 	/* Add one reference that will be dropped by driver_dev_remove() */
 	dev_add_ref(dev);
 	dev->handle = dev_handle;
-
+	
+	char *dev_name = NULL;
 	async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
 	dev->name = dev_name;
-
+	
 	/*
 	 * Currently not used, parent fun handle is stored in context
@@ -146,5 +144,5 @@
 	(void) parent_fun_handle;
 	
-	res = driver->driver_ops->dev_add(dev);
+	int res = driver->driver_ops->dev_add(dev);
 	
 	if (res != EOK) {
@@ -163,12 +161,8 @@
 static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall)
 {
-	devman_handle_t devh;
-	ddf_dev_t *dev;
-	int rc;
-	
-	devh = IPC_GET_ARG1(*icall);
+	devman_handle_t devh = IPC_GET_ARG1(*icall);
 	
 	fibril_mutex_lock(&devices_mutex);
-	dev = driver_get_device(devh);
+	ddf_dev_t *dev = driver_get_device(devh);
 	if (dev != NULL)
 		dev_add_ref(dev);
@@ -179,4 +173,6 @@
 		return;
 	}
+	
+	int rc;
 	
 	if (driver->driver_ops->dev_remove != NULL)
@@ -193,12 +189,8 @@
 static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall)
 {
-	devman_handle_t devh;
-	ddf_dev_t *dev;
-	int rc;
-	
-	devh = IPC_GET_ARG1(*icall);
+	devman_handle_t devh = IPC_GET_ARG1(*icall);
 	
 	fibril_mutex_lock(&devices_mutex);
-	dev = driver_get_device(devh);
+	ddf_dev_t *dev = driver_get_device(devh);
 	if (dev != NULL)
 		dev_add_ref(dev);
@@ -209,4 +201,6 @@
 		return;
 	}
+	
+	int rc;
 	
 	if (driver->driver_ops->dev_gone != NULL)
@@ -223,9 +217,5 @@
 static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall)
 {
-	devman_handle_t funh;
-	ddf_fun_t *fun;
-	int rc;
-	
-	funh = IPC_GET_ARG1(*icall);
+	devman_handle_t funh = IPC_GET_ARG1(*icall);
 	
 	/*
@@ -236,5 +226,5 @@
 	fibril_mutex_lock(&functions_mutex);
 	
-	fun = driver_get_function(funh);
+	ddf_fun_t *fun = driver_get_function(funh);
 	if (fun != NULL)
 		fun_add_ref(fun);
@@ -248,4 +238,6 @@
 	
 	/* Call driver entry point */
+	int rc;
+	
 	if (driver->driver_ops->fun_online != NULL)
 		rc = driver->driver_ops->fun_online(fun);
@@ -260,9 +252,5 @@
 static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall)
 {
-	devman_handle_t funh;
-	ddf_fun_t *fun;
-	int rc;
-	
-	funh = IPC_GET_ARG1(*icall);
+	devman_handle_t funh = IPC_GET_ARG1(*icall);
 	
 	/*
@@ -273,5 +261,5 @@
 	fibril_mutex_lock(&functions_mutex);
 	
-	fun = driver_get_function(funh);
+	ddf_fun_t *fun = driver_get_function(funh);
 	if (fun != NULL)
 		fun_add_ref(fun);
@@ -285,4 +273,6 @@
 	
 	/* Call driver entry point */
+	int rc;
+	
 	if (driver->driver_ops->fun_offline != NULL)
 		rc = driver->driver_ops->fun_offline(fun);
@@ -597,12 +587,10 @@
 void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
 {
-	void *data;
-
 	assert(dev->driver_data == NULL);
-
-	data = calloc(1, size);
+	
+	void *data = calloc(1, size);
 	if (data == NULL)
 		return NULL;
-
+	
 	dev->driver_data = data;
 	return data;
@@ -634,17 +622,15 @@
 ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
 {
-	ddf_fun_t *fun;
-
-	fun = create_function();
+	ddf_fun_t *fun = create_function();
 	if (fun == NULL)
 		return NULL;
-
+	
 	/* Add one reference that will be dropped by ddf_fun_destroy() */
 	fun->dev = dev;
 	fun_add_ref(fun);
-
+	
 	fun->bound = false;
 	fun->ftype = ftype;
-
+	
 	fun->name = str_dup(name);
 	if (fun->name == NULL) {
@@ -652,5 +638,5 @@
 		return NULL;
 	}
-
+	
 	return fun;
 }
@@ -659,13 +645,11 @@
 void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
 {
-	void *data;
-
 	assert(fun->bound == false);
 	assert(fun->driver_data == NULL);
-
-	data = calloc(1, size);
+	
+	void *data = calloc(1, size);
 	if (data == NULL)
 		return NULL;
-
+	
 	fun->driver_data = data;
 	return data;
@@ -677,10 +661,11 @@
  * must not be bound.
  *
- * @param fun		Function to destroy
+ * @param fun Function to destroy
+ *
  */
 void ddf_fun_destroy(ddf_fun_t *fun)
 {
 	assert(fun->bound == false);
-
+	
 	/*
 	 * Drop the reference added by ddf_fun_create(). This will deallocate
@@ -697,4 +682,5 @@
 	if (fun->ops == NULL)
 		return NULL;
+	
 	return fun->ops->interfaces[idx];
 }
@@ -709,6 +695,8 @@
  * the same name.
  *
- * @param fun		Function to bind
- * @return		EOK on success or negative error code
+ * @param fun Function to bind
+ *
+ * @return EOK on success or negative error code
+ *
  */
 int ddf_fun_bind(ddf_fun_t *fun)
@@ -717,8 +705,6 @@
 	assert(fun->name != NULL);
 	
-	int res;
-	
 	add_to_functions_list(fun);
-	res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
+	int res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
 	    fun->dev->handle, &fun->handle);
 	if (res != EOK) {
@@ -736,17 +722,17 @@
  * the function invisible to the system.
  *
- * @param fun		Function to unbind
- * @return		EOK on success or negative error code
+ * @param fun Function to unbind
+ *
+ * @return EOK on success or negative error code
+ *
  */
 int ddf_fun_unbind(ddf_fun_t *fun)
 {
-	int res;
-	
 	assert(fun->bound == true);
 	
-	res = devman_remove_function(fun->handle);
+	int res = devman_remove_function(fun->handle);
 	if (res != EOK)
 		return res;
-
+	
 	remove_from_functions_list(fun);
 	
@@ -757,14 +743,14 @@
 /** Online function.
  *
- * @param fun		Function to online
- * @return		EOK on success or negative error code
+ * @param fun Function to online
+ *
+ * @return EOK on success or negative error code
+ *
  */
 int ddf_fun_online(ddf_fun_t *fun)
 {
-	int res;
-	
 	assert(fun->bound == true);
 	
-	res = devman_drv_fun_online(fun->handle);
+	int res = devman_drv_fun_online(fun->handle);
 	if (res != EOK)
 		return res;
@@ -775,14 +761,14 @@
 /** Offline function.
  *
- * @param fun		Function to offline
- * @return		EOK on success or negative error code
+ * @param fun Function to offline
+ *
+ * @return EOK on success or negative error code
+ *
  */
 int ddf_fun_offline(ddf_fun_t *fun)
 {
-	int res;
-	
 	assert(fun->bound == true);
 	
-	res = devman_drv_fun_offline(fun->handle);
+	int res = devman_drv_fun_offline(fun->handle);
 	if (res != EOK)
 		return res;
@@ -796,18 +782,19 @@
  * Cannot be called when the function node is bound.
  *
- * @param fun			Function
- * @param match_id_str		Match string
- * @param match_score		Match score
- * @return			EOK on success, ENOMEM if out of memory.
+ * @param fun          Function
+ * @param match_id_str Match string
+ * @param match_score  Match score
+ *
+ * @return EOK on success.
+ * @return ENOMEM if out of memory.
+ *
  */
 int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
     int match_score)
 {
-	match_id_t *match_id;
-	
 	assert(fun->bound == false);
 	assert(fun->ftype == fun_inner);
 	
-	match_id = create_match_id();
+	match_id_t *match_id = create_match_id();
 	if (match_id == NULL)
 		return ENOMEM;
@@ -831,4 +818,5 @@
  *
  * Must only be called when the function is bound.
+ *
  */
 int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
@@ -842,6 +830,4 @@
 int ddf_driver_main(driver_t *drv)
 {
-	int rc;
-
 	/*
 	 * Remember the driver structure - driver_ops will be called by generic
@@ -858,5 +844,5 @@
 	 */
 	async_set_client_connection(driver_connection);
-	rc = devman_driver_register(driver->name);
+	int rc = devman_driver_register(driver->name);
 	if (rc != EOK) {
 		printf("Error: Failed to register driver with device manager "
@@ -864,5 +850,5 @@
 		    str_error(rc));
 		
-		return 1;
+		return rc;
 	}
 	
@@ -870,10 +856,10 @@
 	rc = task_retval(0);
 	if (rc != EOK)
-		return 1;
-
+		return rc;
+	
 	async_manager();
 	
 	/* Never reached. */
-	return 0;
+	return EOK;
 }
 
