[clang-tidy] Do not use else after return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
diff --git a/src/afc.c b/src/afc.c
index 17273e2..d8c3db0 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -229,7 +229,9 @@
 	if (recv_len == 0) {
 		debug_info("Just didn't get enough.");
 		return AFC_E_MUX_ERROR;
-	} else if (recv_len < sizeof(AFCPacket)) {
+	}
+
+	if (recv_len < sizeof(AFCPacket)) {
 		debug_info("Did not even get the AFCPacket header");
 		return AFC_E_MUX_ERROR;
 	}
@@ -250,14 +252,14 @@
 	if (header.this_length < sizeof(AFCPacket)) {
 		debug_info("Invalid AFCPacket header received!");
 		return AFC_E_OP_HEADER_INVALID;
-	} else if ((header.this_length == header.entire_length)
-			&& header.entire_length == sizeof(AFCPacket)) {
+	}
+	if ((header.this_length == header.entire_length)
+		&& header.entire_length == sizeof(AFCPacket)) {
 		debug_info("Empty AFCPacket received!");
 		if (header.operation == AFC_OP_DATA) {
 			return AFC_E_SUCCESS;
-		} else {
-			return AFC_E_IO_ERROR;
 		}
+		return AFC_E_IO_ERROR;
 	}
 
 	debug_info("received AFC packet, full len=%lld, this len=%lld, operation=0x%llx", header.entire_length, header.this_length, header.operation);
@@ -273,7 +275,8 @@
 			free(buf);
 			debug_info("Did not get packet contents!");
 			return AFC_E_NOT_ENOUGH_DATA;
-		} else if (recv_len < this_len) {
+		}
+		if (recv_len < this_len) {
 			free(buf);
 			debug_info("Could not receive this_len=%d bytes", this_len);
 			return AFC_E_NOT_ENOUGH_DATA;
@@ -749,22 +752,23 @@
 	if (ret != AFC_E_SUCCESS) {
 		afc_unlock(client);
 		return ret;
-	} else if (bytes_loc == 0) {
+	}
+	if (bytes_loc == 0) {
 		if (input)
 			free(input);
 		afc_unlock(client);
 		*bytes_read = current_count;
 		/* FIXME: check that's actually a success */
 		return ret;
-	} else {
-		if (input) {
-			debug_info("%d", bytes_loc);
-			memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
-			free(input);
-			input = NULL;
-			current_count += (bytes_loc > length) ? length : bytes_loc;
-		}
 	}
+	if (input) {
+		debug_info("%d", bytes_loc);
+		memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
+		free(input);
+		input = NULL;
+		current_count += (bytes_loc > length) ? length : bytes_loc;
+	}
+
 	afc_unlock(client);
 	*bytes_read = current_count;
 	return ret;
diff --git a/src/idevice.c b/src/idevice.c
index f64570b..adf47f4 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -473,7 +473,8 @@
 		new_connection->status = IDEVICE_E_SUCCESS;
 		*connection = new_connection;
 		return IDEVICE_E_SUCCESS;
-	} else if (device->conn_type == CONNECTION_NETWORK) {
+	}
+	if (device->conn_type == CONNECTION_NETWORK) {
 		struct sockaddr_storage saddr_storage;
 		struct sockaddr* saddr = (struct sockaddr*)&saddr_storage;
 
@@ -529,10 +530,9 @@
 		*connection = new_connection;
 
 		return IDEVICE_E_SUCCESS;
-	} else {
-		debug_info("Unknown connection type %d", device->conn_type);
 	}
 
+	debug_info("Unknown connection type %d", device->conn_type);
 	return IDEVICE_E_UNKNOWN_ERROR;
 }
 
@@ -583,7 +583,8 @@
 			return IDEVICE_E_UNKNOWN_ERROR;
 		}
 		return IDEVICE_E_SUCCESS;
-	} else if (connection->type == CONNECTION_NETWORK) {
+	}
+	if (connection->type == CONNECTION_NETWORK) {
 		int s = socket_send((int)(long)connection->data, (void*)data, len);
 		if (s < 0) {
 			*sent_bytes = 0;
@@ -591,9 +592,9 @@
 		}
 		*sent_bytes = s;
 		return IDEVICE_E_SUCCESS;
-	} else {
-		debug_info("Unknown connection type %d", connection->type);
 	}
+
+	debug_info("Unknown connection type %d", connection->type);
 	return IDEVICE_E_UNKNOWN_ERROR;
 
 }
