Skip to content

Commit

Permalink
use common channel group allocation/release code
Browse files Browse the repository at this point in the history
Eliminate individual open coded alloc and release code for channel
groups in hardware drivers and input modules. Use common code instead.

This commit affects: arachnid-labs-re-load-pro, atten-pps3xxx,
baylibre-acme, dcttech-usbrelay, demo, dreamsourcelab-dslogic, fx2lafw,
gwinstek-gds-800, gwinstek-gpd, hameg-hmo, hantek-4032l, hantek-6xxx,
hantek-dso, hp-3457a, hp-59306a, hung-chang-dso-2100, itech-it8500,
lecroy-xstream, maynuo-m97, microchip-pickit2, motech-lps-30x, rigol-dg,
rigol-ds, scpi-pps, siglent-sds, yokogawa-dlm, input/vcd.
  • Loading branch information
gsigh committed Feb 6, 2022
1 parent 7047acc commit d810901
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 152 deletions.
4 changes: 1 addition & 3 deletions src/hardware/arachnid-labs-re-load-pro/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;

cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("1");
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
cg = sr_channel_group_new(sdi, "1", NULL);

ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V");
cg->channels = g_slist_append(cg->channels, ch);
Expand Down
5 changes: 1 addition & 4 deletions src/hardware/atten-pps3xxx/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
for (i = 0; i < MAX_CHANNELS; i++) {
snprintf(channel, 10, "CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel);
cg = g_malloc(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel);
cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);
cg->priv = NULL;
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = g_malloc0(sizeof(struct dev_context));
Expand Down
5 changes: 1 addition & 4 deletions src/hardware/baylibre-acme/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
if (hwmon < 0)
return FALSE;

cg = g_malloc0(sizeof(struct sr_channel_group));
cgp = g_malloc0(sizeof(struct channel_group_priv));
cg->priv = cgp;
cg = sr_channel_group_new(sdi, NULL, cgp);

/*
* See if we can read the EEPROM contents. If not, assume it's
Expand Down Expand Up @@ -380,8 +379,6 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
sr_err("Invalid probe type: %d.", type);
}

sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);

return TRUE;
}

Expand Down
8 changes: 4 additions & 4 deletions src/hardware/dcttech-usbrelay/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static struct sr_dev_inst *probe_device_common(const char *path,
struct channel_group_context *cgc;
size_t idx, nr;
struct sr_channel_group *cg;
char cg_name[24];

/*
* Get relay count from product string. Weak condition,
Expand Down Expand Up @@ -153,12 +154,11 @@ static struct sr_dev_inst *probe_device_common(const char *path,
devc->relay_mask = (1U << relay_count) - 1;
for (idx = 0; idx < devc->relay_count; idx++) {
nr = idx + 1;
cg = g_malloc0(sizeof(*cg));
cg->name = g_strdup_printf("R%zu", nr);
snprintf(cg_name, sizeof(cg_name), "R%zu", nr);
cgc = g_malloc0(sizeof(*cgc));
cg->priv = cgc;
cgc->number = nr;
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
cg = sr_channel_group_new(sdi, cg_name, cgc);
(void)cg;
}

return sdi;
Expand Down
12 changes: 3 additions & 9 deletions src/hardware/demo/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)

if (num_logic_channels > 0) {
/* Logic channels, all in one channel group. */
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("Logic");
cg = sr_channel_group_new(sdi, "Logic", NULL);
for (i = 0; i < num_logic_channels; i++) {
sprintf(channel_name, "D%d", i);
ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
sdi->channel_groups = g_slist_append(NULL, cg);
}

/* Analog channels, channel groups and pattern generators. */
Expand All @@ -173,9 +171,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)

pattern = 0;
/* An "Analog" channel group with all analog channels in it. */
acg = g_malloc0(sizeof(struct sr_channel_group));
acg->name = g_strdup("Analog");
sdi->channel_groups = g_slist_append(sdi->channel_groups, acg);
acg = sr_channel_group_new(sdi, "Analog", NULL);

for (i = 0; i < num_analog_channels; i++) {
snprintf(channel_name, 16, "A%d", i);
Expand All @@ -184,10 +180,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
acg->channels = g_slist_append(acg->channels, ch);

/* Every analog channel gets its own channel group as well. */
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel_name);
cg = sr_channel_group_new(sdi, channel_name, NULL);
cg->channels = g_slist_append(NULL, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);

/* Every channel gets a generator struct. */
ag = g_malloc(sizeof(struct analog_gen));
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/dreamsourcelab-dslogic/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->connection_id = g_strdup(connection_id);

