diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 932c9430..b6c3af47 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -330,8 +330,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s *data = g_variant_new_string(str); break; case SR_CONF_SAMPLERATE: - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_BUG; + devc = sdi->priv; *data = g_variant_new_uint64(devc->cur_samplerate); break; default: diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 3abbd16c..378b6263 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -372,9 +372,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s (void)cg; - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_ARG; + devc = sdi->priv; + ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 4c5e896f..45e86152 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -127,9 +127,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s (void)cg; - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_ARG; + devc = sdi->priv; + switch (key) { case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->sample_rate); diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index afe64891..4b50b7aa 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -189,9 +189,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const struct scope_config *model; struct scope_state *state; - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_ARG; + devc = sdi->priv; + if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) return SR_ERR; diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index f6353830..c3abb0ae 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -258,13 +258,14 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, (void)cg; + if (!sdi) + return SR_ERR_ARG; + + devc = sdi->priv; + switch (key) { case SR_CONF_SAMPLERATE: - if (sdi) { - devc = sdi->priv; - *data = g_variant_new_uint64(devc->cur_rate); - } else - return SR_ERR; + *data = g_variant_new_uint64(devc->cur_rate); break; default: return SR_ERR_NA; diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index c380c330..a88d1ba2 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -501,9 +501,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s int idx = -1; unsigned i; - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_ARG; + devc = sdi->priv; + /* If a channel group is specified, it must be a valid one. */ if (cg && !g_slist_find(sdi->channel_groups, cg)) { sr_err("Invalid channel group specified."); diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 0a02f5d1..1d69a792 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -209,9 +209,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const struct scope_config *model; struct scope_state *state; - if (!sdi || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_ARG; + devc = sdi->priv; + if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) return SR_ERR; diff --git a/src/hwdriver.c b/src/hwdriver.c index 7e16b82a..fafd93fc 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -672,10 +672,11 @@ static int check_key(const struct sr_dev_driver *driver, /** * Query value of a configuration key at the given driver or device instance. * - * @param[in] driver The sr_dev_driver struct to query. + * @param[in] driver The sr_dev_driver struct to query. Must not be NULL. * @param[in] sdi (optional) If the key is specific to a device, this must * contain a pointer to the struct sr_dev_inst to be checked. - * Otherwise it must be NULL. + * Otherwise it must be NULL. If sdi is != NULL, sdi->priv must + * also be != NULL. * @param[in] cg The channel group on the device for which to list the * values, or NULL. * @param[in] key The configuration key (SR_CONF_*). @@ -709,6 +710,9 @@ SR_API int sr_config_get(const struct sr_dev_driver *driver, if (check_key(driver, sdi, cg, key, SR_CONF_GET, NULL) != SR_OK) return SR_ERR_ARG; + if (sdi && !sdi->priv) + return SR_ERR; + if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_GET, *data); /* Got a floating reference from the driver. Sink it here, diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index f020de83..f1e27acb 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -809,8 +809,7 @@ SR_PRIV int es51919_serial_config_get(uint32_t key, GVariant **data, (void)cg; - if (!(devc = sdi->priv)) - return SR_ERR_BUG; + devc = sdi->priv; switch (key) { case SR_CONF_OUTPUT_FREQUENCY: @@ -820,7 +819,6 @@ SR_PRIV int es51919_serial_config_get(uint32_t key, GVariant **data, *data = g_variant_new_string(models[devc->model]); break; default: - sr_spew("%s: Unsupported key %u", __func__, key); return SR_ERR_NA; }