@@ -638,27 +639,26 @@
 		}
 		*sent_bytes = sent;
 		return IDEVICE_E_SUCCESS;
-	} else {
-		uint32_t sent = 0;
-		while (sent < len) {
-			uint32_t bytes = 0;
-			int s = internal_connection_send(connection, data+sent, len-sent, &bytes);
-			if (s < 0) {
-				break;
-			}
-			sent += bytes;
-		}
-		debug_info("len %d, sent %d", len, sent);
-		if (sent < len) {
-			*sent_bytes = sent;
-			if (sent == 0) {
-				return IDEVICE_E_UNKNOWN_ERROR;
-			}
-			return IDEVICE_E_NOT_ENOUGH_DATA;
-		}
-		*sent_bytes = sent;
-		return IDEVICE_E_SUCCESS;
 	}
+	uint32_t sent = 0;
+	while (sent < len) {
+		uint32_t bytes = 0;
+		int s = internal_connection_send(connection, data+sent, len-sent, &bytes);
+		if (s < 0) {
+			break;
+		}
+		sent += bytes;
+	}
+	debug_info("internal_connection_send %d, sent %d", len, sent);
+	if (sent < len) {
+		*sent_bytes = sent;
+		if (sent == 0) {
+			return IDEVICE_E_UNKNOWN_ERROR;
+		}
+		return IDEVICE_E_NOT_ENOUGH_DATA;
+	}
+	*sent_bytes = sent;
+	return IDEVICE_E_SUCCESS;
 }
 
 static inline idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received)
@@ -698,7 +698,8 @@
 			debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error));
 		}
 		return error;
-	} else if (connection->type == CONNECTION_NETWORK) {
+	}
+	if (connection->type == CONNECTION_NETWORK) {
 		int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout);
 		idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0);
 		if (error == IDEVICE_E_SUCCESS) {
@@ -707,9 +708,9 @@
 			debug_info("ERROR: socket_receive_timeout returned %d (%s)", res, strerror(-res));
 		}
 		return error;
-	} else {
-		debug_info("Unknown connection type %d", connection->type);
 	}
+
+	debug_info("Unknown connection type %d", connection->type);
 	return IDEVICE_E_UNKNOWN_ERROR;
 }
 
@@ -793,7 +794,8 @@
 			return IDEVICE_E_UNKNOWN_ERROR;
 		}
 		return IDEVICE_E_SUCCESS;
-	} else if (connection->type == CONNECTION_NETWORK) {
+	}
+	if (connection->type == CONNECTION_NETWORK) {
 		int res = socket_receive((int)(long)connection->data, data, len);
 		if (res < 0) {
 			debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res));
@@ -801,9 +803,9 @@
 		}
 		*recv_bytes = (uint32_t)res;
 		return IDEVICE_E_SUCCESS;
-	} else {
-		debug_info("Unknown connection type %d", connection->type);
 	}
+
+	debug_info("Unknown connection type %d", connection->type);
 	return IDEVICE_E_UNKNOWN_ERROR;
 }
 
@@ -846,17 +848,17 @@
 		return IDEVICE_E_INVALID_ARG;
 	}
 
-	idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR;
 	if (connection->type == CONNECTION_USBMUXD) {
 		*fd = (int)(long)connection->data;
-		result = IDEVICE_E_SUCCESS;
-	} else if (connection->type == CONNECTION_NETWORK) {
-		*fd = (int)(long)connection->data;
-		result = IDEVICE_E_SUCCESS;
-	} else {
-		debug_info("Unknown connection type %d", connection->type);
+		return IDEVICE_E_SUCCESS;
 	}
-	return result;
+	if (connection->type == CONNECTION_NETWORK) {
+		*fd = (int)(long)connection->data;
+		return IDEVICE_E_SUCCESS;
+	}
+
+	debug_info("Unknown connection type %d", connection->type);
+	return IDEVICE_E_UNKNOWN_ERROR;
 }
 
 LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)
diff --git a/src/lockdown.c b/src/lockdown.c
index 25e8c87..d0922dd 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -163,22 +163,22 @@
 
 	if (plist_get_node_type(query_node) != PLIST_STRING) {
 		return ret;
-	} else {
-		char *query_value = NULL;
-
-		plist_get_string_val(query_node, &query_value);
-		if (!query_value) {
-			return ret;
-		}
-
-		if (query_match && (strcmp(query_value, query_match) != 0)) {
-			free(query_value);
-			return ret;
-		}
-
-		free(query_value);
 	}
 
