As per documented rules in HACKING, we don't check "small" allocations.
}
len = 128;
- if (!(buf = g_try_malloc(len))) {
- sr_err("Serial buffer malloc failed.");
- return NULL;
- }
+ buf = g_malloc(len);
serial_readline(serial, &buf, &len, 250);
if (!len)
return NULL;
while (*e && *e == ' ')
e++;
- if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
- return NULL;
- if (!(analog->data = g_try_malloc(sizeof(float))))
- return NULL;
+ analog = g_malloc0(sizeof(struct sr_datafeed_analog));
+ analog->data = g_malloc(sizeof(float));
analog->channels = sdi->channels;
analog->num_samples = 1;
if (is_oor)
return NULL;
}
- if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
- return NULL;
- if (!(analog->data = g_try_malloc(sizeof(float))))
- return NULL;
+ analog = g_malloc0(sizeof(struct sr_datafeed_analog));
+ analog->data = g_malloc(sizeof(float));
analog->channels = sdi->channels;
analog->num_samples = 1;
*analog->data = fvalue;
{
struct scope_state *state;
- if (!(state = g_try_malloc0(sizeof(struct scope_state))))
- return NULL;
-
- if (!(state->analog_channels = g_try_malloc0_n(config->analog_channels,
- sizeof(struct analog_channel_state))))
- goto fail;
-
- if (!(state->digital_channels = g_try_malloc0_n(
- config->digital_channels, sizeof(gboolean))))
- goto fail;
-
- if (!(state->digital_pods = g_try_malloc0_n(config->digital_pods,
- sizeof(gboolean))))
- goto fail;
+ state = g_malloc0(sizeof(struct scope_state));
+ state->analog_channels = g_malloc0_n(config->analog_channels,
+ sizeof(struct analog_channel_state));
+ state->digital_channels = g_malloc0_n(
+ config->digital_channels, sizeof(gboolean));
+ state->digital_pods = g_malloc0_n(config->digital_pods,
+ sizeof(gboolean));
return state;
-
-fail:
- if (state->analog_channels)
- g_free(state->analog_channels);
- if (state->digital_channels)
- g_free(state->digital_channels);
- if (state->digital_pods)
- g_free(state->digital_pods);
- g_free(state);
-
- return NULL;
}
SR_PRIV void hmo_scope_state_free(struct scope_state *state)
}
} else {
/* Already past the trigger point, just send it all out. */
- send_chunk(sdi, transfer->buffer,
- num_samples);
+ send_chunk(sdi, transfer->buffer, num_samples);
}
devc->samp_received += num_samples;
devc->trigger_offset = trigger_offset;
num_channels = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1;
- /* TODO: Check malloc return value. */
- devc->framebuf = g_try_malloc(devc->framesize * num_channels * 2);
+ devc->framebuf = g_malloc(devc->framesize * num_channels * 2);
devc->samp_buffered = devc->samp_received = 0;
/* Tell the scope to send us the first frame. */
usb_source_add(sdi->session, drvc->sr_ctx, 100,
lascar_el_usb_handle_events, (void *)sdi);
- buf = g_try_malloc(4096);
+ buf = g_malloc(4096);
libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN,
buf, 4096, lascar_el_usb_receive_transfer, cb_data, 100);
if ((ret = libusb_submit_transfer(xfer_in) != 0)) {
if (serial->fd < 0)
goto ret;
- if (!(buf = g_try_malloc(s))) {
- sr_err("Failed to malloc message buffer.");
- ret = SR_ERR_MALLOC;
- goto ret;
- }
+ buf = g_malloc(s);
p = buf;
memcpy(p, mso_head, sizeof(mso_head));
serial_flush(serial);
- if (!(buf = g_try_malloc(BUF_MAX))) {
- sr_err("Serial buffer malloc failed.");
- return NULL;
- }
+ buf = g_malloc(BUF_MAX);
snprintf(req, sizeof(req), "%s\r\n",
nmadmm_requests[NMADMM_REQ_IDN].req_str);
devc->flag_reg = 0;
/* Allocate memory for the incoming ftdi data. */
- if (!(devc->ftdi_buf = g_try_malloc0(FTDI_BUF_SIZE))) {
- sr_err("ftdi_buf malloc failed.");
- goto err_free_devc;
- }
+ devc->ftdi_buf = g_malloc0(FTDI_BUF_SIZE);
/* Allocate memory for the FTDI context (ftdic) and initialize it. */
if (!(devc->ftdic = ftdi_new())) {
ftdi_free(devc->ftdic); /* NOT free() or g_free()! */
err_free_ftdi_buf:
g_free(devc->ftdi_buf);
-err_free_devc:
g_free(devc);
return NULL;
devc->num_timebases = &timebases[i] - devc->timebases + 1;
}
- for (i = 0; i < NUM_VDIV; i++)
- if (!memcmp(&devc->model->series->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) {
+ for (i = 0; i < NUM_VDIV; i++) {
+ if (!memcmp(&devc->model->series->min_vdiv,
+ &vdivs[i], sizeof(uint64_t[2]))) {
devc->vdivs = &vdivs[i];
devc->num_vdivs = NUM_VDIV - i;
}
+ }
- if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
- return NULL;
- if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
- return NULL;
+ devc->buffer = g_malloc(ACQ_BUFFER_SIZE);
+ devc->data = g_malloc(ACQ_BUFFER_SIZE * sizeof(float));
devc->data_source = DATA_SOURCE_LIVE;
{
struct acquisition_state *acq;
- acq = g_try_new0(struct acquisition_state, 1);
- if (!acq) {
- sr_err("Acquisition state malloc failed.");
- return NULL;
- }
+ acq = g_malloc0(sizeof(struct acquisition_state));
acq->xfer_in = libusb_alloc_transfer(0);
if (!acq->xfer_in) {
if (testo_request_packet(sdi) != SR_OK)
return SR_ERR;
- buf = g_try_malloc(MAX_REPLY_SIZE);
+ buf = g_malloc(MAX_REPLY_SIZE);
transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, usb->devhdl, EP_IN, buf,
MAX_REPLY_SIZE, receive_transfer, (void *)sdi, 100);
usb_source_add(sdi->session, drvc->sr_ctx, 100,
handle_events, (void *)sdi);
- buf = g_try_malloc(DMM_DATA_SIZE);
+ buf = g_malloc(DMM_DATA_SIZE);
transfer = libusb_alloc_transfer(0);
/* Each transfer request gets 100ms to arrive before it's restarted.
* The device only sends 1 transfer/second no matter how many
return SR_OK;
}
- if (!(buf = g_try_malloc(PACKET_SIZE))) {
- sr_err("Packet buffer malloc failed.");
- return SR_ERR_MALLOC;
- }
+ buf = g_malloc(PACKET_SIZE);
/* Check if the trigger is in the samples we are throwing away */
trigger_now = now_address == trigger_address ||
}
}
- if (!(buf = g_try_malloc(CHUNKSIZE))) {
- sr_err("%s: buf malloc failed", __func__);
- return FALSE;
- }
+ buf = g_malloc(CHUNKSIZE);
ret = zip_fread(vdev->capfile, buf,
CHUNKSIZE / vdev->unitsize * vdev->unitsize);