Return SR_ERR_MALLOC upon allocation errors.
Add some TODOs.
This commit is contained in:
parent
6f22a8ef2c
commit
886a52b6fb
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue