]> sigrok.org Git - libsigrok.git/commitdiff
config_list: Don't check for sdi->priv != NULL.
authorUwe Hermann <redacted>
Sat, 14 May 2016 14:11:53 +0000 (16:11 +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/fx2lafw/api.c
src/hardware/hameg-hmo/api.c
src/hardware/korad-kaxxxxp/api.c
src/hardware/motech-lps-30x/api.c
src/hardware/rigol-ds/api.c
src/hwdriver.c
src/lcr/es51919.c

index b6c3af47a10ac83c19dc350869940bd1b5b7f48c..0508250cd501296ac68ba85a31cf921058cd360c 100644 (file)
@@ -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"),
index 08fbbcd8d99d463fafd555e8c89ff3999785ea9a..54db1f36510802b2b609130b8839c513fee63bfc 100644 (file)
@@ -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,
index 4b50b7aa6edb7a37dffaea3bdcac019de899def5..29dbe917968daad9189dbc60da5ae176903313a8 100644 (file)
@@ -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;
 
index 19daff8be5af4e3b7669fe4a4480f9776f4b198b..e008cfe4a4282d230a0674f780372b9f6c303833 100644 (file)
@@ -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;
index 57bc1d2654e9f9a966c85e7c9e7bf078970b41c8..57befbfd6edf6e9c06e5b2c8bead3e2266a52c84 100644 (file)
@@ -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));
index a88d1ba276b6f179078b5525910511a54700a5a6..e743608381952bc46825564cca42650bac46b028 100644 (file)
@@ -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)) {
index fafd93fc45e9ece33271722a400ddfa6f0b60ecd..6758f6a96fc07c1f905d0708a00710b2481787b8 100644 (file)
@@ -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);
index f1e27acb537d577fee30cda0222d8c04e9edc2a7..3b32df1ed38dd6234783e6ea48b31c30026f3b96 100644 (file)
@@ -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;
        }