/* Logic channels, all in one channel group. */
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("Logic");
cg = sr_channel_group_new(sdi, "Logic", NULL);
for (j = 0; j < NUM_CHANNELS; j++) {
sprintf(channel_name, "%d", j);
ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
sdi->channel_groups = g_slist_append(NULL, cg);

devc = dslogic_dev_new();
devc->profile = prof;
Expand Down
8 changes: 2 additions & 6 deletions src/hardware/fx2lafw/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,22 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0;

/* Logic channels, all in one channel group. */
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("Logic");
cg = sr_channel_group_new(sdi, "Logic", NULL);
for (j = 0; j < num_logic_channels; j++) {
sprintf(channel_name, "D%d", j);
ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
sdi->channel_groups = g_slist_append(NULL, cg);

for (j = 0; j < num_analog_channels; j++) {
snprintf(channel_name, 16, "A%d", j);
ch = sr_channel_new(sdi, j + num_logic_channels,
SR_CHANNEL_ANALOG, TRUE, channel_name);

/* Every analog channel gets its own channel group. */
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel_name);
cg = sr_channel_group_new(sdi, channel_name, NULL);
cg->channels = g_slist_append(NULL, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = fx2lafw_dev_new();
Expand Down
5 changes: 1 addition & 4 deletions src/hardware/gwinstek-gds-800/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2");

cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("");
cg = sr_channel_group_new(sdi, "", NULL);
cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 0));
cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 1));
cg->priv = NULL;
sdi->channel_groups = g_slist_append(NULL, cg);

return sdi;
}
Expand Down
5 changes: 1 addition & 4 deletions src/hardware/gwinstek-gpd/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
for (i = 0; i < model->num_channels; i++) {
snprintf(channel, sizeof(channel), "CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel);
cg = g_malloc(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel);
cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);
cg->priv = NULL;
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = g_malloc0(sizeof(struct dev_context));
Expand Down
14 changes: 4 additions & 10 deletions src/hardware/hameg-hmo/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
unsigned int i, j, group;
struct sr_channel *ch;
struct dev_context *devc;
const char *cg_name;
int ret;

devc = sdi->priv;
Expand Down Expand Up @@ -1232,27 +1233,20 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
(*scope_models[model_index].analog_names)[i]);

devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));

devc->analog_groups[i]->name = g_strdup(
(char *)(*scope_models[model_index].analog_names)[i]);
cg_name = (*scope_models[model_index].analog_names)[i];
devc->analog_groups[i] = sr_channel_group_new(sdi, cg_name, NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);

sdi->channel_groups = g_slist_append(sdi->channel_groups,
devc->analog_groups[i]);
}

/* Add digital channel groups. */
ret = SR_OK;
for (i = 0; i < scope_models[model_index].digital_pods; i++) {
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL);
if (!devc->digital_groups[i]) {
ret = SR_ERR_MALLOC;
break;
}
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
sdi->channel_groups = g_slist_append(sdi->channel_groups,
devc->digital_groups[i]);
}
if (ret != SR_OK)
return ret;
Expand Down
3 changes: 1 addition & 2 deletions src/hardware/hantek-4032l/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)

struct sr_channel_group *channel_groups[2];
for (int j = 0; j < 2; j++) {
cg = g_malloc0(sizeof(struct sr_channel_group));
cg = sr_channel_group_new(sdi, NULL, NULL);
cg->name = g_strdup_printf("%c", 'A' + j);
channel_groups[j] = cg;
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

/* Assemble channel list and add channel to channel groups. */
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/hantek-6xxx/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile

for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel_names[i]);
cg = sr_channel_group_new(sdi, channel_names[i], NULL);
cg->channels = g_slist_append(cg->channels, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = g_malloc0(sizeof(struct dev_context));
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/hantek-dso/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
*/
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup(channel_names[i]);
cg = sr_channel_group_new(sdi, channel_names[i], NULL);
cg->channels = g_slist_append(cg->channels, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = g_malloc0(sizeof(struct dev_context));
Expand Down
10 changes: 2 additions & 8 deletions src/hardware/hp-3457a/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ static int create_front_channel(struct sr_dev_inst *sdi, int chan_idx)
TRUE, "Front");
channel->priv = chanc;

front = g_malloc0(sizeof(*front));
front->name = g_strdup("Front");
front = sr_channel_group_new(sdi, "Front", NULL);
front->channels = g_slist_append(front->channels, channel);

sdi->channel_groups = g_slist_append(sdi->channel_groups, front);

return chan_idx;
}

