From a14b0b7b98fb846287205c66e1f6d372a0a6dcf1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 25 Jan 2010 14:08:01 +0000 Subject: [PATCH] Do not ignore errors during initialization. --- src/oceanic_atom2.c | 14 ++++++++++++-- src/oceanic_veo250.c | 14 ++++++++++++-- src/oceanic_vtpro.c | 21 ++++++++++++++++++--- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index b1d81bc..f950744 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -273,12 +273,22 @@ oceanic_atom2_device_open (device_t **out, const char* name) serial_flush (device->port, SERIAL_QUEUE_BOTH); // Send the init command. - oceanic_atom2_init (device); + device_status_t status = oceanic_atom2_init (device); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } // Switch the device from surface mode into download mode. Before sending // this command, the device needs to be in PC mode (automatically activated // by connecting the device), or already in download mode. - oceanic_atom2_device_version ((device_t *) device, device->version, sizeof (device->version)); + status = oceanic_atom2_device_version ((device_t *) device, device->version, sizeof (device->version)); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } *out = (device_t*) device; diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index 4590229..a4428d8 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -273,7 +273,12 @@ oceanic_veo250_device_open (device_t **out, const char* name) serial_flush (device->port, SERIAL_QUEUE_BOTH); // Initialize the data cable (PPS mode). - oceanic_veo250_init (device); + device_status_t status = oceanic_veo250_init (device); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } // Delay the sending of the version command. serial_sleep (100); @@ -281,7 +286,12 @@ oceanic_veo250_device_open (device_t **out, const char* name) // Switch the device from surface mode into download mode. Before sending // this command, the device needs to be in PC mode (manually activated by // the user), or already in download mode. - oceanic_veo250_device_version ((device_t *) device, device->version, sizeof (device->version)); + status = oceanic_veo250_device_version ((device_t *) device, device->version, sizeof (device->version)); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } *out = (device_t*) device; diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index 8049f07..eaa8b88 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -292,17 +292,32 @@ oceanic_vtpro_device_open (device_t **out, const char* name) serial_flush (device->port, SERIAL_QUEUE_BOTH); // Initialize the data cable (MOD mode). - oceanic_vtpro_init (device); + device_status_t status = oceanic_vtpro_init (device); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } // Switch the device from surface mode into download mode. Before sending // this command, the device needs to be in PC mode (manually activated by // the user), or already in download mode. - oceanic_vtpro_device_version ((device_t *) device, device->version, sizeof (device->version)); + status = oceanic_vtpro_device_version ((device_t *) device, device->version, sizeof (device->version)); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } // Calibrate the device. Although calibration is optional, it's highly // recommended because it reduces the transfer time considerably, even // when processing the command itself is quite slow. - oceanic_vtpro_calibrate (device); + status = oceanic_vtpro_calibrate (device); + if (status != DEVICE_STATUS_SUCCESS) { + serial_close (device->port); + free (device); + return status; + } *out = (device_t*) device;