+static int clear_instances(void)
+{
+ GSList *l;
+ struct sr_dev_inst *sdi;
+ struct context *ctx;
+ int ret;
+
+ ret = SR_OK;
+ for (l = fdi->instances; l; l = l->next) {
+ if (!(sdi = l->data)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("fx2lafw: %s: sdi was NULL, continuing.",
+ __func__);
+ ret = SR_ERR_BUG;
+ continue;
+ }
+ if (!(ctx = sdi->priv)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("fx2lafw: %s: sdi->priv was NULL, continuing",
+ __func__);
+ ret = SR_ERR_BUG;
+ continue;
+ }
+ hw_dev_close(sdi);
+ sdi = l->data;
+ sr_dev_inst_free(sdi);
+ }
+
+ g_slist_free(fdi->instances);
+ fdi->instances = NULL;
+
+ return ret;
+}
+
+