]> sigrok.org Git - libsigrok.git/commitdiff
Some more g_try_*alloc() fixes.
authorUwe Hermann <redacted>
Mon, 23 Mar 2015 18:54:53 +0000 (19:54 +0100)
committerUwe Hermann <redacted>
Tue, 24 Mar 2015 18:30:16 +0000 (19:30 +0100)
As per documented rules in HACKING, we don't check "small" allocations.

14 files changed:
src/hardware/agilent-dmm/api.c
src/hardware/fluke-dmm/fluke.c
src/hardware/hameg-hmo/protocol.c
src/hardware/hantek-dso/api.c
src/hardware/lascar-el-usb/api.c
src/hardware/link-mso19/protocol.c
src/hardware/norma-dmm/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/rigol-ds/api.c
src/hardware/sysclk-lwla/protocol.c
src/hardware/testo/api.c
src/hardware/victor-dmm/api.c
src/hardware/zeroplus-logic-cube/api.c
src/session_driver.c

index 19a4144cca2aed4ea75df880087be1767ae7ace6..e8ef427b7cc1951ca03797d542c1937697ebaf58 100644 (file)
@@ -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;
index c098ced465a351f384db2fbb8eb1da5b60165325..e708518d90f1dd3f003462bced985c955131703e 100644 (file)
@@ -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;
index 8c5589bd37f489a8c4b79bff129dc4221373158d..77027f1d300ecedc25db9cf9381c487db86805bc 100644 (file)
@@ -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)
index 1676085e781b5be30e8e8d43beee6ad3b594fa97..2b039ed22b60e32e499141fbb45fdf29e573a3ff 100644 (file)
@@ -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. */
index ce63bc672f68c2360e79875d174af62cfa357844..14273ce3d4fcfcb32fc7b391ef060ec0b0acb4e0 100644 (file)
@@ -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)) {
index fafd83c3b93b7a15a3488496d4600da9b737e9d3..11fa8a616f79960795983833e953122537128d93 100644 (file)
@@ -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));
index bf44df2756da534b9e00349e49c31c9d105936f9..2743c23431547e367dd946cc758570a3c5164c36 100644 (file)
@@ -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);
index defb39785d32eb994fd954ba55f1598360ddb90c..b84ff193ea8404bbb47ae47ca9eb6aa19bbae140 100644 (file)
@@ -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;
index 111eff067d6734a73883ca957fd26bc18761a7c7..955b6accf7048e2ff3e99106163361d213e08255 100644 (file)
@@ -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;
 
index 2fd4dffaa48bd46267d21d6dad3d57aae4b98bf6..7b8c4885e5608dfd6e7c311953d018229a0b210e 100644 (file)
@@ -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) {
index 64d292dd3488b2a0d928a834bfb65976b1c80130..983451ea6cea08d435c825bdad0170c35c7a8839 100644 (file)
@@ -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);
index 6548fb44433640449e8a3424024761065b2c0838..bed4ce159ae0d6780b94211256c63926238c1b2e 100644 (file)
@@ -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
index 48845c7a2c26b62f37f4bbc23d834d0420b8fc37..5de6f317099d1a63d6346d35d6f4dd65b5d657e3 100644 (file)
@@ -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 ||
index 8bf7fc6f972078136997bc5e5a15aaa3d0c2a4ac..ae1b211892c792779a2df33691e1e064f4f42609 100644 (file)
@@ -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);