Use g_malloc0() consistently, simplify error handling.

Use g_malloc0() for small allocations and assume they always
succeed. Simplify error handling in a few places accordingly.

Don't always sanity-check parameters for non-public (SR_PRIV)
functions, we require the developers to invoke them correctly.
This allows further error handling simplifications.
This commit is contained in:
Uwe Hermann 2014-11-21 19:02:10 +01:00
parent c368e6f3d2
commit 91219afc75
31 changed files with 55 additions and 169 deletions

View File

@ -348,12 +348,7 @@ SR_API int sr_init(struct sr_context **ctx)
}
/* + 1 to handle when struct sr_context has no members. */
context = g_try_malloc0(sizeof(struct sr_context) + 1);
if (!context) {
ret = SR_ERR_MALLOC;
goto done;
}
context = g_malloc0(sizeof(struct sr_context) + 1);
#ifdef HAVE_LIBUSB_1_0
ret = libusb_init(&context->libusb_ctx);

View File

@ -281,7 +281,6 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
* @param[in] address @copydoc sr_usb_dev_inst::address
* @param[in] hdl @copydoc sr_usb_dev_inst::devhdl
*
* @retval NULL Error
* @retval other struct sr_usb_dev_inst * for USB device instance.
*/
SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
@ -289,11 +288,7 @@ SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
{
struct sr_usb_dev_inst *udi;
if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) {
sr_err("USB device instance malloc failed.");
return NULL;
}
udi = g_malloc0(sizeof(struct sr_usb_dev_inst));
udi->bus = bus;
udi->address = address;
udi->devhdl = hdl;
@ -322,10 +317,11 @@ SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb)
*
* @param[in] port OS-specific serial port specification. Examples:
* "/dev/ttyUSB0", "/dev/ttyACM1", "/dev/tty.Modem-0", "COM1".
* Must not be NULL.
* @param[in] serialcomm A serial communication parameters string, in the form
* of \<speed\>/\<data bits\>\<parity\>\<stopbits\>, for example
* "9600/8n1" or "600/7o2". This is an optional parameter;
* it may be filled in later.
* it may be filled in later. Can be NULL.
*
* @return A pointer to a newly initialized struct sr_serial_dev_inst,
* or NULL on error.
@ -335,16 +331,7 @@ SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
{
struct sr_serial_dev_inst *serial;
if (!port) {
sr_err("Serial port required.");
return NULL;
}
if (!(serial = g_try_malloc0(sizeof(struct sr_serial_dev_inst)))) {
sr_err("Serial device instance malloc failed.");
return NULL;
}
serial = g_malloc0(sizeof(struct sr_serial_dev_inst));
serial->port = g_strdup(port);
if (serialcomm)
serial->serialcomm = g_strdup(serialcomm);
@ -369,16 +356,7 @@ SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device)
{
struct sr_usbtmc_dev_inst *usbtmc;
if (!device) {
sr_err("Device name required.");
return NULL;
}
if (!(usbtmc = g_try_malloc0(sizeof(struct sr_usbtmc_dev_inst)))) {
sr_err("USBTMC device instance malloc failed.");
return NULL;
}
usbtmc = g_malloc0(sizeof(struct sr_usbtmc_dev_inst));
usbtmc->device = g_strdup(device);
usbtmc->fd = -1;

View File

@ -112,8 +112,7 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -81,8 +81,8 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = "9600/8n1";
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
return NULL;

View File

@ -122,11 +122,11 @@ static GSList *scan(GSList *options, int modelid)
if (!serialcomm)
serialcomm = SERIALCOMM;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
serial_flush(serial);
/* This is how the vendor software scans for hardware. */

View File

@ -51,8 +51,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm)
uint8_t buf[128];
size_t len;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -97,8 +97,7 @@ static GSList *scan(GSList *options)
if (!conn)
return NULL;
if (!(serial = sr_serial_dev_inst_new(conn, SERIALCOMM)))
return NULL;
serial = sr_serial_dev_inst_new(conn, SERIALCOMM);
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
return NULL;
@ -119,10 +118,7 @@ static GSList *scan(GSList *options)
devc->cur_meas_range = 0;
devc->cur_data_source = DATA_SOURCE_LIVE;
devc->enable_data_source_memory = FALSE;
if (!(sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM)))
return NULL;
sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
sdi->driver = di;

