X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fstd.c;h=5b97f66a857696f09998b30732ec6956f3649c5f;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=910e884704ce64a169a3a4b60fb7aac7542bebe3;hpb=886413b6d2e26513bd73f5d89f8b1816eda800a8;p=libsigrok.git diff --git a/src/std.c b/src/std.c index 910e8847..5b97f66a 100644 --- a/src/std.c +++ b/src/std.c @@ -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,14 +53,10 @@ 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; + di->context = drvc; return SR_OK; } @@ -115,7 +110,7 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi, * * This function can be used to implement the dev_open() driver API * callback in drivers that use a serial port. The port is opened - * with the SERIAL_RDWR and SERIAL_NONBLOCK flags. + * with the SERIAL_RDWR flag. * * If the open succeeded, the status field of the given sdi is set * to SR_ST_ACTIVE. @@ -128,7 +123,7 @@ SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi) struct sr_serial_dev_inst *serial; serial = sdi->conn; - if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + if (serial_open(serial, SERIAL_RDWR) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -249,11 +244,10 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, { struct drv_context *drvc; struct sr_dev_inst *sdi; - struct sr_channel_group *cg; - GSList *l, *lcg; + GSList *l; int ret; - if (!(drvc = driver->priv)) + if (!(drvc = driver->context)) /* Driver was never initialized, nothing to do. */ return SR_OK; @@ -277,6 +271,8 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, #endif if (sdi->inst_type == SR_INST_SCPI) sr_scpi_free(sdi->conn); + if (sdi->inst_type == SR_INST_MODBUS) + sr_modbus_free(sdi->conn); } if (clear_private) /* The helper function is responsible for freeing @@ -285,13 +281,6 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, else g_free(sdi->priv); - /* Channel groups */ - for (lcg = sdi->channel_groups; lcg; lcg = lcg->next) { - cg = lcg->data; - g_free(cg->name); - g_slist_free(cg->channels); - g_free(cg); - } sr_dev_inst_free(sdi); }