Consistently use g_malloc0() for allocating devc.

We assume the allocation will always succeed, hence no need for
checking the returned value.
This commit is contained in:
Uwe Hermann 2014-11-21 02:26:24 +01:00
parent aac29cc192
commit f57d8ffe66
34 changed files with 37 additions and 168 deletions

View File

@ -144,10 +144,7 @@ static GSList *scan(GSList *options)
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;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->profile = &supported_agdmm[i];
devc->cur_mq = -1;
sdi->inst_type = SR_INST_SERIAL;

View File

@ -103,14 +103,8 @@ static GSList *scan(GSList *options)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->data_source = DEFAULT_DATA_SOURCE;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;

View File

@ -341,10 +341,7 @@ static GSList *scan(GSList *options)
devices = NULL;
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("%s: devc malloc failed", __func__);
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
ftdi_init(&devc->ftdic);

View File

@ -65,12 +65,11 @@ static int init(struct sr_context *sr_ctx)
return std_init(sr_ctx, di, LOG_PREFIX);
}
static struct dev_context * beaglelogic_devc_alloc(void)
static struct dev_context *beaglelogic_devc_alloc(void)
{
struct dev_context *devc;
/* Allocate zeroed structure */
devc = g_try_malloc0(sizeof(*devc));
devc = g_malloc0(sizeof(struct dev_context));
/* Default non-zero values (if any) */
devc->fd = -1;

View File

@ -77,12 +77,7 @@ static GSList *scan(GSList *options)
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.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
sdi->driver = di;
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1")))

View File

@ -79,12 +79,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
drvc = di->priv;

View File

@ -113,11 +113,7 @@ static GSList *scan(GSList *options)
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.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->cur_mqflags = 0;
devc->recording = -1;
devc->cur_meas_range = 0;

View File

@ -92,15 +92,9 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = center_devs[idx].di;

View File

@ -87,7 +87,7 @@ static int add_device(int idx, int model, GSList **devices)
drvc = di->priv;
/* Allocate memory for our private device context. */
devc = g_try_malloc(sizeof(struct dev_context));
devc = g_malloc0(sizeof(struct dev_context));
/* Set some sane defaults. */
devc->prof = &cv_profiles[model];

View File

@ -86,15 +86,9 @@ static GSList *scan(GSList *options)
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.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
if (!(sdi->conn = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
sdi->driver = di;

View File

@ -127,10 +127,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
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;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->profile = &supported_flukedmm[i];
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;

View File

@ -299,11 +299,7 @@ SR_PRIV struct dev_context *fx2lafw_dev_new(void)
{
struct dev_context *devc;
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->profile = NULL;
devc->fw_updated = 0;
devc->cur_samplerate = 0;

View File

@ -227,17 +227,13 @@ static GSList *scan_1x_2x_rs232(GSList *options)
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;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->model = model;
devc->limit_samples = 0;
devc->limit_msec = 0;
devc->num_samples = 0;
devc->elapsed_msec = g_timer_new();
devc->settings_ok = FALSE;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = &gmc_mh_1x_2x_rs232_driver_info;
@ -299,10 +295,7 @@ static GSList *scan_2x_bd232(GSList *options)
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
goto exit_err;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
goto exit_err;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
@ -350,10 +343,7 @@ static GSList *scan_2x_bd232(GSList *options)
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
goto exit_err;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;

View File

@ -92,8 +92,7 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi
sr_scpi_hw_info_free(hw_info);
hw_info = NULL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
goto fail;
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;

View File

@ -91,11 +91,7 @@ static GSList *scan(GSList *options)
continue;
}
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("Device instance malloc failed.");
sr_usb_dev_inst_free(usb);
continue;
}
devc = g_malloc0(sizeof(struct dev_context));
if (!(devc->xfer_in = libusb_alloc_transfer(0))) {
sr_err("Transfer malloc failed.");

View File

@ -88,10 +88,7 @@ static GSList *scan(GSList *options)
devices = NULL;
/* Allocate memory for our private device context. */
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
goto err_free_nothing;
}
devc = g_malloc0(sizeof(struct dev_context));
/* Allocate memory for the incoming compressed samples. */
if (!(devc->compressed_buf = g_try_malloc0(COMPRESSED_BUF_SIZE))) {
@ -154,7 +151,6 @@ err_free_compressed_buf:
g_free(devc->compressed_buf);
err_free_devc:
g_free(devc);
err_free_nothing:
return NULL;
}

View File

@ -139,11 +139,7 @@ static GSList *scan(GSList *options)
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL")))
return NULL;
sdi->channels = g_slist_append(sdi->channels, ch);
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_dbg("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->limit_samples = 0;
/* The protocol provides no way to read the current

View File

@ -348,8 +348,7 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
sdi->channels = g_slist_append(NULL, ch);
}
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return NULL;
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->profile = profile;
}

View File

@ -178,10 +178,7 @@ static GSList *scan(GSList *options)
//Create the device context and set its params
struct dev_context *devc;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return devices;
}
devc = g_malloc0(sizeof(struct dev_context));
if (mso_parse_serial(iSerial, iProduct, devc) != SR_OK) {
sr_err("Invalid iSerial: %s.", iSerial);

View File

@ -95,15 +95,9 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = mic_devs[idx].di;

View File

@ -149,14 +149,10 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options)
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;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->type = auxtype;
devc->version = g_strdup(&buf[9]);
devc->elapsed_msec = g_timer_new();
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = drv;

View File

@ -124,10 +124,7 @@ SR_PRIV struct dev_context *ols_dev_new(void)
{
struct dev_context *devc;
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
/* Device-specific settings */
devc->max_samples = devc->max_samplerate = devc->protocol_version = 0;

View File

@ -100,10 +100,7 @@ static GSList *scan(GSList *options)
devices = NULL;
/* Allocate memory for our private device context. */
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
goto err_free_nothing;
}
devc = g_malloc0(sizeof(struct dev_context));
/* Device-specific settings */
devc->max_samplebytes = devc->max_samplerate = devc->protocol_version = 0;
@ -204,7 +201,6 @@ err_free_ftdi_buf:
g_free(devc->ftdi_buf);
err_free_devc:
g_free(devc);
err_free_nothing:
return NULL;
}

View File

@ -305,10 +305,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
sdi->driver = di;
sdi->inst_type = SR_INST_SCPI;
sdi->serial_num = g_strdup(hw_info->serial_number);
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return NULL;
devc = g_malloc0(sizeof(struct dev_context));
devc->limit_frames = 0;
devc->model = model;
devc->format = model->series->format;

View File

@ -212,8 +212,7 @@ static GSList *scan(GSList *options)
sdi->channels = g_slist_append(sdi->channels, ch);
}
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return NULL;
devc = g_malloc0(sizeof(struct dev_context));
devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
sdi->priv = devc;
drvc->instances = g_slist_append(drvc->instances, sdi);

