diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index 7dfb2c65..60f271b2 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -96,7 +96,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("Driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } di->priv = drvc; @@ -196,7 +196,10 @@ static GSList *hw_scan(GSList *options) } len = 128; - buf = g_try_malloc(len); + if (!(buf = g_try_malloc(len))) { + sr_err("Serial buffer malloc failed."); + return NULL; + } serial_readline2(fd, &buf, &len, 150); if (!len) return NULL; @@ -211,7 +214,7 @@ static GSList *hw_scan(GSList *options) tokens[1], tokens[3]))) return NULL; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_dbg("failed to malloc devc"); + sr_err("Device context malloc failed."); return NULL; } devc->profile = &supported_agdmm[i]; diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 4fb8c5d5..c0f4ccaa 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -76,7 +76,7 @@ static int hw_init(const char *devinfo) if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_err("alsa: %s: ctx malloc failed", __func__); - return 0; + return SR_ERR_MALLOC; } if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, "alsa", NULL, NULL))) { @@ -117,7 +117,7 @@ static int hw_dev_open(int dev_index) if (ret < 0) { sr_err("alsa: can't allocate hardware parameter structure (%s)", snd_strerror(ret)); - return SR_ERR; + return SR_ERR_MALLOC; } ret = snd_pcm_hw_params_any(ctx->capture_handle, ctx->hw_params); diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index ed32e6a5..7bf50104 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -440,7 +440,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("asix-sigma: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } adi->priv = drvc; diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 4a92a668..38d4a5f1 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -166,7 +166,7 @@ SR_PRIV void *serial_backup_params(int fd) /* TODO: 'term' is never g_free()'d? */ if (!(term = g_try_malloc(sizeof(struct termios)))) { sr_err("serial: %s: term malloc failed", __func__); - return NULL; + return -1; } tcgetattr(fd, term); diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 8300e6f4..b8a4c242 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -145,8 +145,8 @@ static int hw_init(void) struct drv_context *drvc; if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("fx2lafw: driver context malloc failed."); - return SR_ERR; + sr_err("demo: driver context malloc failed."); + return SR_ERR_MALLOC; } ddi->priv = drvc; diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index 5786438d..2c82d92d 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -87,7 +87,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("Driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } di->priv = drvc; diff --git a/hardware/fluke-dmm/fluke.c b/hardware/fluke-dmm/fluke.c index 6719b41c..f8544e99 100644 --- a/hardware/fluke-dmm/fluke.c +++ b/hardware/fluke-dmm/fluke.c @@ -54,8 +54,10 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, while(*e && *e == ' ') e++; + /* TODO: Check malloc return value. */ analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)); analog->num_samples = 1; + /* TODO: Check malloc return value. */ analog->data = g_try_malloc(sizeof(float)); if (is_oor) *analog->data = NAN; @@ -162,8 +164,10 @@ static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi, return NULL; } + /* TODO: Check malloc return value. */ analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)); analog->num_samples = 1; + /* TODO: Check malloc return value. */ analog->data = g_try_malloc(sizeof(float)); *analog->data = fvalue; analog->mq = -1; diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 9a193270..e74312fb 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -406,7 +406,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("fx2lafw: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } if (libusb_init(NULL) != 0) { @@ -972,8 +972,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, const size_t size = get_buffer_size(devc); devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers); - if (!devc->transfers) - return SR_ERR; + if (!devc->transfers) { + sr_err("fx2lafw: USB transfers malloc failed."); + return SR_ERR_MALLOC; + } devc->num_transfers = num_transfers; diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index 7e93f50c..5b12b2e4 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -152,7 +152,7 @@ static GSList *connect_usb(const char *conn) /* Found one. */ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); - return 0; + return NULL; } devcnt = g_slist_length(drvc->instances); @@ -323,7 +323,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("Driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } if (libusb_init(&genericdmm_usb_context) != 0) { diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index e35dacbd..8c7a9dce 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -258,7 +258,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("hantek-dso: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } if (libusb_init(NULL) != 0) { @@ -602,6 +602,7 @@ static void send_chunk(struct dev_context *devc, unsigned char *buf, analog.num_samples = num_samples; analog.mq = SR_MQ_VOLTAGE; analog.unit = SR_UNIT_VOLT; + /* TODO: Check malloc return value. */ analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_probes); data_offset = 0; for (i = 0; i < analog.num_samples; i++) { @@ -804,6 +805,7 @@ static int handle_event(int fd, int revents, void *cb_data) devc->trigger_offset = trigger_offset; num_probes = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1; + /* TODO: Check malloc return value. */ devc->framebuf = g_try_malloc(devc->framesize * num_probes * 2); devc->samp_buffered = devc->samp_received = 0; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index 5b13931c..ef3081c3 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -369,7 +369,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("ols: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } odi->priv = drvc; @@ -763,6 +763,7 @@ static int receive_data(int fd, int revents, void *cb_data) */ sr_source_remove(fd); sr_source_add(fd, G_IO_IN, 30, receive_data, cb_data); + /* TODO: Check malloc return code. */ devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4); if (!devc->raw_sample_buf) { sr_err("ols: %s: devc->raw_sample_buf malloc failed", @@ -1075,7 +1076,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data) { - /* Avoid compiler warnings. */ (void)cb_data; diff --git a/hardware/radioshack-dmm/api.c b/hardware/radioshack-dmm/api.c index e9abf830..4eb5cbfa 100644 --- a/hardware/radioshack-dmm/api.c +++ b/hardware/radioshack-dmm/api.c @@ -85,7 +85,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("Driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } di->priv = drvc; diff --git a/hardware/radioshack-dmm/radioshack.c b/hardware/radioshack-dmm/radioshack.c index f14af46e..64ef59be 100644 --- a/hardware/radioshack-dmm/radioshack.c +++ b/hardware/radioshack-dmm/radioshack.c @@ -229,8 +229,10 @@ static void rs_22_812_handle_packet(rs_22_812_packet *rs_packet, struct sr_datafeed_packet packet; struct sr_datafeed_analog *analog; + /* TODO: Check malloc return value. */ analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)); analog->num_samples = 1; + /* TODO: Check malloc return value. */ analog->data = g_try_malloc(sizeof(float)); *analog->data = (float)rawval; analog->mq = -1; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index c22f9458..f1b6431b 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -257,7 +257,7 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("zeroplus: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } zdi->priv = drvc; @@ -321,7 +321,7 @@ static GSList *hw_scan(GSList *options) /* Allocate memory for our private driver context. */ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("zp: %s: devc malloc failed", __func__); - return 0; + return NULL; } sdi->priv = devc; devc->num_channels = prof->channels; diff --git a/output/analog.c b/output/analog.c index 6f3609c0..4f8715aa 100644 --- a/output/analog.c +++ b/output/analog.c @@ -30,7 +30,6 @@ struct context { GString *out; }; - static int init(struct sr_output *o) { struct context *ctx; @@ -41,8 +40,10 @@ static int init(struct sr_output *o) if (!o || !o->sdi) return SR_ERR_ARG; - if (!(ctx = g_try_malloc0(sizeof(struct context)))) + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("output/analog: Context malloc failed."); return SR_ERR_MALLOC; + } o->internal = ctx; /* Get the number of probes and their names. */ diff --git a/output/float.c b/output/float.c index cd4ef8c3..7812413d 100644 --- a/output/float.c +++ b/output/float.c @@ -43,8 +43,10 @@ static int init(struct sr_output *o) if (!o->sdi->driver) return SR_ERR_ARG; - if (!(ctx = g_try_malloc0(sizeof(struct context)))) + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("output/float: Context malloc failed."); return SR_ERR_MALLOC; + } o->internal = ctx;