]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/zeroplus.c
libsigrok: closedev() now has a return code.
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
index 7ce5c61b2fb185aa91ac1a95665050d6e98bd750..f5b2d9e4443268956df325ccec771397dd993957 100644 (file)
@@ -370,12 +370,19 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
 
-       if ((sdi = sr_get_device_instance(device_instances, device_index)))
-               close_device(sdi);
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("lap-c: %s: sdi was NULL", __func__);
+               return SR_ERR; /* TODO: SR_ERR_ARG? */
+       }
+
+       /* TODO */
+       close_device(sdi);
+
+       return SR_OK;
 }
 
 static void hw_cleanup(void)
@@ -518,9 +525,11 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
        header.num_analog_probes = 0;
        sr_session_bus(session_device_id, &packet);
 
-       buf = g_malloc(PACKET_SIZE);
-       if (!buf)
-               return SR_ERR;
+       if (!(buf = g_try_malloc(PACKET_SIZE))) {
+               sr_err("zeroplus: %s: buf malloc failed", __func__);
+               return SR_ERR_MALLOC;
+       }
+
        analyzer_read_start(sdi->usb->devhdl);
        /* Send the incoming transfer to the session bus. */
        for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE);
@@ -563,17 +572,17 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
 }
 
 struct sr_device_plugin zeroplus_logic_cube_plugin_info = {
-       "zeroplus-logic-cube",
-       "Zeroplus Logic Cube LAP-C series",
-       1,
-       hw_init,
-       hw_cleanup,
-       hw_opendev,
-       hw_closedev,
-       hw_get_device_info,
-       hw_get_status,
-       hw_get_capabilities,
-       hw_set_configuration,
-       hw_start_acquisition,
-       hw_stop_acquisition,
+       .name = "zeroplus-logic-cube",
+       .longname = "Zeroplus Logic Cube LAP-C series",
+       .api_version = 1,
+       .init = hw_init,
+       .cleanup = hw_cleanup,
+       .opendev = hw_opendev,
+       .closedev = hw_closedev,
+       .get_device_info = hw_get_device_info,
+       .get_status = hw_get_status,
+       .get_capabilities = hw_get_capabilities,
+       .set_configuration = hw_set_configuration,
+       .start_acquisition = hw_start_acquisition,
+       .stop_acquisition = hw_stop_acquisition,
 };