From: Uwe Hermann Date: Fri, 21 Nov 2014 08:07:04 +0000 (+0100) Subject: Don't check sr_channel_new() return value (always succeeds). X-Git-Tag: libsigrok-0.4.0~728 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=c368e6f3d248a73d69cd0c2c4a7c88a92def55e3;p=libsigrok.git Don't check sr_channel_new() return value (always succeeds). We now use g_malloc0() for the allocation and assume the allocation will always succeed, thus sr_channel_new() will always return a valid new channel. --- diff --git a/src/device.c b/src/device.c index 8367ec28..1945f01a 100644 --- a/src/device.c +++ b/src/device.c @@ -48,18 +48,14 @@ * @param[in] enabled @copydoc sr_channel::enabled * @param[in] name @copydoc sr_channel::name * - * @return NULL (failure) or new struct sr_channel*. + * @return A new struct sr_channel*. */ SR_PRIV struct sr_channel *sr_channel_new(int index, int type, gboolean enabled, const char *name) { struct sr_channel *ch; - if (!(ch = g_try_malloc0(sizeof(struct sr_channel)))) { - sr_err("Channel malloc failed."); - return NULL; - } - + ch = g_malloc0(sizeof(struct sr_channel)); ch->index = index; ch->type = type; ch->enabled = enabled; @@ -237,9 +233,6 @@ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, return SR_ERR_ARG; ch = sr_channel_new(index, type, TRUE, name); - if (!ch) - return SR_ERR; - sdi->channels = g_slist_append(sdi->channels, ch); return SR_OK; diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index a41e730a..eb723bfa 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -151,8 +151,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 9cdf9447..c36e72c8 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -110,11 +110,9 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T1"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T1"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T2"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T2"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index c0282746..c577ca74 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -386,8 +386,6 @@ static GSList *scan(GSList *options) for (i = 0; i < ARRAY_SIZE(channel_names); i++) { ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); - if (!ch) - return NULL; sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index a703adf3..46abde3d 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -136,9 +136,8 @@ static GSList *scan(GSList *options) /* Fill the channels */ for (i = 0; i < maxch; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - beaglelogic_channel_names[i]))) - return NULL; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + beaglelogic_channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index c67aba18..65fcb428 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -80,11 +80,9 @@ static GSList *scan(GSList *options) devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P2"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P2"); sdi->channels = g_slist_append(sdi->channels, ch); sdi->inst_type = SR_INST_USB; diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 0db5c2d8..797d05a9 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -85,10 +85,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm) drvc = di->priv; sdi->priv = devc; sdi->driver = di; - - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - goto scan_cleanup; - + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 62f580c5..29db2451 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -126,8 +126,7 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index 8118a2b1..25df2eb0 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -99,16 +99,14 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) sdi->driver = center_devs[idx].di; for (i = 0; i < center_devs[idx].num_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG, - TRUE, channel_names[i]))) - goto scan_cleanup; + ch = sr_channel_new(i, SR_CHANNEL_ANALOG, + TRUE, channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); -scan_cleanup: serial_close(serial); return devices; diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index d9e3cc39..c9d7ec11 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -128,11 +128,8 @@ static int add_device(int idx, int model, GSList **devices) sdi->priv = devc; for (i = 0; i < devc->prof->num_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - cv_channel_names[i]))) { - ret = SR_ERR; - goto err_free_dev_inst; - } + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + cv_channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } @@ -142,9 +139,6 @@ static int add_device(int idx, int model, GSList **devices) if (ret == SR_OK) return SR_OK; -err_free_dev_inst: - sr_dev_inst_free(sdi); - 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 c7d36678..4c35f0fb 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -92,8 +92,7 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index 850e29b0..7f061fbb 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -101,10 +101,8 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->priv = NULL; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); sdi->channels = g_slist_append(sdi->channels, ch); - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index c93542ef..26e49ca9 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -311,8 +311,7 @@ static GSList *scan(GSList *options) cg->name = g_strdup("Logic"); for (i = 0; i < num_logic_channels; i++) { sprintf(channel_name, "D%d", i); - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name))) - return NULL; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); sdi->channels = g_slist_append(sdi->channels, ch); cg->channels = g_slist_append(cg->channels, ch); } diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 4519d3a5..fc3355c2 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -133,8 +133,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) sdi->conn = serial; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 64d3bfea..7559f437 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -253,9 +253,8 @@ static GSList *scan(GSList *options) /* Fill in channellist according to this device's profile. */ num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; for (j = 0; j < num_logic_channels; j++) { - if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, - channel_names[j]))) - return NULL; + ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + channel_names[j]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 02eb6d6e..8e7d2c1b 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -237,8 +237,7 @@ static GSList *scan_1x_2x_rs232(GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = &gmc_mh_1x_2x_rs232_driver_info; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -329,22 +328,17 @@ static GSList *scan_2x_bd232(GSList *options) if (devc->model != METRAHIT_NONE) { sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model)); - devc->elapsed_msec = g_timer_new(); - sdi->model = g_strdup(gmc_model_str(devc->model)); sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min); sdi->conn = serial; sdi->priv = devc; sdi->driver = &gmc_mh_2x_bd232_driver_info; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - goto exit_err; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); - devc = g_malloc0(sizeof(struct dev_context)); - sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(VENDOR_GMC); diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index c97658ea..8f39ba11 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -616,9 +616,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, - (*scope_models[model_index].analog_names)[i]))) - return SR_ERR_MALLOC; + ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, + (*scope_models[model_index].analog_names)[i]); sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); @@ -644,9 +643,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) /* Add digital channels. */ for (i = 0; i < scope_models[model_index].digital_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - (*scope_models[model_index].digital_names)[i]))) - return SR_ERR_MALLOC; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + (*scope_models[model_index].digital_names)[i]); sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_groups[i < 8 ? 0 : 1]->channels = g_slist_append( diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index f3cd8120..ea508c09 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -128,9 +128,8 @@ static GSList *scan(GSList *options) sdi->priv = devc; for (i = 0; channel_names[i]; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - channel_names[i]))) - return NULL; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 04cfb247..0f8304fc 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -136,8 +136,7 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"); sdi->channels = g_slist_append(sdi->channels, ch); devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index c18357b3..801f83b0 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -332,19 +332,15 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config) if (profile->logformat == LOG_TEMP_RH) { /* Model this as two channels: temperature and humidity. */ - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temp"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temp"); sdi->channels = g_slist_append(NULL, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Hum"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Hum"); sdi->channels = g_slist_append(sdi->channels, ch); } else if (profile->logformat == LOG_CO) { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CO"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CO"); sdi->channels = g_slist_append(NULL, ch); } else { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(NULL, ch); } diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 5112fe28..46270ffe 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -220,9 +220,8 @@ static GSList *scan(GSList *options) for (i = 0; i < NUM_CHANNELS; i++) { struct sr_channel *ch; chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC; - if (!(ch = sr_channel_new(i, chtype, TRUE, - mso19_channel_names[i]))) - return 0; + ch = sr_channel_new(i, chtype, TRUE, + mso19_channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index d287067b..6355d004 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -163,10 +163,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) { - sr_err("Failed to create channel."); - goto exit_err; - } + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); sdi->channels = g_slist_append(sdi->channels, ch); devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index ea665046..6e834bd4 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -101,20 +101,17 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sdi->priv = devc; sdi->driver = mic_devs[idx].di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temperature"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temperature"); sdi->channels = g_slist_append(sdi->channels, ch); if (mic_devs[idx].has_humidity) { - if (!(ch = sr_channel_new(1, SR_CHANNEL_ANALOG, TRUE, "Humidity"))) - goto scan_cleanup; + ch = sr_channel_new(1, SR_CHANNEL_ANALOG, TRUE, "Humidity"); sdi->channels = g_slist_append(sdi->channels, ch); } drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); -scan_cleanup: serial_close(serial); return devices; diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index a0e53fc4..34d7de14 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -156,9 +156,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = drv; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, - "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 02cc02b5..cb55bf19 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -187,9 +187,8 @@ static GSList *scan(GSList *options) 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, - ols_channel_names[i]))) - return 0; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } devc = ols_dev_new(); diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 584164e7..b732da59 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -216,9 +216,8 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) case 0x00: /* Number of usable channels */ for (ui = 0; ui < tmp_int; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]))) - return 0; + ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[ui]); sdi->channels = g_slist_append(sdi->channels, ch); } break; @@ -255,9 +254,8 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) case 0x00: /* Number of usable channels */ for (ui = 0; ui < tmp_c; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]))) - return 0; + ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[ui]); sdi->channels = g_slist_append(sdi->channels, ch); } break; diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 7eddec0d..272c8a8c 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -289,9 +289,8 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str case 0x00: /* Number of usable channels */ for (ui = 0; ui < tmp_int; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - p_ols_channel_names[ui]))) - return 0; + ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + p_ols_channel_names[ui]); sdi->channels = g_slist_append(sdi->channels, ch); } break; @@ -326,9 +325,8 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str case 0x00: /* Number of usable channels */ for (ui = 0; ui < tmp_c; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - p_ols_channel_names[ui]))) - return 0; + ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + p_ols_channel_names[ui]); sdi->channels = g_slist_append(sdi->channels, ch); } break; diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index e988741e..1c2a2ba1 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -361,8 +361,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) return NULL; ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); g_free(channel_name); - if (!ch) - return NULL; sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 21ccd557..c30900b2 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -206,9 +206,8 @@ static GSList *scan(GSList *options) sdi->connection_id = g_strdup(connection_id); for (j = 0; channel_names[j]; j++) { - if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, - channel_names[j]))) - return NULL; + ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + channel_names[j]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 268805b0..f240266f 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -465,8 +465,7 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) sdi->conn = serial; sdi->priv = devc; sdi->driver = dmms[dmm].di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 00d058aa..6089f3a5 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -103,55 +103,41 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P"); sdi->channels = g_slist_append(sdi->channels, ch); if (devc->optarif == OPTARIF_BASE) { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "BASE"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "BASE"); sdi->channels = g_slist_append(sdi->channels, ch); } else if (devc->optarif == OPTARIF_HC) { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HP"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HP"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HC"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HC"); sdi->channels = g_slist_append(sdi->channels, ch); } else if (devc->optarif == OPTARIF_EJP) { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HN"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HN"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPM"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPM"); sdi->channels = g_slist_append(sdi->channels, ch); } else if (devc->optarif == OPTARIF_BBR) { - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJB"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJB"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJW"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJW"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJR"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJR"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJB"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJB"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJW"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJW"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJR"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJR"); sdi->channels = g_slist_append(sdi->channels, ch); } - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "IINST"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "IINST"); sdi->channels = g_slist_append(sdi->channels, ch); - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "PAPP"))) - goto scan_cleanup; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "PAPP"); sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index 12026c35..1b40b9f6 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -102,10 +102,6 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - if (!ch) { - sr_err("Failed to create channel."); - return NULL; - } sdi->channels = g_slist_append(sdi->channels, ch); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index 6feefed1..e1580b99 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -252,24 +252,18 @@ static GSList *scan(GSList *options, int dmm) for (l = usb_devices; l; l = l->next) { usb = l->data; - devc = g_malloc0(sizeof(struct dev_context)); - devc->first_run = TRUE; - sdi = g_malloc0(sizeof(struct sr_dev_inst)); 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"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(sdi->channels, ch); - sdi->inst_type = SR_INST_USB; sdi->conn = usb; - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 8c04e64a..aa38cf5f 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -87,11 +87,8 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_USB; sdi->conn = l->data; for (i = 0; i < 3; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, - channels[i]))) { - sr_dbg("Channel malloc failed."); - return NULL; - } + ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, + channels[i]); sdi->channels = g_slist_append(sdi->channels, ch); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index c1620161..de7e94b2 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -92,8 +92,7 @@ static GSList *scan(GSList *options) devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) - return NULL; + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->channels = g_slist_append(NULL, ch); if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), diff --git a/src/hardware/yokogawa-dlm/protocol.c b/src/hardware/yokogawa-dlm/protocol.c index 09d3c9b8..5dc03194 100644 --- a/src/hardware/yokogawa-dlm/protocol.c +++ b/src/hardware/yokogawa-dlm/protocol.c @@ -669,9 +669,8 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index) /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, - (*scope_models[model_index].analog_names)[i]))) - return SR_ERR_MALLOC; + ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, + (*scope_models[model_index].analog_names)[i]); sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); @@ -699,9 +698,8 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index) /* Add digital channels. */ for (i = 0; i < scope_models[model_index].digital_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - (*scope_models[model_index].digital_names)[i]))) - return SR_ERR_MALLOC; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + (*scope_models[model_index].digital_names)[i]); sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_groups[i / 8]->channels = g_slist_append( diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 2cf5aaf1..fa6ef1dc 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -248,9 +248,8 @@ static GSList *scan(GSList *options) /* Fill in channellist according to this device's profile. */ for (j = 0; j < devc->num_channels; j++) { - if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, - channel_names[j]))) - return NULL; + ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + channel_names[j]); sdi->channels = g_slist_append(sdi->channels, ch); } diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index d15c4d38..0c9054a8 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -783,9 +783,7 @@ static int add_channel(struct sr_dev_inst *sdi, const char *name) { struct sr_channel *ch; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, name))) - return SR_ERR; - + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, name); sdi->channels = g_slist_append(sdi->channels, ch); return SR_OK; diff --git a/src/session_file.c b/src/session_file.c index 6433998a..8b4f60b5 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -213,9 +213,8 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) g_variant_new_uint64(total_channels), sdi, NULL); for (p = 0; p < total_channels; p++) { snprintf(channelname, SR_MAX_CHANNELNAME_LEN, "%" PRIu64, p); - if (!(ch = sr_channel_new(p, SR_CHANNEL_LOGIC, TRUE, - channelname))) - return SR_ERR; + ch = sr_channel_new(p, SR_CHANNEL_LOGIC, TRUE, + channelname); sdi->channels = g_slist_append(sdi->channels, ch); } } else if (!strncmp(keys[j], "probe", 5)) {