Expand All @@ -74,10 +71,7 @@ static int create_rear_channels(struct sr_dev_inst *sdi, int chan_idx,
if (!card)
return chan_idx;

group = g_malloc0(sizeof(*group));
group->priv = NULL;
group->name = g_strdup(card->cg_name);
sdi->channel_groups = g_slist_append(sdi->channel_groups, group);
group = sr_channel_group_new(sdi, card->cg_name, NULL);

for (i = 0; i < card->num_channels; i++) {

Expand Down
11 changes: 4 additions & 7 deletions src/hardware/hp-59306a/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
struct channel_group_context *cgc;
size_t idx, nr;
struct sr_channel_group *cg;
char cg_name[24];

/*
* The device cannot get identified by means of SCPI queries.
Expand All @@ -73,15 +74,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
devc->channel_count = 6;
for (idx = 0; idx < devc->channel_count; idx++) {
nr = idx + 1;

cg = g_malloc0(sizeof(*cg));
cg->name = g_strdup_printf("R%zu", nr);

snprintf(cg_name, sizeof(cg_name), "R%zu", nr);
cgc = g_malloc0(sizeof(*cgc));
cgc->number = nr;
cg->priv = cgc;

sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
cg = sr_channel_group_new(sdi, cg_name, cgc);
(void)cg;
}

return sdi;
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/hung-chang-dso-2100/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ static GSList *scan_port(GSList *devices, struct parport *port)
ieee1284_ref(port);

for (i = 0; i < NUM_CHANNELS; i++) {
cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup(trigger_sources[i]);
cg = sr_channel_group_new(sdi, trigger_sources[i], NULL);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]);
cg->channels = g_slist_append(cg->channels, ch);
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

devc = g_malloc0(sizeof(struct dev_context));
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/itech-it8500/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->version = g_strdup_printf("%x.%02x", fw_major, fw_minor);
sdi->serial_num = unit_serial;

cg = g_malloc0(sizeof(*cg));
cg->name = g_strdup("1");
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
cg = sr_channel_group_new(sdi, "1", NULL);
ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1");
cg->channels = g_slist_append(cg->channels, ch);
ch = sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "I1");
Expand Down
9 changes: 2 additions & 7 deletions src/hardware/lecroy-xstream/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,9 @@ SR_PRIV int lecroy_xstream_init_device(struct sr_dev_inst *sdi)
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, channel_enabled,
(*scope_models[model_index].analog_names)[i]);

devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));

devc->analog_groups[i]->name = g_strdup(
(char *)(*scope_models[model_index].analog_names)[i]);
devc->analog_groups[i] = sr_channel_group_new(sdi,
(*scope_models[model_index].analog_names)[i], NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);

sdi->channel_groups = g_slist_append(sdi->channel_groups,
devc->analog_groups[i]);
}

devc->model_config = &scope_models[model_index];
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/maynuo-m97/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ static struct sr_dev_inst *probe_device(struct sr_modbus_dev_inst *modbus)
sdi->driver = &maynuo_m97_driver_info;
sdi->inst_type = SR_INST_MODBUS;

cg = g_malloc0(sizeof(struct sr_channel_group));
cg->name = g_strdup("1");
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
cg = sr_channel_group_new(sdi, "1", NULL);

ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1");
cg->channels = g_slist_append(cg->channels, ch);
Expand Down
4 changes: 1 addition & 3 deletions src/hardware/microchip-pickit2/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->connection_id = g_strdup(conn);

/* Create the logic channels group. */
cg = g_malloc0(sizeof(*cg));
sdi->channel_groups = g_slist_append(NULL, cg);
cg->name = g_strdup("Logic");
cg = sr_channel_group_new(sdi, "Logic", NULL);
ch_count = ARRAY_SIZE(channel_names);
for (ch_idx = 0; ch_idx < ch_count; ch_idx++) {
ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC,
Expand Down
6 changes: 1 addition & 5 deletions src/hardware/motech-lps-30x/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,9 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o

devc->channel_status[cnt].info = g_slist_append(NULL, ch);

cg = g_malloc(sizeof(struct sr_channel_group));
snprintf(channel, sizeof(channel), "CG%d", cnt + 1);
cg->name = g_strdup(channel);
cg->priv = NULL;
cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);

sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

/* Query status */
Expand Down
5 changes: 1 addition & 4 deletions src/hardware/rigol-dg/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
for (i = 0; i < device->num_channels; i++) {
ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG, TRUE,
device->channels[i].name);
cg = g_malloc0(sizeof(*cg));
snprintf(tmp, sizeof(tmp), "%u", i + 1);
cg->name = g_strdup(tmp);
cg = sr_channel_group_new(sdi, tmp, NULL);
cg->channels = g_slist_append(cg->channels, ch);

sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}

/* Create channels for the frequency counter output. */
Expand Down
Loading

0 comments on commit d810901

Please sign in to comment.