Rephrase the successful lookup of a supported model by means of a
pointer to a models[] entry. Which eliminates the numeric index,
including the "sentinel" value which points outside of the table.
Use a signed integer for iteration over table items. Don't break
text lines between vendor and model fields, these fields form a
logical group from the user's perspective.
const char *conn, *serialcomm;
const char *force_detect;
struct sr_serial_dev_inst *serial;
const char *conn, *serialcomm;
const char *force_detect;
struct sr_serial_dev_inst *serial;
+ int ret;
+ const struct korad_kaxxxxp_model *model;
serno += strlen(serno_prefix);
}
serno += strlen(serno_prefix);
}
for (i = 0; models[i].id; i++) {
if (g_strcmp0(models[i].id, reply) != 0)
continue;
for (i = 0; models[i].id; i++) {
if (g_strcmp0(models[i].id, reply) != 0)
continue;
- if (model_id < 0 && force_detect) {
+ if (!model && force_detect) {
sr_warn("Found model ID '%s' is unknown, trying '%s' spec.",
reply, force_detect);
for (i = 0; models[i].id; i++) {
if (strcmp(models[i].id, force_detect) != 0)
continue;
sr_info("Found replacement, using it instead.");
sr_warn("Found model ID '%s' is unknown, trying '%s' spec.",
reply, force_detect);
for (i = 0; models[i].id; i++) {
if (strcmp(models[i].id, force_detect) != 0)
continue;
sr_info("Found replacement, using it instead.");
sr_err("Unknown model ID '%s' detected, aborting.", reply);
return NULL;
}
sr_err("Unknown model ID '%s' detected, aborting.", reply);
return NULL;
}
- sr_dbg("Found: %s %s (idx %d, ID '%s').", models[model_id].vendor,
- models[model_id].name, model_id, models[model_id].id);
+ sr_dbg("Found: %s %s (idx %zu, ID '%s').", model->vendor, model->name,
+ model - &models[0], model->id);
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->vendor = g_strdup(models[model_id].vendor);
- sdi->model = g_strdup(models[model_id].name);
+ sdi->vendor = g_strdup(model->vendor);
+ sdi->model = g_strdup(model->name);
if (serno)
sdi->serial_num = g_strdup(serno);
sdi->inst_type = SR_INST_SERIAL;
if (serno)
sdi->serial_num = g_strdup(serno);
sdi->inst_type = SR_INST_SERIAL;
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
g_mutex_init(&devc->rw_mutex);
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
g_mutex_init(&devc->rw_mutex);
- devc->model = &models[model_id];
devc->req_sent_at = 0;
devc->cc_mode_1_changed = FALSE;
devc->cc_mode_2_changed = FALSE;
devc->req_sent_at = 0;
devc->cc_mode_1_changed = FALSE;
devc->cc_mode_2_changed = FALSE;