Some more g_try_*alloc() fixes.
As per documented rules in HACKING, we don't check "small" allocations.
This commit is contained in:
parent
1a46cc62e2
commit
a95f142e88
|
@ -122,10 +122,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -59,10 +59,8 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
|
|||
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)
|
||||
|
@ -170,10 +168,8 @@ static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi,
|
|||
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;
|
||||
|
|
|
@ -543,33 +543,15 @@ static struct scope_state *scope_state_new(const struct scope_config *config)
|
|||
{
|
||||
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)
|
||||
|
|
|
@ -827,8 +827,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
|||
}
|
||||
} 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;
|
||||
|
@ -939,8 +938,7 @@ static int handle_event(int fd, int revents, void *cb_data)
|
|||
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. */
|
||||
|
|
|
@ -433,7 +433,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
|||
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)) {
|
||||
|
|
|
@ -42,11 +42,7 @@ SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial,
|
|||
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));
|
||||
|
|
|
@ -113,10 +113,7 @@ static GSList *scan(struct sr_dev_driver* drv, GSList *options)
|
|||
|
||||
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);
|
||||
|
|
|
@ -110,10 +110,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
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())) {
|
||||
|
@ -197,7 +194,6 @@ err_free_ftdic:
|
|||
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;
|
||||
|
|
|
@ -388,16 +388,16 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
|
|||
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;
|
||||
|
||||
|
|
|
@ -959,11 +959,7 @@ SR_PRIV struct acquisition_state *lwla_alloc_acquisition_state(void)
|
|||
{
|
||||
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) {
|
||||
|
|
|
@ -490,7 +490,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
|||
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);
|
||||
|
|
|
@ -395,7 +395,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
|||
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
|
||||
|
|
|
@ -592,10 +592,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
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 ||
|
||||
|
|
|
@ -117,10 +117,7 @@ static int receive_data(int fd, int revents, void *cb_data)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue