yokogawa-dlm: Replace g_try_malloc() calls and fix coding style

This commit is contained in:
Soeren Apel 2014-08-31 00:40:11 +02:00
parent 0028d5a1ee
commit ac10a927b5
3 changed files with 77 additions and 79 deletions

View File

@ -69,8 +69,7 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
sr_scpi_hw_info_free(hw_info); sr_scpi_hw_info_free(hw_info);
hw_info = NULL; hw_info = NULL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) devc = g_malloc0(sizeof(struct dev_context));
goto fail;
sdi->driver = di; sdi->driver = di;
sdi->priv = devc; sdi->priv = devc;
@ -570,7 +569,7 @@ static int dlm_setup_channels(const struct sr_dev_inst *sdi)
model = devc->model_config; model = devc->model_config;
setup_changed = FALSE; setup_changed = FALSE;
pod_enabled = g_try_malloc0(sizeof(gboolean) * model->pods); pod_enabled = g_malloc0(sizeof(gboolean) * model->pods);
for (l = sdi->channels; l; l = l->next) { for (l = sdi->channels; l; l = l->next) {
ch = l->data; ch = l->data;
@ -635,7 +634,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
(void)cb_data; (void)cb_data;
if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
scpi = sdi->conn; scpi = sdi->conn;
devc = sdi->priv; devc = sdi->priv;
@ -708,7 +708,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = { SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = {
.name = "yokogawa-dlm", .name = "yokogawa-dlm",
.longname = "Yokogawa DL/DLM driver", .longname = "Yokogawa DL/DLM",
.api_version = 1, .api_version = 1,
.init = init, .init = init,
.cleanup = cleanup, .cleanup = cleanup,

View File

@ -328,6 +328,7 @@ static int array_float_get(gchar *value, const uint64_t array[][2],
int i; int i;
uint64_t f; uint64_t f;
float s; float s;
unsigned int s_int;
gchar ss[10], es[10]; gchar ss[10], es[10];
memset(ss, 0, sizeof(ss)); memset(ss, 0, sizeof(ss));
@ -350,10 +351,10 @@ static int array_float_get(gchar *value, const uint64_t array[][2],
while ((int)fmod(log10(f), 3) > 0) { s *= 10; f *= 10; } while ((int)fmod(log10(f), 3) > 0) { s *= 10; f *= 10; }
/* Truncate s to circumvent rounding errors. */ /* Truncate s to circumvent rounding errors. */
s = (int)s; s_int = (unsigned int)s;
for (i = 0; i < array_len; i++) { for (i = 0; i < array_len; i++) {
if ( (s == array[i][0]) && (f == array[i][1]) ) { if ( (s_int == array[i][0]) && (f == array[i][1]) ) {
*result = i; *result = i;
return SR_OK; return SR_OK;
} }
@ -583,14 +584,13 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
* *
* @param config The device configuration to use. * @param config The device configuration to use.
* *
* @return The newly allocated scope_state struct or NULL on error. * @return The newly allocated scope_state struct.
*/ */
static struct scope_state *dlm_scope_state_new(struct scope_config *config) static struct scope_state *dlm_scope_state_new(struct scope_config *config)
{ {
struct scope_state *state; struct scope_state *state;
if (!(state = g_try_malloc0(sizeof(struct scope_state)))) state = g_malloc0(sizeof(struct scope_state));
return NULL;
state->analog_states = g_malloc0(config->analog_channels * state->analog_states = g_malloc0(config->analog_channels *
sizeof(struct analog_channel_state)); sizeof(struct analog_channel_state));

View File

@ -79,8 +79,6 @@ struct scope_config {
const uint8_t num_xdivs; const uint8_t num_xdivs;
const uint8_t num_ydivs; const uint8_t num_ydivs;
const char *(*scpi_dialect)[];
}; };
struct analog_channel_state { struct analog_channel_state {