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.
*
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;
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);
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;
}