config_get(): 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.
This commit is contained in:
Uwe Hermann 2016-05-14 15:41:45 +02:00
parent b0baddef56
commit 709468baf7
9 changed files with 30 additions and 16 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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.");

View File

@ -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;

View File

@ -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,

View File

@ -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;
}