]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/openbench-logic-sniffer/protocol.c
Various #include file cosmetic fixes.
[libsigrok.git] / src / hardware / openbench-logic-sniffer / protocol.c
index 0a816d01625ad238d7fb548007bd67903da09c76..9082ec1851fcd160bae1e6b4c2d5c434e8db9bba 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "protocol.h"
 #include <libserialport.h>
+#include "protocol.h"
 
 extern SR_PRIV struct sr_dev_driver ols_driver_info;
-static struct sr_dev_driver *di = &ols_driver_info;
 
 SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial,
                uint8_t command)
@@ -124,10 +123,7 @@ SR_PRIV struct dev_context *ols_dev_new(void)
 {
        struct dev_context *devc;
 
-       if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
-               sr_err("Device context malloc failed.");
-               return NULL;
-       }
+       devc = g_malloc0(sizeof(struct dev_context));
 
        /* Device-specific settings */
        devc->max_samples = devc->max_samplerate = devc->protocol_version = 0;
@@ -145,15 +141,15 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       struct sr_channel *ch;
        uint32_t tmp_int, ui;
        uint8_t key, type, token;
        int delay_ms;
        GString *tmp_str, *devname, *version;
        guchar tmp_c;
 
-       sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL);
-       sdi->driver = di;
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_INACTIVE;
+       sdi->driver = &ols_driver_info;
        devc = ols_dev_new();
        sdi->priv = devc;
 
@@ -217,12 +213,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
-                               for (ui = 0; ui < tmp_int; ui++) {
-                                       if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE,
-                                                       ols_channel_names[ui])))
-                                               return 0;
-                                       sdi->channels = g_slist_append(sdi->channels, ch);
-                               }
+                               for (ui = 0; ui < tmp_int; ui++)
+                                       sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
+                                                       ols_channel_names[ui]);
                                break;
                        case 0x01:
                                /* Amount of sample memory available (bytes) */
@@ -233,7 +226,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
                                /* what is this for? */
                                break;
                        case 0x03:
-                               /* Maximum sample rate (hz) */
+                               /* Maximum sample rate (Hz) */
                                devc->max_samplerate = tmp_int;
                                break;
                        case 0x04:
@@ -256,12 +249,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
                        switch (token) {
                        case 0x00:
                                /* Number of usable channels */
-                               for (ui = 0; ui < tmp_c; ui++) {
-                                       if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE,
-                                                       ols_channel_names[ui])))
-                                               return 0;
-                                       sdi->channels = g_slist_append(sdi->channels, ch);
-                               }
+                               for (ui = 0; ui < tmp_c; ui++)
+                                       sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
+                                                       ols_channel_names[ui]);
                                break;
                        case 0x01:
                                /* protocol version */