]> sigrok.org Git - libsigrok.git/blobdiff - hardware/colead-slm/api.c
Factor out common hw_init() driver code.
[libsigrok.git] / hardware / colead-slm / api.c
index 048fdd918e84587d8be369e4a27fcc4f0c4c7bc3..5532b1a162fca5e2a93079afd713c6ce35165977 100644 (file)
@@ -74,17 +74,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR;
-       }
-
-       drvc->sr_ctx = sr_ctx;
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -97,10 +87,11 @@ static GSList *hw_scan(GSList *options)
        GSList *devices, *l;
        const char *conn, *serialcomm;
 
-       devices = NULL;
        drvc = di->priv;
        drvc->instances = NULL;
 
+       devices = NULL;
+
        conn = serialcomm = NULL;
        for (l = options; l; l = l->next) {
                src = l->data;
@@ -123,7 +114,7 @@ static GSList *hw_scan(GSList *options)
                return NULL;
 
        if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
-               sr_dbg("failed to malloc devc");
+               sr_dbg("Device context malloc failed.");
                return NULL;
        }