+ struct sr_device_instance *sdi;
+ struct fx2_device *fx2;
+ int ret = SR_OK;
+
+ /* Properly close and free all devices. */
+ for (l = device_instances; l; l = l->next) {
+ if (!(sdi = l->data)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("fx2: %s: sdi was NULL, continuing", __func__);
+ ret = SR_ERR_BUG;
+ continue;
+ }
+ if (!(fx2 = sdi->priv)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("fx2: %s: sdi->priv was NULL, continuing",
+ __func__);
+ ret = SR_ERR_BUG;
+ continue;
+ }
+ close_device(sdi);
+ sr_usb_device_instance_free(fx2->usb);
+ sr_device_instance_free(sdi);
+ }