Cleanup: consistently check return value of iostream functions

Coverity CID 215197
Coverity CID 215200

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-01-04 08:50:25 -08:00 committed by Jef Driesen
parent 4e93b9a8f8
commit 2f097e54fe
9 changed files with 94 additions and 20 deletions

View File

@ -159,7 +159,11 @@ citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_NOMEMORY;
}
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};
@ -201,7 +205,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;
}

View File

@ -905,7 +905,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};
@ -931,7 +936,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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -161,7 +161,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;

View File

@ -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;
}

View File

@ -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);