From: Uwe Hermann Date: Sat, 14 May 2016 14:11:53 +0000 (+0200) Subject: config_list: Don't check for sdi->priv != NULL. X-Git-Tag: libsigrok-0.5.0~387 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4d399734b4ec7affb58c5881ea1b8d88eaa57d53;p=libsigrok.git config_list: Don't check for sdi->priv != NULL. If sdi is != NULL, the backend ensures that sdi->priv is also != NULL. Almost all drivers were relying on this already. --- diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index b6c3af47..0508250c 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -399,8 +399,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; case SR_CONF_SAMPLERATE: - if (!sdi || !sdi->priv || !(devc = sdi->priv)) + if (!sdi) return SR_ERR_BUG; + devc = sdi->priv; cv_fill_samplerates_if_needed(sdi); g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 08fbbcd8..54db1f36 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -740,8 +740,6 @@ static int config_list(uint32_t key, GVariant **data, *data = g_variant_builder_end(&gvb); break; case SR_CONF_SAMPLERATE: - if (!sdi->priv) - return SR_ERR_ARG; devc = sdi->priv; g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 4b50b7aa..29dbe917 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -487,7 +487,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * struct dev_context *devc = NULL; const struct scope_config *model = NULL; - if (sdi && (devc = sdi->priv)) { + if (sdi) { + devc = sdi->priv; if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) return SR_ERR; diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index 19daff8b..e008cfe4 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -288,7 +288,6 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct dev_context *devc; GVariant *gvar; GVariantBuilder gvb; diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 57bc1d26..57befbfd 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -700,7 +700,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); return SR_OK; case SR_CONF_DEVICE_OPTIONS: - if (sdi != NULL) + if (sdi) break; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index a88d1ba2..e7436083 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -805,8 +805,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } /* Every other option requires a valid device instance. */ - 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)) { diff --git a/src/hwdriver.c b/src/hwdriver.c index fafd93fc..6758f6a9 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -710,8 +710,10 @@ 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) + if (sdi && !sdi->priv) { + sr_err("Can't get config (sdi != NULL, sdi->priv == NULL)."); return SR_ERR; + } if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_GET, *data); @@ -793,9 +795,11 @@ SR_API int sr_config_commit(const struct sr_dev_inst *sdi) /** * List all possible values for a configuration key. * - * @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. 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_*). @@ -828,6 +832,10 @@ SR_API int sr_config_list(const struct sr_dev_driver *driver, if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK) return SR_ERR_ARG; } + if (sdi && !sdi->priv) { + sr_err("Can't list config (sdi != NULL, sdi->priv == NULL)."); + return SR_ERR; + } if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_LIST, *data); g_variant_ref_sink(*data); diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index f1e27acb..3b32df1e 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -894,7 +894,6 @@ SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data, *data = g_variant_new_strv(models, ARRAY_SIZE(models)); break; default: - sr_spew("%s: Unsupported key %u", __func__, key); return SR_ERR_NA; }