+	char *query_value = NULL;
+
+	plist_get_string_val(query_node, &query_value);
+	if (!query_value) {
+		return ret;
+	}
+
+	if (query_match && (strcmp(query_value, query_match) != 0)) {
+		free(query_value);
+		return ret;
+	}
+
+	free(query_value);
+
 	plist_t result_node = plist_dict_get_item(dict, "Result");
 	if (!result_node) {
 		/* iOS 5: the 'Result' key is not present anymore.
diff --git a/src/misagent.c b/src/misagent.c
index d790a05..af925f9 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -85,9 +85,8 @@
 	*status_code = (int)(val & 0xFFFFFFFF);
 	if (*status_code == 0) {
 		return MISAGENT_E_SUCCESS;
-	} else {
-		return MISAGENT_E_REQUEST_FAILED;
 	}
+	return MISAGENT_E_REQUEST_FAILED;
 }
 
 LIBIMOBILEDEVICE_API misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)
diff --git a/src/mobileactivation.c b/src/mobileactivation.c
index 2de4333..79c7003 100644
--- a/src/mobileactivation.c
+++ b/src/mobileactivation.c
@@ -109,8 +109,6 @@
 
 static mobileactivation_error_t mobileactivation_check_result(plist_t dict, const char *command)
 {
-	mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR;
-
 	if (!dict || plist_get_node_type(dict) != PLIST_DICT) {
 		return MOBILEACTIVATION_E_PLIST_ERROR;
 	}
@@ -118,14 +116,13 @@
 	plist_t err_node = plist_dict_get_item(dict, "Error");
 	if (!err_node) {
 		return MOBILEACTIVATION_E_SUCCESS;
-	} else {
-		char *errmsg = NULL;
-		plist_get_string_val(err_node, &errmsg);
-		debug_info("ERROR: %s: %s", command, errmsg);
-		ret = MOBILEACTIVATION_E_REQUEST_FAILED;
-		free(errmsg);
 	}
-	return ret;
+
+	char *errmsg = NULL;
+	plist_get_string_val(err_node, &errmsg);
+	debug_info("ERROR: %s: %s", command, errmsg);
+	free(errmsg);
+	return MOBILEACTIVATION_E_REQUEST_FAILED;
 }
 
 static mobileactivation_error_t mobileactivation_send_command_plist(mobileactivation_client_t client, plist_t command, plist_t *result)
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index f4fde95..3726065 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -240,9 +240,8 @@
 	if (sent > 0) {
 		*bytes = sent;
 		return MOBILEBACKUP2_E_SUCCESS;
-	} else {
-		return MOBILEBACKUP2_E_MUX_ERROR;
 	}
+	return MOBILEBACKUP2_E_MUX_ERROR;
 }
 
 LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes)
@@ -265,11 +264,11 @@
 	if (received > 0) {
 		*bytes = received;
 		return MOBILEBACKUP2_E_SUCCESS;
-	} else if (received == 0) {
-		return MOBILEBACKUP2_E_SUCCESS;
-	} else {
-		return MOBILEBACKUP2_E_MUX_ERROR;
 	}
+	if (received == 0) {
+		return MOBILEBACKUP2_E_SUCCESS;
+	}
+	return MOBILEBACKUP2_E_MUX_ERROR;
 }
 
 LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version)
diff --git a/src/preboard.c b/src/preboard.c
index b975f0e..4b3b444 100644
--- a/src/preboard.c
+++ b/src/preboard.c
@@ -162,7 +162,8 @@
 		preboard_error_t perr = preboard_receive_with_timeout(data->client, &pl, 1000);
 		if (perr == PREBOARD_E_TIMEOUT) {
 			continue;
-		} else if (perr == PREBOARD_E_SUCCESS) {
+		}
+		if (perr == PREBOARD_E_SUCCESS) {
 			data->cbfunc(pl, data->user_data);
 		}
 		plist_free(pl);
diff --git a/src/restore.c b/src/restore.c
index 4e9d65a..591fd16 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -268,29 +268,27 @@
 
 LIBIMOBILEDEVICE_API restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value)
 {
+	plist_t item;
+
 	if (!client || !value || (value && *value))
 		return RESTORE_E_INVALID_ARG;
 
 	if (!client->info)
 		return RESTORE_E_NOT_ENOUGH_DATA;
 
-	restored_error_t ret = RESTORE_E_SUCCESS;
-	plist_t item = NULL;
-
 	if (!key) {
 		*value = plist_copy(client->info);
 		return RESTORE_E_SUCCESS;
-	} else {
-		item = plist_dict_get_item(client->info, key);
 	}
 
-	if (item) {
-		*value = plist_copy(item);
-	} else {
-		ret = RESTORE_E_PLIST_ERROR;
+	item = plist_dict_get_item(client->info, key);
+	if (!item) {
+		return RESTORE_E_PLIST_ERROR;
 	}
 
-	return ret;
+	*value = plist_copy(item);
+	free(item);
+	return RESTORE_E_SUCCESS;
 }
 
 LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label)
diff --git a/src/syslog_relay.c b/src/syslog_relay.c
index c137297..ec9eca5 100644
--- a/src/syslog_relay.c
+++ b/src/syslog_relay.c
@@ -154,16 +154,15 @@
 		ret = syslog_relay_receive_with_timeout(srwt->client, &c, 1, &bytes, 100);
 		if (ret == SYSLOG_RELAY_E_TIMEOUT || ret == SYSLOG_RELAY_E_NOT_ENOUGH_DATA || ((bytes == 0) && (ret == SYSLOG_RELAY_E_SUCCESS))) {
 			continue;
-		} else if (ret < 0) {
+		}
+		if (ret < 0) {
 			debug_info("Connection to syslog relay interrupted");
 			break;
 		}
 		if (srwt->is_raw) {
 			srwt->cbfunc(c, srwt->user_data);
-		} else {
-			if (c != 0) {
-				srwt->cbfunc(c, srwt->user_data);
-			}
+		} else if (c != 0) {
+			srwt->cbfunc(c, srwt->user_data);
 		}
 	}
 
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 0affd7a..2856fda 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -926,15 +926,16 @@
 				if (aerr == AFC_E_SUCCESS) {
 					do_post_notification(NP_SYNC_DID_START);
 					break;
-				} else if (aerr == AFC_E_OP_WOULD_BLOCK) {
+				}
+				if (aerr == AFC_E_OP_WOULD_BLOCK) {
 					usleep(LOCK_WAIT);
 					continue;
-				} else {
-					fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
-					afc_file_close(afc, lockfile);
-					lockfile = 0;
-					cmd = CMD_LEAVE;
 				}
+
+				fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
+				afc_file_close(afc, lockfile);
+				lockfile = 0;
+				cmd = CMD_LEAVE;
 			}
 			if (i == LOCK_ATTEMPTS) {
 				fprintf(stderr, "ERROR: timeout while locking for sync\n");
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index d1ef0d6..ec7eacd 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -184,9 +184,8 @@
 	if (!dir) return -1;
 	if (__mkdir(dir, mode) == 0) {
 		return 0;
-	} else {
-		if (errno == EEXIST) return 0;
 	}
+	if (errno == EEXIST) return 0;
 	int res;
 	char *parent = strdup(dir);
 	char *parentdir = dirname(parent);
@@ -973,10 +972,12 @@
 		if ((nlen == 0) && (rlen == 4)) {
 			// a zero length means no more files to receive
 			return 0;
-		} else if(rlen == 0) {
+		}
+		if (rlen == 0) {
 			// device needs more time, waiting...
 			continue;
-		} else if (nlen > 4096) {
+		}
+		if (nlen > 4096) {
 			// filename length is too large
 			printf("ERROR: %s: too large filename length (%d)!\n", __func__, nlen);
 			return 0;
@@ -1368,7 +1369,8 @@
 	while ((c = my_getch())) {
 		if ((c == '\r') || (c == '\n')) {
 			break;
-		} else if (isprint(c)) {
+		}
+		if (isprint(c)) {
 			if (pwlen < maxlen-1)
 				buf[pwlen++] = c;
 			fputc('*', stderr);
@@ -1961,15 +1963,16 @@
 				if (aerr == AFC_E_SUCCESS) {
 					do_post_notification(device, NP_SYNC_DID_START);
 					break;
-				} else if (aerr == AFC_E_OP_WOULD_BLOCK) {
+				}
+				if (aerr == AFC_E_OP_WOULD_BLOCK) {
 					usleep(LOCK_WAIT);
 					continue;
-				} else {
-					fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
-					afc_file_close(afc, lockfile);
-					lockfile = 0;
-					cmd = CMD_LEAVE;
 				}
+
+				fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
+				afc_file_close(afc, lockfile);
+				lockfile = 0;
+				cmd = CMD_LEAVE;
 			}
 			if (i == LOCK_ATTEMPTS) {
 				fprintf(stderr, "ERROR: timeout while locking for sync\n");
@@ -2103,9 +2106,8 @@
 				if (write_restore_applications(info_plist, afc) < 0) {
 					cmd = CMD_LEAVE;
 					break;
-				} else {
-					PRINT_VERBOSE(1, "Wrote RestoreApplications.plist\n");
 				}
+				PRINT_VERBOSE(1, "Wrote RestoreApplications.plist\n");
 			}
 
 			/* Start restore */
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c
index 48bda3a..d0d2147 100644
--- a/tools/idevicecrashreport.c
+++ b/tools/idevicecrashreport.c
@@ -475,10 +475,10 @@
 		if (service_error == SERVICE_E_SUCCESS || service_error == SERVICE_E_TIMEOUT) {
 			attempts++;
 			continue;
-		} else {
-			fprintf(stderr, "ERROR: Crash logs could not be moved. Connection interrupted (%d).\n", service_error);
-			break;
 		}
+
+		fprintf(stderr, "ERROR: Crash logs could not be moved. Connection interrupted (%d).\n", service_error);
+		break;
 	}
 	service_client_free(svcmove);
 	free(ping);
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c
index 981a7ee..7cd4f3f 100644
--- a/tools/ideviceprovision.c
+++ b/tools/ideviceprovision.c
@@ -448,7 +448,9 @@
 		plist_free(pl);
 
 		return res;
