[PATCH 12/14] Cleanup: consistently check return value of iostream functions

Dirk Hohndel dirk at hohndel.org
Wed Jan 3 11:35:15 PST 2018


Coverity CID 215197
Coverity CID 215200

Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
 src/citizen_aqualand.c  | 12 ++++++++++--
 src/hw_ostc.c           | 14 ++++++++++++--
 src/oceanic_atom2.c     | 12 ++++++++++--
 src/oceanic_vtpro.c     | 10 +++++++---
 src/reefnet_sensuspro.c | 12 ++++++++++--
 src/suunto_d9.c         | 12 ++++++++++--
 src/suunto_solution.c   |  6 +++++-
 src/suunto_vyper.c      | 12 ++++++++++--
 src/suunto_vyper2.c     | 24 ++++++++++++++++++++----
 9 files changed, 94 insertions(+), 20 deletions(-)

diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c
index f639efdd9566..7510000b49fc 100644
--- a/src/citizen_aqualand.c
+++ b/src/citizen_aqualand.c
@@ -155,7 +155,11 @@ citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	// Erase the current contents of the buffer
 	dc_buffer_clear (buffer);
 
-	dc_iostream_set_dtr (device->iostream, 1);
+	status = dc_iostream_set_dtr (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set the DTR line.");
+		return status;
+	}
 
 	// Send the init byte.
 	const unsigned char init[] = {0x7F};
@@ -200,7 +204,11 @@ citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 			break;
 	}
 
-	dc_iostream_set_dtr (device->iostream, 0);
+	status = dc_iostream_set_dtr (device->iostream, 0);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to clear the DTR line.");
+		return status;
+	}
 
 	return DC_STATUS_SUCCESS;
 }
diff --git a/src/hw_ostc.c b/src/hw_ostc.c
index ed81fdf293df..05d511850e47 100644
--- a/src/hw_ostc.c
+++ b/src/hw_ostc.c
@@ -902,7 +902,12 @@ hw_ostc_device_fwupdate (dc_device_t *abstract, const char *filename)
 	// bootloader needs to be send repeatedly, until the response packet is
 	// received. Thus the time between each two attempts is directly controlled
 	// by the timeout value.
-	dc_iostream_set_timeout (device->iostream, 300);
+	rc = dc_iostream_set_timeout (device->iostream, 300);
+	if (rc != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to set the timeout.");
+		free (firmware);
+		return rc;
+	}
 
 	// Setup the bootloader.
 	const unsigned int baudrates[] = {19200, 115200};
@@ -928,7 +933,12 @@ hw_ostc_device_fwupdate (dc_device_t *abstract, const char *filename)
 	}
 
 	// Increase the timeout again.
-	dc_iostream_set_timeout (device->iostream, 1000);
+	rc = dc_iostream_set_timeout (device->iostream, 1000);
+	if (rc != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to set the timeout.");
+		free (firmware);
+		return rc;
+	}
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c
index 77c8e9d54fdd..77b946ae44bf 100644
--- a/src/oceanic_atom2.c
+++ b/src/oceanic_atom2.c
@@ -630,8 +630,16 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
 	dc_iostream_sleep (device->iostream, 100);
 
 	// Set the DTR/RTS lines.
-	dc_iostream_set_dtr(device->iostream, 1);
-	dc_iostream_set_rts(device->iostream, 1);
+	status = dc_iostream_set_dtr(device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to set the DTR line.");
+		return status;
+	}
+	status = dc_iostream_set_rts(device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to set the DTR line.");
+		return status;
+	}
 
 	// Make sure everything is in a sane state.
 	dc_iostream_purge (device->iostream, DC_DIRECTION_ALL);
diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c
index cdb8943930b7..1ae4d4a79f04 100644
--- a/src/oceanic_vtpro.c
+++ b/src/oceanic_vtpro.c
@@ -269,9 +269,13 @@ oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
 	// device needs approximately 6 seconds to respond.
 	unsigned char answer[2] = {0};
 	unsigned char command[2] = {0x18, 0x00};
-	dc_iostream_set_timeout (device->iostream, 9000);
-	dc_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
-	dc_iostream_set_timeout (device->iostream, 3000);
+	dc_status_t rc = dc_iostream_set_timeout (device->iostream, 9000);
+	if (rc != DC_STATUS_SUCCESS)
+		return rc;
+	rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
+	if (rc != DC_STATUS_SUCCESS)
+		return rc;
+	rc = dc_iostream_set_timeout (device->iostream, 3000);
 	if (rc != DC_STATUS_SUCCESS)
 		return rc;
 
diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c
index 88c165028f12..2aee3ec40b29 100644
--- a/src/reefnet_sensuspro.c
+++ b/src/reefnet_sensuspro.c
@@ -182,7 +182,11 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
 	dc_device_t *abstract = (dc_device_t *) device;
 
 	// Assert a break condition.