View File

@ -460,15 +460,9 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = dmms[dmm].di;
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1")))

View File

@ -105,11 +105,7 @@ static struct sr_dev_inst *dev_inst_new(void)
struct dev_context *devc;
/* Allocate memory for our private driver context. */
devc = g_try_new0(struct dev_context, 1);
if (!devc) {
sr_err("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
/* Register the device with libsigrok. */
sdi = g_malloc0(sizeof(struct sr_dev_inst));

View File

@ -96,14 +96,8 @@ static GSList *scan(GSList *options)
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->optarif = teleinfo_get_optarif(buf);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;

View File

@ -88,11 +88,7 @@ static GSList *scan(GSList *options)
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.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;

View File

@ -253,10 +253,7 @@ static GSList *scan(GSList *options, int dmm)
for (l = usb_devices; l; l = l->next) {
usb = l->data;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
devc->first_run = TRUE;

View File

@ -94,11 +94,7 @@ static GSList *scan(GSList *options)
}
sdi->channels = g_slist_append(sdi->channels, ch);
}
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_dbg("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->limit_samples = 0;
devc->data_source = DEFAULT_DATA_SOURCE;

View File

@ -89,9 +89,7 @@ static GSList *scan(GSList *options)
sdi->vendor = g_strdup(VICTOR_VENDOR);
sdi->driver = di;
sdi->connection_id = g_strdup(connection_id);
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return NULL;
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1")))

View File

@ -231,11 +231,7 @@ static GSList *scan(GSList *options)
sdi->connection_id = g_strdup(connection_id);
/* Allocate memory for our private driver context. */
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return NULL;
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->prof = prof;
devc->num_channels = prof->channels;

View File

@ -847,11 +847,7 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
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.");
goto scan_cleanup;
}
devc = g_malloc0(sizeof(struct dev_context));
if (!(devc->buf = dev_buffer_new(PACKET_SIZE * 8)))
goto scan_cleanup;