-	} else if (op == OP_COPY) {
+	}
+
+	if (op == OP_COPY) {
 		struct stat st;
 		const char *checkdir = (param2) ? param2 : param;
 		if ((stat(checkdir, &st) < 0) || !S_ISDIR(st.st_mode)) {
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 2a72d72..f85c7cc 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -151,7 +151,9 @@
 				shall_print = 1;
 				cprintf(COLOR_WHITE);
 				break;
-			} else if (line[3] == ' ' && line[6] == ' ' && line[15] == ' ') {
+			}
+
+			if (line[3] == ' ' && line[6] == ' ' && line[15] == ' ') {
 				char* end = &line[lp];
 				char* p = &line[16];
 
@@ -190,10 +192,9 @@
 					if (!found) {
 						shall_print = 0;
 						break;
-					} else {
-						triggered = 1;
-						shall_print = 1;
 					}
+					triggered = 1;
+					shall_print = 1;
 				} else if (num_trigger_filters == 0 && num_untrigger_filters > 0 && !triggered) {
 					shall_print = 0;
 					quit_flag++;
@@ -213,9 +214,8 @@
 					if (!found) {
 						shall_print = 0;
 						break;
-					} else {
-						shall_print = 1;
 					}
+					shall_print = 1;
 				}
 
 				/* process name */
@@ -430,7 +430,8 @@
 {
 	if (use_network && event->conn_type != CONNECTION_NETWORK) {
 		return;
-	} else if (!use_network && event->conn_type != CONNECTION_USBMUXD) {
+	}
+	if (!use_network && event->conn_type != CONNECTION_USBMUXD) {
 		return;
 	}
 	if (event->event == IDEVICE_DEVICE_ADD) {
@@ -656,7 +657,8 @@
 		fprintf(stderr, "ERROR: -p and -e/-q cannot be used together.\n");
 		print_usage(argc, argv, 1);
 		return 2;
-	} else if (include_filter > 0 && exclude_kernel > 0) {
+	}
+	if (include_filter > 0 && exclude_kernel > 0) {
 		fprintf(stderr, "ERROR: -p and -K cannot be used together.\n");
 		print_usage(argc, argv, 1);
 		return 2;
@@ -699,9 +701,9 @@
 		if (!udid) {
 			fprintf(stderr, "No device found. Plug in a device or pass UDID with -u to wait for device to be available.\n");
 			return -1;
-		} else {
-			fprintf(stderr, "Waiting for device with UDID %s to become available...\n", udid);
 		}
+
+		fprintf(stderr, "Waiting for device with UDID %s to become available...\n", udid);
 	}
 
 	line_buffer_size = 1024;