-	dc_iostream_set_break (device->iostream, 1);
+	status = dc_iostream_set_break (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set break.");
+		return status;
+	}
 
 	// Receive the handshake from the dive computer.
 	unsigned char handshake[SZ_HANDSHAKE + 2] = {0};
@@ -193,7 +197,11 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
 	}
 
 	// Clear the break condition again.
-	dc_iostream_set_break (device->iostream, 0);
+	status = dc_iostream_set_break (device->iostream, 0);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to clear break.");
+		return status;
+	}
 
 	// Verify the checksum of the handshake packet.
 	unsigned short crc = array_uint16_le (handshake + SZ_HANDSHAKE);
diff --git a/src/suunto_d9.c b/src/suunto_d9.c
index 2c92a49c2a76..8c2834c8c799 100644
--- a/src/suunto_d9.c
+++ b/src/suunto_d9.c
@@ -240,7 +240,11 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
 		return DC_STATUS_CANCELLED;
 
 	// Clear RTS to send the command.
-	dc_iostream_set_rts (device->iostream, 0);
+	status = dc_iostream_set_rts (device->iostream, 0);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to clear RTS.");
+		return status;
+	}
 
 	// Send the command to the dive computer.
 	status = dc_iostream_write (device->iostream, command, csize, NULL);
@@ -265,7 +269,11 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
 	}
 
 	// Set RTS to receive the reply.
-	dc_iostream_set_rts (device->iostream, 1);
+	status = dc_iostream_set_rts (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set RTS.");
+		return status;
+	}
 
 	// Receive the answer of the dive computer.
 	status = dc_iostream_read (device->iostream, answer, asize, NULL);
diff --git a/src/suunto_solution.c b/src/suunto_solution.c
index bbeaf8e90132..7242eed5f2cf 100644
--- a/src/suunto_solution.c
+++ b/src/suunto_solution.c
@@ -162,7 +162,11 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	unsigned char answer[3] = {0};
 
 	// Assert DTR
-	dc_iostream_set_dtr (device->iostream, 1);
+	status = dc_iostream_set_dtr(device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set the DTR line.");
+		return status;
+	}
 
 	// Send: 0xFF
 	command[0] = 0xFF;
diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c
index 586a01716dfd..c82226b7ee91 100644
--- a/src/suunto_vyper.c
+++ b/src/suunto_vyper.c
@@ -178,7 +178,11 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[],
 	dc_iostream_sleep (device->iostream, 500);
 
 	// Set RTS to send the command.
-	dc_iostream_set_rts (device->iostream, 1);
+	status = dc_iostream_set_rts (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set RTS.");
+		return status;
+	}
 
 	// Send the command to the dive computer.
 	status = dc_iostream_write (device->iostream, command, csize, NULL);
@@ -202,7 +206,11 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[],
 	dc_iostream_purge (device->iostream, DC_DIRECTION_INPUT);
 
 	// Clear RTS to receive the reply.
-	dc_iostream_set_rts (device->iostream, 0);
+	status = dc_iostream_set_rts (device->iostream, 0);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to clear RTS.");
+		return status;
+	}
 
 	return DC_STATUS_SUCCESS;
 }
diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c
index 6ddd3d7a7f42..25918784d2ee 100644
--- a/src/suunto_vyper2.c
+++ b/src/suunto_vyper2.c
@@ -127,10 +127,18 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
 	dc_iostream_sleep (device->iostream, 100);
 
 	// Make sure everything is in a sane state.
-	dc_iostream_purge (device->iostream, DC_DIRECTION_ALL);
+	status = dc_iostream_purge (device->iostream, DC_DIRECTION_ALL);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to reset IO state.");
+		goto error_close;
+	}
 
 	// Enable half-duplex emulation.
-	dc_iostream_set_halfduplex (device->iostream, 1);
+	status = dc_iostream_set_halfduplex (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to set half duplex.");
+		goto error_close;
+	}
 
 	// Read the version info.
 	status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
@@ -187,7 +195,11 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
 	dc_iostream_sleep (device->iostream, 600);
 
 	// Set RTS to send the command.
-	dc_iostream_set_rts (device->iostream, 1);
+	status = dc_iostream_set_rts (device->iostream, 1);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set the RTS line.");
+		return status;
+	}
 
 	// Send the command to the dive computer.
 	status = dc_iostream_write (device->iostream, command, csize, NULL);
@@ -197,7 +209,11 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
 	}
 
 	// Clear RTS to receive the reply.
-	dc_iostream_set_rts (device->iostream, 0);
+	status = dc_iostream_set_rts (device->iostream, 0);
+	if (status != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to set the RTS line.");
+		return status;
+	}
 
 	// Receive the answer of the dive computer.
 	status = dc_iostream_read (device->iostream, answer, asize, NULL);
-- 
2.15.1



More information about the devel mailing list