From a5c38703eeea8661e563c30631601b8334dd2b7c Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 15 Oct 2015 22:38:12 +0200 Subject: [PATCH] drivers: Fix behaviour when trying to set an invalid capture ratio. Trying to configure an invalid capture ratio would reset the previously configured value. Instead, we should just reject the new value and keep the original one. --- src/hardware/beaglelogic/api.c | 4 +--- src/hardware/fx2lafw/api.c | 6 +----- src/hardware/openbench-logic-sniffer/api.c | 5 ++--- src/hardware/pipistrello-ols/api.c | 5 ++--- src/hardware/saleae-logic16/api.c | 6 +----- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 1c8e43b8..b9740104 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -284,10 +284,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return beaglelogic_set_triggerflags(devc); case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) { - devc->capture_ratio = 0; + if (devc->capture_ratio > 100) return SR_ERR; - } return SR_OK; default: return SR_ERR_NA; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index efb1d0d2..6376d0fb 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -567,11 +567,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) { - devc->capture_ratio = 0; - ret = SR_ERR; - } else - ret = SR_OK; + ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK; break; default: ret = SR_ERR_NA; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index e61bd10d..fe442ac6 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -291,10 +291,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) { - devc->capture_ratio = 0; + if (devc->capture_ratio < 0 || devc->capture_ratio > 100) ret = SR_ERR; - } else + else ret = SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index c467f0cc..44af4017 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -299,10 +299,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) { - devc->capture_ratio = 0; + if (devc->capture_ratio < 0 || devc->capture_ratio > 100) ret = SR_ERR; - } else + else ret = SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 43477d5b..bee0ea4a 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -502,11 +502,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) { - devc->capture_ratio = 0; - ret = SR_ERR; - } else - ret = SR_OK; + ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK; break; case SR_CONF_VOLTAGE_THRESHOLD: g_variant_get(data, "(dd)", &low, &high);