Simplify single device list handling
Some driver scan() functions only ever return a single device. For those it is possible to slightly simplify the handling of the device list by creating it on demand when the function returns. Some drivers also have the following expression: devices = g_slist_append(devices, sdi); ... if (!devices) ... This check will never evaluate to false so it is dropped as well. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
15a5bfe481
commit
43376f3324
|
@ -65,14 +65,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct sr_serial_dev_inst *serial;
|
||||
struct sr_channel_group *cg;
|
||||
struct sr_channel *ch;
|
||||
GSList *l, *devices;
|
||||
GSList *l;
|
||||
int ret, len;
|
||||
const char *conn, *serialcomm;
|
||||
char buf[100];
|
||||
char *bufptr;
|
||||
double version;
|
||||
|
||||
devices = NULL;
|
||||
drvc = di->context;
|
||||
|
||||
conn = serialcomm = NULL;
|
||||
|
@ -145,13 +144,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
devc = g_malloc0(sizeof(struct dev_context));
|
||||
sdi->priv = devc;
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
if (!devices)
|
||||
sr_serial_dev_inst_free(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int config_list(uint32_t key, GVariant **data,
|
||||
|
|
|
@ -65,7 +65,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
GSList *devices;
|
||||
struct ftdi_device_list *devlist;
|
||||
char serial_txt[10];
|
||||
uint32_t serial;
|
||||
|
@ -74,8 +73,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
(void)options;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
devc = g_malloc0(sizeof(struct dev_context));
|
||||
|
||||
ftdi_init(&devc->ftdic);
|
||||
|
@ -120,13 +117,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
|
||||
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
sdi->priv = devc;
|
||||
|
||||
/* We will open the device again when we need it. */
|
||||
ftdi_list_free(&devlist);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
|
||||
free:
|
||||
ftdi_deinit(&devc->ftdic);
|
||||
|
|
|
@ -84,7 +84,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
|
|||
struct sr_channel *ch;
|
||||
struct sr_channel_group *cg;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
GSList *l, *devices;
|
||||
GSList *l;
|
||||
const struct pps_model *model;
|
||||
uint8_t packet[PACKET_SIZE];
|
||||
unsigned int i;
|
||||
|
@ -92,7 +92,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
|
|||
const char *conn, *serialcomm;
|
||||
char channel[10];
|
||||
|
||||
devices = NULL;
|
||||
drvc = di->context;
|
||||
|
||||
conn = serialcomm = NULL;
|
||||
|
@ -175,13 +174,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid)
|
|||
devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
|
||||
devc->delay_ms = delay_ms;
|
||||
sdi->priv = devc;
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
if (!devices)
|
||||
sr_serial_dev_inst_free(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static GSList *scan_3203(struct sr_dev_driver *di, GSList *options)
|
||||
|
|
|
@ -55,14 +55,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
{
|
||||
struct dev_context *devc;
|
||||
struct sr_dev_inst *sdi;
|
||||
GSList *devices;
|
||||
gboolean status;
|
||||
int i;
|
||||
|
||||
(void)options;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
devc = g_malloc0(sizeof(struct dev_context));
|
||||
devc->samplerate = SR_HZ(10);
|
||||
|
||||
|
@ -120,9 +117,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
if (!sdi->channel_groups)
|
||||
goto err_out;
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
|
||||
err_out:
|
||||
g_free(devc);
|
||||
|
|
|
@ -73,14 +73,12 @@ static struct dev_context *beaglelogic_devc_alloc(void)
|
|||
|
||||
static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||
{
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
struct sr_config *src;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
int i, maxch;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
/* Probe for /dev/beaglelogic */
|
||||
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
|
||||
return NULL;
|
||||
|
@ -128,9 +126,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
channel_names[i]);
|
||||
|
||||
sdi->priv = devc;
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int dev_open(struct sr_dev_inst *sdi)
|
||||
|
|
|
@ -62,14 +62,12 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
|
|||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
GSList *devices;
|
||||
|
||||
serial = sr_serial_dev_inst_new(conn, serialcomm);
|
||||
|
||||
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
|
||||
return NULL;
|
||||
|
||||
devices = NULL;
|
||||
serial_flush(serial);
|
||||
|
||||
sr_info("Found device on port %s.", conn);
|
||||
|
@ -86,11 +84,9 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
|
|||
for (i = 0; i < center_devs[idx].num_channels; i++)
|
||||
sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
|
||||
return devices;
|
||||
return g_slist_append(NULL, sdi);
|
||||
}
|
||||
|
||||
static GSList *scan(GSList *options, int idx)
|
||||
|
|
|
@ -47,11 +47,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct dev_context *devc;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_config *src;
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
const char *conn, *serialcomm;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
conn = serialcomm = NULL;
|
||||
for (l = options; l; l = l->next) {
|
||||
src = l->data;
|
||||
|
@ -79,9 +77,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
sdi->inst_type = SR_INST_SERIAL;
|
||||
sdi->priv = devc;
|
||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
|
|
|
@ -45,10 +45,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct drv_context *drvc;
|
||||
struct sr_config *src;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
GSList *l, *devices;
|
||||
GSList *l;
|
||||
const char *conn, *serialcomm;
|
||||
|
||||
devices = NULL;
|
||||
drvc = di->context;
|
||||
conn = serialcomm = NULL;
|
||||
|
||||
|
@ -91,9 +90,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
sdi->conn = serial;
|
||||
sdi->priv = NULL;
|
||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
|
|
|
@ -259,7 +259,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct sr_channel_group *cg, *acg;
|
||||
struct sr_config *src;
|
||||
struct analog_gen *ag;
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
int num_logic_channels, num_analog_channels, pattern, i;
|
||||
char channel_name[16];
|
||||
|
||||
|
@ -279,8 +279,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
}
|
||||
}
|
||||
|
||||
devices = NULL;
|
||||
|
||||
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
||||
sdi->status = SR_ST_INACTIVE;
|
||||
sdi->model = g_strdup("Demo device");
|
||||
|
@ -344,9 +342,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
}
|
||||
|
||||
sdi->priv = devc;
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int dev_open(struct sr_dev_inst *sdi)
|
||||
|
|
|
@ -68,7 +68,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct sr_dev_inst *sdi;
|
||||
struct drv_context *drvc;
|
||||
struct dev_context *devc;
|
||||
GSList *devices;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
|
||||
|
@ -76,8 +75,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
drvc = di->context;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
/* Allocate memory for our private device context. */
|
||||
devc = g_malloc0(sizeof(struct dev_context));
|
||||
|
||||
|
@ -120,12 +117,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
|
||||
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
/* Close device. We'll reopen it again when we need it. */
|
||||
scanaplus_close(devc);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
|
||||
scanaplus_close(devc);
|
||||
err_free_ftdic:
|
||||
|
|
|
@ -65,7 +65,7 @@ static const struct korad_kaxxxxp_model models[] = {
|
|||
static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_config *src;
|
||||
const char *conn, *serialcomm;
|
||||
|
@ -74,7 +74,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
int i, model_id;
|
||||
unsigned int len;
|
||||
|
||||
devices = NULL;
|
||||
conn = NULL;
|
||||
serialcomm = NULL;
|
||||
|
||||
|
@ -151,13 +150,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
/* Get current status of device. */
|
||||
if (korad_kaxxxxp_get_all_values(serial, devc) < 0)
|
||||
goto exit_err;
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
if (!devices)
|
||||
sr_serial_dev_inst_free(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
|
||||
exit_err:
|
||||
sr_dev_inst_free(sdi);
|
||||
|
|
|
@ -79,12 +79,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct dev_context *devc;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_config *src;
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
const char *conn, *serialcomm;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
char reply[50], **tokens, *dummy;
|
||||
|
||||
devices = NULL;
|
||||
conn = NULL;
|
||||
serialcomm = NULL;
|
||||
devc = NULL;
|
||||
|
@ -174,13 +173,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
devc->voltage_max_device = g_strtod(tokens[0], &dummy) * devc->model->voltage[2];
|
||||
g_strfreev(tokens);
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
if (!devices)
|
||||
sr_serial_dev_inst_free(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
|
||||
exit_err:
|
||||
sr_dev_inst_free(sdi);
|
||||
|
|
|
@ -62,14 +62,12 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
|
|||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
GSList *devices;
|
||||
|
||||
serial = sr_serial_dev_inst_new(conn, serialcomm);
|
||||
|
||||
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
|
||||
return NULL;
|
||||
|
||||
devices = NULL;
|
||||
serial_flush(serial);
|
||||
|
||||
/* TODO: Query device type. */
|
||||
|
@ -93,11 +91,9 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
|
|||
if (mic_devs[idx].has_humidity)
|
||||
sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "Humidity");
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
|
||||
return std_scan_complete(mic_devs[idx].di, devices);
|
||||
return std_scan_complete(mic_devs[idx].di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static GSList *scan(GSList *options, int idx)
|
||||
|
|
|
@ -370,7 +370,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
|
|||
struct sr_serial_dev_inst *serial;
|
||||
struct sr_channel *ch;
|
||||
struct sr_channel_group *cg;
|
||||
GSList *devices;
|
||||
const char *conn, *serialcomm;
|
||||
int cnt, ret;
|
||||
gchar buf[LINELEN_MAX];
|
||||
|
@ -380,7 +379,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
|
|||
sdi = NULL;
|
||||
devc = NULL;
|
||||
conn = serialcomm = NULL;
|
||||
devices = NULL;
|
||||
|
||||
sr_spew("scan() called!");
|
||||
|
||||
|
@ -468,17 +466,13 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
|
|||
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
|
||||
}
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
/* Query status */
|
||||
if (lps_query_status(sdi) != SR_OK)
|
||||
goto exit_err;
|
||||
|
||||
serial_close(serial);
|
||||
if (!devices)
|
||||
sr_serial_dev_inst_free(serial);
|
||||
|
||||
return std_scan_complete(drv, devices);
|
||||
return std_scan_complete(drv, g_slist_append(NULL, sdi));
|
||||
|
||||
exit_err:
|
||||
sr_info("%s: Error!", __func__);
|
||||
|
|
|
@ -90,14 +90,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct sr_config *src;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
GSList *l, *devices;
|
||||
GSList *l;
|
||||
int ret;
|
||||
unsigned int i;
|
||||
const char *conn, *serialcomm;
|
||||
char buf[8];
|
||||
|
||||
devices = NULL;
|
||||
|
||||
conn = serialcomm = NULL;
|
||||
for (l = options; l; l = l->next) {
|
||||
src = l->data;
|
||||
|
@ -191,11 +189,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
sdi->inst_type = SR_INST_SERIAL;
|
||||
sdi->conn = serial;
|
||||
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||
|
|
|
@ -63,7 +63,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct sr_config *src;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
struct sr_dev_inst *sdi;
|
||||
GSList *l, *devices;
|
||||
GSList *l;
|
||||
const char *conn;
|
||||
|
||||
conn = NULL;
|
||||
|
@ -80,8 +80,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
|
||||
return NULL;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
||||
sdi->status = SR_ST_INACTIVE;
|
||||
sdi->vendor = g_strdup("PCE");
|
||||
|
@ -92,11 +90,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
sdi->inst_type = SR_INST_SERIAL;
|
||||
sdi->priv = devc;
|
||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
serial_close(serial);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int dev_clear(const struct sr_dev_driver *di)
|
||||
|
|
|
@ -45,14 +45,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
struct dev_context *devc;
|
||||
struct sr_dev_inst *sdi;
|
||||
struct sr_config *src;
|
||||
GSList *devices, *l;
|
||||
GSList *l;
|
||||
const char *conn, *serialcomm;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
|
||||
drvc = di->context;
|
||||
|
||||
devices = NULL;
|
||||
|
||||
conn = serialcomm = NULL;
|
||||
for (l = options; l; l = l->next) {
|
||||
if (!(src = l->data)) {
|
||||
|
@ -93,9 +91,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
sdi->priv = devc;
|
||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
||||
devices = g_slist_append(devices, sdi);
|
||||
|
||||
return std_scan_complete(di, devices);
|
||||
return std_scan_complete(di, g_slist_append(NULL, sdi));
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
|
|
Loading…
Reference in New Issue