Eliminate an incomplete local copy of sdi resource release code in an
error path of scan/probe. Use common code instead to free the sdi.
Assign opaque pointers to intermediate variables before passing their
values to other routines. Should slightly increase readability and
data type safety. Also close the USB handle if it's open at this time.
/* Convenience. Release an allocated sdi from error paths. */
static void kingst_la2016_free_sdi(struct sr_dev_inst *sdi)
{
+ struct sr_usb_dev_inst *usb;
+ struct dev_context *devc;
+
if (!sdi)
return;
- g_free(sdi->vendor);
- g_free(sdi->model);
- g_free(sdi->version);
- g_free(sdi->serial_num);
- g_free(sdi->connection_id);
- sr_usb_dev_inst_free(sdi->conn);
- kingst_la2016_free_devc(sdi->priv);
+
+ usb = sdi->conn;
+ if (usb && usb->devhdl)
+ sr_usb_close(usb);
+ sr_usb_dev_inst_free(usb);
+
+ devc = sdi->priv;
+ kingst_la2016_free_devc(devc);
+
+ sr_dev_inst_free(sdi);
}
/* Convenience. Open a USB device (including claiming an interface). */