yokogawa-dlm: fix several compiler warnings (assignment, memory)

Check pointers' validity before dereferencing them. Release partially
allocated memory in an error path. Remove an assignment which never took
effect.

This was reported by clang's scan-build.
This commit is contained in:
Gerhard Sittig 2018-02-09 19:32:12 +01:00 committed by Uwe Hermann
parent 2da5c95f3d
commit 93b5cd6919
2 changed files with 9 additions and 3 deletions

View File

@ -164,6 +164,8 @@ static int check_channel_group(struct dev_context *devc,
{
const struct scope_config *model;
if (!devc)
return CG_INVALID;
model = devc->model_config;
if (!cg)
@ -284,8 +286,6 @@ static int config_set(uint32_t key, GVariant *data,
state = devc->model_state;
update_sample_rate = FALSE;
ret = SR_ERR_NA;
switch (key) {
case SR_CONF_LIMIT_FRAMES:
devc->frame_limit = g_variant_get_uint64(data);
@ -409,6 +409,8 @@ static int config_list(uint32_t key, GVariant **data,
*data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes));
return SR_OK;
case SR_CONF_NUM_HDIV:
if (!model)
return SR_ERR_ARG;
*data = g_variant_new_uint32(model->num_xdivs);
return SR_OK;
default:

View File

@ -777,9 +777,13 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
scope_models[model_index].analog_channels);
devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
scope_models[model_index].pods);
if (!devc->analog_groups || !devc->digital_groups) {
g_free(devc->analog_groups);
g_free(devc->digital_groups);
return SR_ERR_MALLOC;
}
/* Add analog channels, each in its own group. */
for (i = 0; i < scope_models[model_index].analog_channels; i++) {