After scan() completed the conn= can no longer be unknown. The firmware
was loaded and became effective (and communication was tested) before we
get to the config getter. Check PWM period and duty cycle value ranges
in the config setter.
Use symbolic names in the threshold voltage range check when protocol.c
forwards the configured value to the device.
switch (key) {
case SR_CONF_CONN:
switch (key) {
case SR_CONF_CONN:
- if (!sdi->conn)
- return SR_ERR_ARG;
- if (usb->address == 0xff) {
- /*
- * Device still needs to re-enumerate after firmware
- * upload, so we don't know its (future) address.
- */
- return SR_ERR;
- }
*data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
break;
case SR_CONF_SAMPLERATE:
*data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
break;
case SR_CONF_SAMPLERATE:
int ret, cg_type;
size_t logic_idx, analog_idx;
struct pwm_setting *pwm;
int ret, cg_type;
size_t logic_idx, analog_idx;
struct pwm_setting *pwm;
double low, high;
int idx;
double low, high;
int idx;
return ret;
break;
case SR_CONF_OUTPUT_FREQUENCY:
return ret;
break;
case SR_CONF_OUTPUT_FREQUENCY:
- pwm->freq = g_variant_get_double(data);
+ value_f = g_variant_get_double(data);
+ if (value_f <= 0.0 || value_f > MAX_PWM_FREQ)
+ return SR_ERR_ARG;
+ pwm->freq = value_f;
ret = la2016_write_pwm_config(sdi, analog_idx);
if (ret != SR_OK)
return ret;
break;
case SR_CONF_DUTY_CYCLE:
ret = la2016_write_pwm_config(sdi, analog_idx);
if (ret != SR_OK)
return ret;
break;
case SR_CONF_DUTY_CYCLE:
- pwm->duty = g_variant_get_double(data);
+ value_f = g_variant_get_double(data);
+ if (value_f <= 0.0 || value_f > 100.0)
+ return SR_ERR_ARG;
+ pwm->duty = value_f;
ret = la2016_write_pwm_config(sdi, analog_idx);
if (ret != SR_OK)
return ret;
ret = la2016_write_pwm_config(sdi, analog_idx);
if (ret != SR_OK)
return ret;
devc = sdi->priv;
/* Clamp threshold setting to valid range for LA2016. */
devc = sdi->priv;
/* Clamp threshold setting to valid range for LA2016. */
- if (voltage > 4.0) {
- voltage = 4.0;
- } else if (voltage < -4.0) {
- voltage = -4.0;
+ if (voltage > LA2016_THR_VOLTAGE_MAX) {
+ voltage = LA2016_THR_VOLTAGE_MAX;
+ } else if (voltage < -LA2016_THR_VOLTAGE_MAX) {
+ voltage = -LA2016_THR_VOLTAGE_MAX;