]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
resource.c: Fix firmware loading bug (#1140)
[libsigrok.git] / src / hardware / scpi-pps / api.c
index 6de714014e2ea0c800b10a02af75857ddbe1905b..9158933dedf5e9bc44c95780ddabe34a3f251409 100644 (file)
@@ -433,7 +433,6 @@ static int config_set(uint32_t key, GVariant *data,
 {
        struct dev_context *devc;
        double d;
-       int ret;
 
        if (!sdi)
                return SR_ERR_ARG;
@@ -446,66 +445,66 @@ static int config_set(uint32_t key, GVariant *data,
        switch (key) {
        case SR_CONF_ENABLED:
                if (g_variant_get_boolean(data))
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OUTPUT_ENABLE);
                else
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OUTPUT_DISABLE);
                break;
        case SR_CONF_VOLTAGE_TARGET:
                d = g_variant_get_double(data);
-               ret = scpi_cmd(sdi, devc->device->commands,
+               return scpi_cmd(sdi, devc->device->commands,
                                SCPI_CMD_SET_VOLTAGE_TARGET, d);
                break;
        case SR_CONF_OUTPUT_FREQUENCY_TARGET:
                d = g_variant_get_double(data);
-               ret = scpi_cmd(sdi, devc->device->commands,
+               return scpi_cmd(sdi, devc->device->commands,
                                SCPI_CMD_SET_FREQUENCY_TARGET, d);
                break;
        case SR_CONF_CURRENT_LIMIT:
                d = g_variant_get_double(data);
-               ret = scpi_cmd(sdi, devc->device->commands,
+               return scpi_cmd(sdi, devc->device->commands,
                                SCPI_CMD_SET_CURRENT_LIMIT, d);
                break;
        case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
                if (g_variant_get_boolean(data))
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE);
                else
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE);
                break;
        case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
                d = g_variant_get_double(data);
-               ret = scpi_cmd(sdi, devc->device->commands,
+               return scpi_cmd(sdi, devc->device->commands,
                                SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d);
                break;
        case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
                if (g_variant_get_boolean(data))
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE);
                else
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE);
                break;
        case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
                d = g_variant_get_double(data);
-               ret = scpi_cmd(sdi, devc->device->commands,
+               return scpi_cmd(sdi, devc->device->commands,
                                SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d);
                break;
        case SR_CONF_OVER_TEMPERATURE_PROTECTION:
                if (g_variant_get_boolean(data))
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE);
                else
-                       ret = scpi_cmd(sdi, devc->device->commands,
+                       return scpi_cmd(sdi, devc->device->commands,
                                        SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE);
                break;
        default:
-               ret = SR_ERR_NA;
+               return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int config_list(uint32_t key, GVariant **data,
@@ -526,10 +525,12 @@ static int config_list(uint32_t key, GVariant **data,
                        return std_opts_config_list(key, data, sdi, cg,
                                ARRAY_AND_SIZE(scanopts),
                                ARRAY_AND_SIZE(drvopts),
-                               (devc) ? devc->device->devopts : NULL,
-                               (devc) ? devc->device->num_devopts : 0);
+                               (devc && devc->device) ? devc->device->devopts : NULL,
+                               (devc && devc->device) ? devc->device->num_devopts : 0);
                        break;
                case SR_CONF_CHANNEL_CONFIG:
+                       if (!devc || !devc->device)
+                               return SR_ERR_ARG;
                        /* Not used. */
                        i = 0;
                        if (devc->device->features & PPS_INDEPENDENT)
@@ -558,6 +559,8 @@ static int config_list(uint32_t key, GVariant **data,
                 * specification for use in series or parallel mode.
                 */
                ch = cg->channels->data;
+               if (!devc || !devc->device)
+                       return SR_ERR_ARG;
                ch_spec = &(devc->device->channels[ch->index]);
 
                switch (key) {