]> sigrok.org Git - libsigrok.git/commitdiff
config_get(): Don't check for sdi->priv != NULL.
authorUwe Hermann <redacted>
Sat, 14 May 2016 13:41:45 +0000 (15:41 +0200)
committerUwe Hermann <redacted>
Mon, 16 May 2016 23:12:56 +0000 (01:12 +0200)
If sdi is != NULL, the backend ensures that sdi->priv is also != NULL.
Almost all drivers were relying on this already.

src/hardware/chronovu-la/api.c
src/hardware/gmc-mh-1x-2x/api.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/hameg-hmo/api.c
src/hardware/link-mso19/api.c
src/hardware/rigol-ds/api.c
src/hardware/yokogawa-dlm/api.c
src/hwdriver.c
src/lcr/es51919.c

index 932c9430039b306a0ecf8b08a582614a8bf57f3f..b6c3af47a10ac83c19dc350869940bd1b5b7f48c 100644 (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:
index 3abbd16cbf0e3646d17a8e8827fa814151c82d18..378b6263bf32c6cfd4b39e53c20bd22c4572d23b 100644 (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:
index 4c5e896f09e9e5fb30954fdae37127e7be30ccff..45e861521d0f2bbe68c0567afabece855a87ce4e 100644 (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);
index afe648911a06f4e2e106bf228ac45a5935fa3412..4b50b7aa6edb7a37dffaea3bdcac019de899def5 100644 (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;
 
index f635383034b81f43862fb976564b574031e4e0e5..c3abb0ae8de738e653c3d5a3977f16767d963bf5 100644 (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;
index c380c330db11d835164dfd24f382d6d368c178f4..a88d1ba276b6f179078b5525910511a54700a5a6 100644 (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.");
index 0a02f5d129ad6289bbc19ccc49cfbd9754d36a3e..1d69a7925d8f8d2ecf2c9163f5825e191fb89a16 100644 (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;
 
index 7e16b82a9cecd2aaca78ead54f4456bea77c56bc..fafd93fc45e9ece33271722a400ddfa6f0b60ecd 100644 (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,
index f020de8398d850839d66a00af895c092a3813943..f1e27acb537d577fee30cda0222d8c04e9edc2a7 100644 (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;
        }