+ struct sr_dev_inst *sdi;
+ struct context *ctx;
+ int ret = SR_OK;
+
+ /* Properly close and free all devices. */
+ for (l = dev_insts; l; l = l->next) {
+ if (!(sdi = l->data)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("logic: %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("logic: %s: sdi->priv was NULL, continuing",
+ __func__);
+ ret = SR_ERR_BUG;
+ continue;
+ }
+ close_dev(sdi);
+ sr_usb_dev_inst_free(ctx->usb);
+ sr_dev_inst_free(sdi);
+ }