X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdevice.c;h=dbbb2e26ac122e446f4c4c4efcf66e16260a5a2a;hb=fe71c7e42ea442d7706c7dab4d98c2c9f1658537;hp=e58c1790f2c166204779f8ba0069a1903292fa55;hpb=12852b0337fd802ac0f9c51a39a173636685ef18;p=libsigrok.git diff --git a/src/device.c b/src/device.c index e58c1790..dbbb2e26 100644 --- a/src/device.c +++ b/src/device.c @@ -73,6 +73,30 @@ SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi, return ch; } +/** + * Release a previously allocated struct sr_channel. + * + * @param[in] ch Pointer to struct sr_channel. + * + * @private + */ +SR_PRIV void sr_channel_free(struct sr_channel *ch) +{ + if (!ch) + return; + g_free(ch->name); + g_free(ch->priv); + g_free(ch); +} + +/** + * Wrapper around @ref sr_channel_free(), suitable for glib iterators. + */ +SR_PRIV void sr_channel_free_cb(void *p) +{ + sr_channel_free(p); +} + /** * Set the name of the specified channel. * @@ -135,10 +159,18 @@ SR_API int sr_dev_channel_enable(struct sr_channel *channel, gboolean state) return SR_OK; } -/* Returns the next enabled channel, wrapping around if necessary. */ -/** @private */ +/** + * Returns the next enabled channel, wrapping around if necessary. + * + * @param[in] sdi The device instance the channel is connected to. + * Must not be NULL. + * @param[in] cur_channel The current channel. + * + * @return A pointer to the next enabled channel of this device. + * + * @private + */ SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi, - struct sr_channel *cur_channel) { struct sr_channel *next_channel; @@ -356,9 +388,7 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi) for (l = sdi->channels; l; l = l->next) { ch = l->data; - g_free(ch->name); - g_free(ch->priv); - g_free(ch); + sr_channel_free(ch); } g_slist_free(sdi->channels); @@ -529,8 +559,6 @@ SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver) */ SR_API int sr_dev_clear(const struct sr_dev_driver *driver) { - int ret; - if (!driver) { sr_err("Invalid driver."); return SR_ERR_ARG; @@ -546,12 +574,9 @@ SR_API int sr_dev_clear(const struct sr_dev_driver *driver) return SR_OK; } - if (driver->dev_clear) - ret = driver->dev_clear(driver); - else - ret = std_dev_clear(driver, NULL); + /* No log message here, too verbose and not very useful. */ - return ret; + return driver->dev_clear(driver); } /** @@ -615,8 +640,6 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi) */ SR_API int sr_dev_close(struct sr_dev_inst *sdi) { - int ret; - if (!sdi || !sdi->driver || !sdi->driver->dev_close) return SR_ERR_ARG; @@ -630,9 +653,7 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi) sr_dbg("%s: Closing device instance.", sdi->driver->name); - ret = sdi->driver->dev_close(sdi); - - return ret; + return sdi->driver->dev_close(sdi); } /** @@ -762,7 +783,9 @@ SR_API const char *sr_dev_inst_connid_get(const struct sr_dev_inst *sdi) if (b != usb->bus || a != usb->address) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id); break; }