From: Uwe Hermann Date: Wed, 12 Nov 2014 01:06:15 +0000 (+0100) Subject: Change sr_dev_inst_new() to take no parameters. X-Git-Tag: libsigrok-0.4.0~786 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=0af636bed97c174bea46e61e961eaa1b0b162e0f Change sr_dev_inst_new() to take no parameters. Change all callers to set the fields manually as needed. --- diff --git a/src/device.c b/src/device.c index fb40182c..a45bd982 100644 --- a/src/device.c +++ b/src/device.c @@ -203,32 +203,22 @@ SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key) /** @private * Allocate and init a new device instance struct. - * @param[in] index @copydoc sr_dev_inst::index - * @param[in] status @copydoc sr_dev_inst::status - * @param[in] vendor @copydoc sr_dev_inst::vendor - * @param[in] model @copydoc sr_dev_inst::model - * @param[in] version @copydoc sr_dev_inst::version * - * @retval NULL Error * @retval struct sr_dev_inst *. Dynamically allocated, free using * sr_dev_inst_free(). */ -SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status, - const char *vendor, const char *model, const char *version) +SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void) { struct sr_dev_inst *sdi; - if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) { - sr_err("Device instance malloc failed."); - return NULL; - } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->driver = NULL; - sdi->status = status; + sdi->status = -1; sdi->inst_type = -1; - sdi->vendor = vendor ? g_strdup(vendor) : NULL; - sdi->model = model ? g_strdup(model) : NULL; - sdi->version = version ? g_strdup(version) : NULL; + sdi->vendor = NULL; + sdi->model = NULL; + sdi->version = NULL; sdi->serial_num = NULL; sdi->connection_id = NULL; sdi->channels = NULL; @@ -248,10 +238,10 @@ SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor, { struct sr_dev_inst *sdi; - sdi = sr_dev_inst_new(0, vendor, model, version); - if (!sdi) - return NULL; - + sdi = sr_dev_inst_new(); + sdi->vendor = g_strdup(vendor); + sdi->model = g_strdup(model); + sdi->version = g_strdup(version); sdi->inst_type = SR_INST_USER; return sdi; diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 084f9b4d..9dcbd230 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -136,9 +136,11 @@ static GSList *scan(GSList *options) for (i = 0; supported_agdmm[i].model; i++) { if (strcmp(supported_agdmm[i].modelname, tokens[1])) continue; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Agilent", - tokens[1], tokens[3]))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Agilent"); + sdi->model = g_strdup(tokens[1]); + sdi->version = g_strdup(tokens[3]); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index ab3ad790..01c5f5ba 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -96,8 +96,10 @@ static GSList *scan(GSList *options) sr_info("Found device on port %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "APPA", "55II", NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("APPA"); + sdi->model = g_strdup("55II"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index 3a15b281..24c786da 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -380,11 +380,10 @@ static GSList *scan(GSList *options) devc->use_triggers = 0; /* Register SIGMA device. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INITIALIZING, USB_VENDOR_NAME, - USB_MODEL_NAME, NULL))) { - sr_err("%s: sdi was NULL", __func__); - goto free; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(USB_VENDOR_NAME); + sdi->model = g_strdup(USB_MODEL_NAME); sdi->driver = di; for (i = 0; i < ARRAY_SIZE(channel_names); i++) { diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index f29377e3..2a3ac8f5 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -164,7 +164,10 @@ static GSList *scan(GSList *options, int modelid) return NULL; } - sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Atten", model->name, NULL); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Atten"); + sdi->model = g_strdup(model->name); sdi->driver = di; sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 9abbbefc..910bb843 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -97,7 +97,10 @@ static GSList *scan(GSList *options) if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) return NULL; - sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, "BeagleLogic", "1.0"); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->model = g_strdup("BeagleLogic"); + sdi->version = g_strdup("1.0"); sdi->driver = di; /* Unless explicitly specified, keep max channels to 8 only */ diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index f2253541..c38665c1 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -73,11 +73,10 @@ static GSList *scan(GSList *options) for (l = usb_devices; l; l = l->next) { usb = l->data; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, - "Brymen", "BM869", NULL))) { - sr_err("sr_dev_inst_new returned NULL."); - return NULL; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Brymen"); + sdi->model = g_strdup("BM869"); if (!(devc = g_try_malloc0(sizeof(*devc)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 0a10956b..210d7e61 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -75,8 +75,10 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm) sr_info("Found device on port %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Brymen", "BM85x", NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Brymen"); + sdi->model = g_strdup("BM85x"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 4cd0ccb6..252946e3 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -109,9 +109,10 @@ static GSList *scan(GSList *options) while (g_get_monotonic_time() - start < MAX_SCAN_TIME) { if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) { /* Found one. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "CEM", - "DT-885x", NULL))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("CEM"); + sdi->model = g_strdup("DT-885x"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_dbg("Device context malloc failed."); diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index 9226c5a0..0d671fbf 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -85,9 +85,10 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) sr_info("Found device on port %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, center_devs[idx].vendor, - center_devs[idx].device, NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(center_devs[idx].vendor); + sdi->model = g_strdup(center_devs[idx].device); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index d65dabb6..3dc0598e 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -120,13 +120,10 @@ static int add_device(int idx, int model, GSList **devices) devc->cur_samplerate = devc->prof->max_samplerate; /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, - "ChronoVu", devc->prof->modelname, NULL); - if (!sdi) { - sr_err("Failed to create device instance."); - ret = SR_ERR; - goto err_free_final_buf; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup("ChronoVu"); + sdi->model = g_strdup(devc->prof->modelname); sdi->driver = di; sdi->priv = devc; @@ -147,7 +144,6 @@ static int add_device(int idx, int model, GSList **devices) err_free_dev_inst: sr_dev_inst_free(sdi); -err_free_final_buf: g_free(devc->final_buf); err_free_devc: g_free(devc); diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index 9ea44178..fa941196 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -82,9 +82,10 @@ static GSList *scan(GSList *options) if (!serialcomm) serialcomm = SERIALCOMM; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Colead", - "SL-5868P", NULL))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Colead"); + sdi->model = g_strdup("SL-5868P"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_dbg("Device context malloc failed."); diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index e820e253..8a9650ec 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -94,9 +94,10 @@ static GSList *scan(GSList *options) sr_spew("Conrad DIGI 35 CPU assumed at %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, "Conrad", "DIGI 35 CPU", NULL))) - return NULL; - + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup("Conrad"); + sdi->model = g_strdup("DIGI 35 CPU"); sdi->conn = serial; sdi->priv = NULL; sdi->driver = di; diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index 2a8ea234..b5cb276c 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -289,11 +289,10 @@ static GSList *scan(GSList *options) } devices = NULL; - sdi = sr_dev_inst_new(SR_ST_ACTIVE, "Demo device", NULL, NULL); - if (!sdi) { - sr_err("Device instance creation failed."); - return NULL; - } + + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->model = "Demo device"; sdi->driver = di; devc = g_malloc(sizeof(struct dev_context)); diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 7ece6487..b7638fa2 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -122,9 +122,11 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) continue; /* Skip leading spaces in version number. */ for (s = 0; tokens[1][s] == ' '; s++); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Fluke", - tokens[0] + 6, tokens[1] + s))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Fluke"); + sdi->model = g_strdup(tokens[0] + 6); + sdi->version = g_strdup(tokens[1] + s); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index a4a679a4..41f71d1b 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -238,10 +238,11 @@ static GSList *scan(GSList *options) if (!prof) continue; - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, - prof->vendor, prof->model, prof->model_version); - if (!sdi) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(prof->vendor); + sdi->model = g_strdup(prof->model); + sdi->version = g_strdup(prof->model_version); sdi->driver = di; sdi->serial_num = g_strdup(serial_num); sdi->connection_id = g_strdup(connection_id); diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 7c7ca88e..464fe502 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -223,9 +223,10 @@ static GSList *scan_1x_2x_rs232(GSList *options) if (model != METRAHIT_NONE) { sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model)); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, - gmc_model_str(model), NULL))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_GMC); + sdi->model = g_strdup(gmc_model_str(model)); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; @@ -303,9 +304,9 @@ static GSList *scan_2x_bd232(GSList *options) goto exit_err; } - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL))) - goto exit_err; - + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_GMC); sdi->priv = devc; /* Send message 03 "Query multimeter version and status" */ @@ -354,8 +355,9 @@ static GSList *scan_2x_bd232(GSList *options) goto exit_err; } - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL))) - goto exit_err; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_GMC); } }; diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 31c11e2b..f9ba81b8 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -75,16 +75,15 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi if (check_manufacturer(hw_info->manufacturer) != SR_OK) goto fail; - if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, - hw_info->manufacturer, hw_info->model, - hw_info->firmware_version))) { - goto fail; - } - + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup(hw_info->manufacturer); + sdi->model = g_strdup(hw_info->model); + sdi->version = g_strdup(hw_info->firmware_version); + sdi->serial_num = g_strdup(hw_info->serial_number); sdi->driver = di; sdi->inst_type = SR_INST_SCPI; sdi->conn = scpi; - sdi->serial_num = g_strdup(hw_info->serial_number); sr_scpi_hw_info_free(hw_info); hw_info = NULL; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index e6420a24..201518a4 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -172,7 +172,10 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) struct dev_context *devc; int i; - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, prof->vendor, prof->model, NULL); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(prof->vendor); + sdi->model = g_strdup(prof->model); sdi->driver = di; /* diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 89d12ea9..d459210f 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -70,7 +70,6 @@ static GSList *scan(GSList *options) struct sr_usb_dev_inst *usb; struct device_info dev_info; int ret, i; - char *fw_ver_str; (void)options; @@ -113,34 +112,16 @@ static GSList *scan(GSList *options) continue; } - fw_ver_str = g_strdup_printf("%u.%u", dev_info.fw_ver_major, - dev_info.fw_ver_minor); - if (!fw_ver_str) { - sr_err("Firmware string malloc failed."); - sr_usb_dev_inst_free(usb); - libusb_free_transfer(devc->xfer_in); - libusb_free_transfer(devc->xfer_out); - g_free(devc); - continue; - } - - sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_NAME, - MODEL_NAME, fw_ver_str); - g_free(fw_ver_str); - if (!sdi) { - sr_err("sr_dev_inst_new failed."); - sr_usb_dev_inst_free(usb); - libusb_free_transfer(devc->xfer_in); - libusb_free_transfer(devc->xfer_out); - g_free(devc); - continue; - } - + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_NAME); + sdi->model = g_strdup(MODEL_NAME); + sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor); + sdi->serial_num = g_strdup_printf("%d", dev_info.serial); sdi->priv = devc; sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = usb; - sdi->serial_num = g_strdup_printf("%d", dev_info.serial); for (i = 0; channel_names[i]; i++) { ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 95bd3c1a..50753646 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -123,12 +123,10 @@ static GSList *scan(GSList *options) } /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, - USB_VENDOR_NAME, USB_MODEL_NAME, NULL); - if (!sdi) { - sr_err("Failed to create device instance."); - goto err_close_ftdic; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(USB_VENDOR_NAME); + sdi->model = g_strdup(USB_MODEL_NAME); sdi->driver = di; sdi->priv = devc; @@ -147,7 +145,6 @@ static GSList *scan(GSList *options) return devices; -err_close_ftdic: scanaplus_close(devc); err_free_ftdic: ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 0e5baef5..721ceda1 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -129,10 +129,10 @@ static GSList *scan(GSList *options) for (l = usb_devices; l; l = l->next) { if (scan_kecheng(l->data, &model) != SR_OK) continue; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR, - model, NULL))) - return NULL; - g_free(model); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR); + sdi->model = model; /* Already g_strndup()'d. */ sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index 7459a1f1..ab5b6734 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -323,9 +323,11 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config) return NULL; } - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, LASCAR_VENDOR, - profile->modelname, firmware))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(LASCAR_VENDOR); + sdi->model = g_strdup(profile->modelname); + sdi->version = g_strdup(firmware); sdi->driver = di; if (profile->logformat == LOG_TEMP_RH) { diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index fad2e8da..6be41b9f 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -150,12 +150,10 @@ static GSList *scan(GSList *options) } /* Init device instance, etc. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Manson", - models[model_id].name, NULL))) { - sr_err("Failed to create device instance."); - return NULL; - } - + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Manson"); + sdi->model = g_strdup(models[model_id].name); sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->driver = di; diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index eb5d25d4..5969b103 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -84,9 +84,10 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sr_info("Found device on port %s.", conn); /* TODO: Fill in version from protocol response. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, mic_devs[idx].vendor, - mic_devs[idx].device, NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(mic_devs[idx].vendor); + sdi->model = g_strdup(mic_devs[idx].device); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index bcbc2954..40bb2d95 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -375,9 +375,9 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o GSList *devices; const char *conn, *serialcomm; int cnt; - gchar buf[LINELEN_MAX]; + gchar buf[LINELEN_MAX]; gchar channel[10]; - char* verstr; + char *verstr; sdi = NULL; devc = NULL; @@ -444,7 +444,11 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o Therefore just print an error message, but do not exit with error. */ sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno)); - sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_MOTECH, models[modelid].modelstr, verstr); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_MOTECH); + sdi->model = g_strdup(models[modelid].modelstr); + sdi->version = g_strdup(verstr); sdi->driver = drv; sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index f95e7398..ab9b36e2 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -144,9 +144,11 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) auxtype = xgittoint(buf[7]); sr_spew("%s %s DMM %s detected!", get_brandstr(drv), get_typestr(auxtype, drv), buf + 9); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, - get_brandstr(drv), get_typestr(auxtype, drv), buf + 9))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(get_brandstr(drv)); + sdi->model = g_strdup(get_typestr(auxtype, drv)); + sdi->version = g_strdup(buf + 9); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index aaf42ab8..174d333d 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -177,8 +177,11 @@ static GSList *scan(GSList *options) } else { /* Not an OLS -- some other board that uses the sump protocol. */ sr_info("Device does not support metadata."); - sdi = sr_dev_inst_new(SR_ST_INACTIVE, - "Sump", "Logic Analyzer", "v1.0"); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Sump"); + sdi->model = g_strdup("Logic Analyzer"); + sdi->version = g_strdup("v1.0"); sdi->driver = di; for (i = 0; i < 32; i++) { if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 0a816d01..c2b66615 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -152,7 +152,8 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) GString *tmp_str, *devname, *version; guchar tmp_c; - sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; sdi->driver = di; devc = ols_dev_new(); sdi->priv = devc; diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 62d77e96..81bbe8e6 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -226,7 +226,8 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str guchar tmp_c; int index, i; - sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; sdi->driver = di; sdi->priv = devc; diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 0234c9c0..76327662 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -291,14 +291,16 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } } - if (!model || !(sdi = sr_dev_inst_new(SR_ST_ACTIVE, - model->series->vendor->name, - model->name, - hw_info->firmware_version))) { + if (!model) { sr_scpi_hw_info_free(hw_info); return NULL; } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup(model->series->vendor->name); + sdi->model = g_strdup(model->name); + sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; sdi->driver = di; sdi->inst_type = SR_INST_SCPI; diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index bc5a3b9a..f151fbd9 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -198,10 +198,10 @@ static GSList *scan(GSList *options) if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID) continue; - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, - "Saleae", "Logic16", NULL); - if (!sdi) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup("Saleae"); + sdi->model = g_strdup("Logic16"); sdi->driver = di; sdi->connection_id = g_strdup(connection_id); diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index c8502fc5..b62574e2 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -90,8 +90,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) return NULL; } - sdi = sr_dev_inst_new(SR_ST_ACTIVE, vendor, hw_info->model, - hw_info->firmware_version); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup(vendor); + sdi->model = g_strdup(hw_info->model); + sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; sdi->driver = di; sdi->inst_type = SR_INST_SCPI; diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 70f05f2d..87e63b10 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -456,9 +456,10 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) sr_info("Found device on port %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, dmms[dmm].vendor, - dmms[dmm].device, NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(dmms[dmm].vendor); + sdi->model = g_strdup(dmms[dmm].device); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 11d78d49..f2fc1916 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -99,7 +99,7 @@ static GSList *gen_channel_list(int num_channels) return list; } -static struct sr_dev_inst *dev_inst_new() +static struct sr_dev_inst *dev_inst_new(void) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -112,13 +112,10 @@ static struct sr_dev_inst *dev_inst_new() } /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(SR_ST_INACTIVE, - VENDOR_NAME, MODEL_NAME, NULL); - if (!sdi) { - sr_err("Failed to instantiate device."); - g_free(devc); - return NULL; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_NAME); + sdi->model = g_strdup(MODEL_NAME); /* Enable all channels to match the default channel configuration. */ devc->channel_mask = ALL_CHANNELS_MASK; diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 63432f58..3e6a4d45 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -92,8 +92,10 @@ static GSList *scan(GSList *options) sr_info("Found device on port %s.", conn); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "EDF", "Teleinfo", NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("EDF"); + sdi->model = g_strdup("Teleinfo"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 3ceb0869..6f0e4e1a 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -124,8 +124,10 @@ static GSList *scan(GSList *options) if (strcmp(product, "testo 435/635/735")) continue; - sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Testo", - "435/635/735", NULL); + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Testo"); + sdi->model = g_strdup("435/635/735"); sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index 4578c21f..d725ec35 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -84,11 +84,10 @@ static GSList *scan(GSList *options) if (!serialcomm) serialcomm = SERIALCOMM; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Tondaj", - "SL-814", NULL))) { - sr_err("Failed to create device instance."); - return NULL; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Tondaj"); + sdi->model = g_strdup("SL-814"); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index a69885d6..35ceaaed 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -260,11 +260,10 @@ static GSList *scan(GSList *options, int dmm) devc->first_run = TRUE; - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, - udmms[dmm].vendor, udmms[dmm].device, NULL))) { - sr_err("sr_dev_inst_new returned NULL."); - return NULL; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(udmms[dmm].vendor); + sdi->model = g_strdup(udmms[dmm].device); sdi->priv = devc; sdi->driver = udmms[dmm].di; if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index ab1618e8..a50d4a4f 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -79,9 +79,10 @@ static GSList *scan(GSList *options) /* We have a list of sr_usb_dev_inst matching the connection * string. Wrap them in sr_dev_inst and we're done. */ for (l = usb_devices; l; l = l->next) { - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR, - MODEL, NULL))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR); + sdi->model = g_strdup(MODEL); sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 7ce468e5..fe419443 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -82,9 +82,9 @@ static GSList *scan(GSList *options) usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, - VICTOR_VENDOR, NULL, NULL))) - return NULL; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VICTOR_VENDOR); sdi->driver = di; sdi->connection_id = g_strdup(connection_id); diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 23d21185..48e9a0ce 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -62,9 +62,11 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK) goto fail; - if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, MANUFACTURER_NAME, - model_name, hw_info->firmware_version))) - goto fail; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_ACTIVE; + sdi->vendor = g_strdup(MANUFACTURER_NAME); + sdi->model = g_strdup(model_name); + sdi->version = g_strdup(hw_info->firmware_version); sdi->serial_num = g_strdup(hw_info->serial_number); diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 3eeb9811..76ae1e33 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -222,11 +222,10 @@ static GSList *scan(GSList *options) sr_info("Found ZEROPLUS %s.", prof->model_name); /* Register the device with libsigrok. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, - VENDOR_NAME, prof->model_name, NULL))) { - sr_err("%s: sr_dev_inst_new failed", __func__); - return NULL; - } + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_NAME); + sdi->model = g_strdup(prof->model_name); sdi->driver = di; sdi->serial_num = g_strdup(serial_num); sdi->connection_id = g_strdup(connection_id); diff --git a/src/input/binary.c b/src/input/binary.c index 813cf4a4..b3f12d76 100644 --- a/src/input/binary.c +++ b/src/input/binary.c @@ -50,7 +50,7 @@ static int init(struct sr_input *in, GHashTable *options) return SR_ERR_ARG; } - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = sr_dev_inst_new(); in->priv = inc = g_malloc0(sizeof(struct context)); inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate")); diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index 55331df8..c1cf4d38 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -62,7 +62,7 @@ static int init(struct sr_input *in, GHashTable *options) return SR_ERR_ARG; } - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = sr_dev_inst_new(); in->priv = inc = g_malloc0(sizeof(struct context)); inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate")); diff --git a/src/input/csv.c b/src/input/csv.c index 49bd73c8..b2756fa0 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -393,7 +393,7 @@ static int init(struct sr_input *in, GHashTable *options) struct context *inc; const char *s; - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = sr_dev_inst_new(); in->priv = inc = g_malloc0(sizeof(struct context)); inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column")); diff --git a/src/input/vcd.c b/src/input/vcd.c index ef78c9fe..e6bc05e5 100644 --- a/src/input/vcd.c +++ b/src/input/vcd.c @@ -429,7 +429,7 @@ static int init(struct sr_input *in, GHashTable *options) inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip")); inc->skip /= inc->downsample; - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = sr_dev_inst_new(); in->priv = inc; for (i = 0; i < num_channels; i++) { diff --git a/src/input/wav.c b/src/input/wav.c index 1c0d4fd1..8f8a3710 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -150,7 +150,7 @@ static int init(struct sr_input *in, GHashTable *options) { (void)options; - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = sr_dev_inst_new(); in->priv = g_malloc0(sizeof(struct context)); return SR_OK; diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index b8773493..4cacbe9a 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -843,8 +843,10 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options, sr_info("Found device on port %s.", serial->port); - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, vendor, model, NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(vendor); + sdi->model = g_strdup(model); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 9e393f42..f98a35a8 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -521,8 +521,7 @@ struct sr_dev_inst { }; /* Generic device instances */ -SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status, - const char *vendor, const char *model, const char *version); +SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void); SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi); #ifdef HAVE_LIBUSB_1_0 diff --git a/src/session_file.c b/src/session_file.c index bd5b827f..9f8ee756 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -170,8 +170,9 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) for (j = 0; keys[j]; j++) { val = g_key_file_get_string(kf, sections[i], keys[j], NULL); if (!strcmp(keys[j], "capturefile")) { - sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + sdi = sr_dev_inst_new(); sdi->driver = &session_driver; + sdi->status = SR_ST_ACTIVE; if (!session_driver_initialized) { /* first device, init the driver */ session_driver_initialized = 1;