View File

@ -76,8 +76,7 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
struct sr_serial_dev_inst *serial;
GSList *devices;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -87,8 +87,7 @@ static GSList *scan(GSList *options)
sdi->vendor = g_strdup("Colead");
sdi->model = g_strdup("SL-5868P");
devc = g_malloc0(sizeof(struct dev_context));
if (!(sdi->conn = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
sdi->conn = sr_serial_dev_inst_new(conn, serialcomm);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
sdi->driver = di;

View File

@ -83,8 +83,7 @@ static GSList *scan(GSList *options)
* the device is there.
*/
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -75,8 +75,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
int retry, len, i, s;
char buf[128], *b, **tokens;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -195,8 +195,7 @@ static GSList *scan_1x_2x_rs232(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM_2X_RS232;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK) {
sr_serial_dev_inst_free(serial);
@ -288,8 +287,7 @@ static GSList *scan_2x_bd232(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM_2X;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
goto exit_err;

View File

@ -195,10 +195,7 @@ static GSList *scan(GSList *options)
devc->protocol_trigger.mask[i] = 0xff;
}
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) {
g_free(devc);
return devices;
}
devc->serial = sr_serial_dev_inst_new(conn, serialcomm);
struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;

View File

@ -125,8 +125,7 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = "9600/8n1";
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -75,8 +75,7 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
struct sr_serial_dev_inst *serial;
GSList *devices;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -402,8 +402,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
serialcomm = SERIALCOMM;
/* Init serial port. */
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
goto exit_err;

View File

@ -112,8 +112,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -128,8 +128,7 @@ static GSList *scan(GSList *options)
if (serialcomm == NULL)
serialcomm = SERIALCOMM;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
/* The discovery procedure is like this: first send the Reset
* command (0x00) 5 times, since the device could be anywhere

View File

@ -409,8 +409,7 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm)
size_t len;
uint8_t buf[128];
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -74,8 +74,8 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = "1200/7e1";
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
return NULL;

View File

@ -90,8 +90,7 @@ static GSList *scan(GSList *options)
sdi->model = g_strdup("SL-814");
devc = g_malloc0(sizeof(struct dev_context));
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;

View File

@ -95,9 +95,8 @@ static GSList *scan(GSList *options)
ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1");
sdi->channels = g_slist_append(NULL, ch);
if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL)))
return NULL;
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
sdi->inst_type = SR_INST_USB;
drvc->instances = g_slist_append(drvc->instances, sdi);

View File

@ -395,8 +395,7 @@ SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data)
{
struct sr_config *src;
if (!(src = g_try_malloc(sizeof(struct sr_config))))
return NULL;
src = g_malloc0(sizeof(struct sr_config));
src->key = key;
src->data = g_variant_ref_sink(data);

View File

@ -41,11 +41,7 @@ static struct dev_buffer *dev_buffer_new(size_t size)
{
struct dev_buffer *dbuf;
if (!(dbuf = g_try_malloc(sizeof(struct dev_buffer) + size))) {
sr_err("Dev buffer malloc failed (size=%zu).", size);
return NULL;
}
dbuf = g_malloc0(sizeof(struct dev_buffer) + size);
dbuf->size = size;
dbuf->len = 0;
dbuf->offset = 0;
@ -846,13 +842,9 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
devc = g_malloc0(sizeof(struct dev_context));
if (!(devc->buf = dev_buffer_new(PACKET_SIZE * 8)))
goto scan_cleanup;
devc->buf = dev_buffer_new(PACKET_SIZE * 8);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
if (setup_channels(sdi) != SR_OK)

View File

@ -47,7 +47,7 @@ static int init(struct sr_output *o, GHashTable *options)
if (!o || !o->sdi)
return SR_ERR_ARG;
o->priv = ctx = g_try_malloc0(sizeof(struct context));
o->priv = ctx = g_malloc0(sizeof(struct context));
s = g_variant_get_string(g_hash_table_lookup(options, "digits"), NULL);
if (!strcmp(s, "all"))
ctx->digits = DIGITS_ALL;

View File

@ -44,12 +44,8 @@ static int init(struct sr_output *o, GHashTable *options)
(void)options;
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
sr_err("%s: ctx malloc failed", __func__);
return SR_ERR_MALLOC;
}
ctx = g_malloc0(sizeof(struct context));
o->priv = ctx;
ctx->samplerate = 0;
ctx->num_samples = 0;

View File

@ -742,12 +742,7 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
}
g_free(response);
hw_info = g_try_malloc(sizeof(struct sr_scpi_hw_info));
if (!hw_info) {
g_strfreev(tokens);
return SR_ERR_MALLOC;
}
hw_info = g_malloc0(sizeof(struct sr_scpi_hw_info));
hw_info->manufacturer = g_strdup(tokens[0]);
hw_info->model = g_strdup(tokens[1]);
hw_info->serial_number = g_strdup(tokens[2]);

View File

@ -79,8 +79,7 @@ static int scpi_serial_dev_inst_new(void *priv, struct drv_context *drvc,
(void)drvc;
(void)params;
if (!(sscpi->serial = sr_serial_dev_inst_new(resource, serialcomm)))
return SR_ERR;
sscpi->serial = sr_serial_dev_inst_new(resource, serialcomm);
return SR_OK;
}

View File

@ -306,9 +306,7 @@ SR_API int sr_session_datafeed_callback_add(struct sr_session *session,
return SR_ERR_ARG;
}
if (!(cb_struct = g_try_malloc0(sizeof(struct datafeed_callback))))
return SR_ERR_MALLOC;
cb_struct = g_malloc0(sizeof(struct datafeed_callback));
cb_struct->cb = cb;
cb_struct->cb_data = cb_data;
@ -712,7 +710,6 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
*/
static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
int timeout, sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
@ -727,19 +724,10 @@ static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
/* Note: cb_data can be NULL, that's not a bug. */
new_pollfds = g_try_realloc(session->pollfds,
new_pollfds = g_realloc(session->pollfds,
sizeof(GPollFD) * (session->num_sources + 1));
if (!new_pollfds) {
sr_err("%s: new_pollfds malloc failed", __func__);
return SR_ERR_MALLOC;
}
new_sources = g_try_realloc(session->sources, sizeof(struct source) *
new_sources = g_realloc(session->sources, sizeof(struct source) *
(session->num_sources + 1));
if (!new_sources) {
sr_err("%s: new_sources malloc failed", __func__);
return SR_ERR_MALLOC;
}
new_pollfds[session->num_sources] = *pollfd;
s = &new_sources[session->num_sources++];
@ -769,7 +757,6 @@ static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
*
* @since 0.3.0
*/
@ -795,7 +782,6 @@ SR_API int sr_session_source_add(struct sr_session *session, int fd,
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
*
* @since 0.3.0
*/
@ -819,7 +805,6 @@ SR_API int sr_session_source_add_pollfd(struct sr_session *session,
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
*
* @since 0.3.0
*/
@ -842,20 +827,15 @@ SR_API int sr_session_source_add_channel(struct sr_session *session,
/**
* Remove the source belonging to the specified channel.
*
* @todo Add more error checks and logging.
*
* @param session The session to use. Must not be NULL.
* @param poll_object The channel for which the source should be removed.
*
* @retval SR_OK Success
* @retval SR_ERR_ARG Invalid arguments
* @retval SR_ERR_MALLOC Memory allocation error
* @retval SR_ERR_BUG Internal error
*/
static int _sr_session_source_remove(struct sr_session *session, gintptr poll_object)
{
struct source *new_sources;
GPollFD *new_pollfds;
unsigned int old;
if (!session->sources || !session->num_sources) {
@ -872,7 +852,7 @@ static int _sr_session_source_remove(struct sr_session *session, gintptr poll_ob
if (old == session->num_sources)
return SR_OK;
session->num_sources -= 1;
session->num_sources--;
if (old != session->num_sources) {
memmove(&session->pollfds[old], &session->pollfds[old + 1],
@ -881,20 +861,8 @@ static int _sr_session_source_remove(struct sr_session *session, gintptr poll_ob
(session->num_sources - old) * sizeof(struct source));
}
new_pollfds = g_try_realloc(session->pollfds, sizeof(GPollFD) * session->num_sources);
if (!new_pollfds && session->num_sources > 0) {
sr_err("%s: new_pollfds malloc failed", __func__);
return SR_ERR_MALLOC;
}
new_sources = g_try_realloc(session->sources, sizeof(struct source) * session->num_sources);
if (!new_sources && session->num_sources > 0) {
sr_err("%s: new_sources malloc failed", __func__);
return SR_ERR_MALLOC;
}
session->pollfds = new_pollfds;
session->sources = new_sources;
session->pollfds = g_realloc(session->pollfds, sizeof(GPollFD) * session->num_sources);
session->sources = g_realloc(session->sources, sizeof(struct source) * session->num_sources);
return SR_OK;
}
@ -907,7 +875,6 @@ static int _sr_session_source_remove(struct sr_session *session, gintptr poll_ob
*
* @retval SR_OK Success
* @retval SR_ERR_ARG Invalid argument
* @retval SR_ERR_MALLOC Memory allocation error.
* @retval SR_ERR_BUG Internal error.
*
* @since 0.3.0
@ -943,7 +910,6 @@ SR_API int sr_session_source_remove_pollfd(struct sr_session *session,
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
* @return SR_ERR_BUG Internal error.
*
* @since 0.2.0

View File

@ -41,8 +41,7 @@
* @param di The driver instance to use.
* @param[in] prefix A driver-specific prefix string used for log messages.
*
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
*/
SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
const char *prefix)
@ -54,11 +53,7 @@ SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
return SR_ERR_ARG;
}
if (!(drvc = g_try_malloc(sizeof(struct drv_context)))) {
sr_err("%s: Driver context malloc failed.", prefix);
return SR_ERR_MALLOC;
}
drvc = g_malloc0(sizeof(struct drv_context));
drvc->sr_ctx = sr_ctx;
drvc->instances = NULL;
di->priv = drvc;

View File

@ -230,7 +230,7 @@ SR_PRIV int sr_atof_ascii(const char *str, float *ret)
* @param unit The unit to append to the string, or NULL if the string
* has no units.
*
* @return A g_try_malloc()ed string representation of the samplerate value,
* @return A newly allocated string representation of the samplerate value,
* or NULL upon errors. The caller is responsible to g_free() the
* memory.
*
@ -272,7 +272,7 @@ SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
*
* @param samplerate The samplerate in Hz.
*
* @return A g_try_malloc()ed string representation of the samplerate value,
* @return A newly allocated string representation of the samplerate value,
* or NULL upon errors. The caller is responsible to g_free() the
* memory.
*
@ -291,7 +291,7 @@ SR_API char *sr_samplerate_string(uint64_t samplerate)
*
* @param frequency The frequency in Hz.
*
* @return A g_try_malloc()ed string representation of the frequency value,
* @return A newly allocated string representation of the frequency value,
* or NULL upon errors. The caller is responsible to g_free() the
* memory.
*
@ -303,10 +303,7 @@ SR_API char *sr_period_string(uint64_t frequency)
int r;
/* Allocate enough for a uint64_t as string + " ms". */
if (!(o = g_try_malloc0(30 + 1))) {
sr_err("%s: o malloc failed", __func__);
return NULL;
}
o = g_malloc0(30 + 1);
if (frequency >= SR_GHZ(1))
r = snprintf(o, 30, "%" PRIu64 " ns", frequency / 1000000000);
@ -336,7 +333,7 @@ SR_API char *sr_period_string(uint64_t frequency)
* @param v_p The voltage numerator.
* @param v_q The voltage denominator.
*
* @return A g_try_malloc()ed string representation of the voltage value,
* @return A newly allocated string representation of the voltage value,
* or NULL upon errors. The caller is responsible to g_free() the
* memory.
*
@ -347,10 +344,7 @@ SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q)
int r;
char *o;
if (!(o = g_try_malloc0(30 + 1))) {
sr_err("%s: o malloc failed", __func__);
return NULL;
}
o = g_malloc0(30 + 1);
if (v_q == 1000)
r = snprintf(o, 30, "%" PRIu64 "mV", v_p);