X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Fapi.c;h=959b566dcd451b568bb5e4f4d9c6d55a14cf3c72;hb=9e60a31fb954493754770fe2192db74b947c6867;hp=11d78d4915d3945eff62f4b9fdeaaee8909cb5fb;hpb=0699ccdd92229a82f947993ec6c15adbcf43e867;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 11d78d49..959b566d 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -79,53 +79,32 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *gen_channel_list(int num_channels) -{ - GSList *list; - struct sr_channel *ch; - int i; - char name[8]; - - list = NULL; - - for (i = num_channels; i > 0; --i) { - /* The LWLA series simply number channels from CH1 to CHxx. */ - g_snprintf(name, sizeof(name), "CH%d", i); - - ch = sr_channel_new(i - 1, SR_CHANNEL_LOGIC, TRUE, name); - list = g_slist_prepend(list, ch); - } - - return list; -} - -static struct sr_dev_inst *dev_inst_new() +static struct sr_dev_inst *dev_inst_new(void) { struct sr_dev_inst *sdi; struct dev_context *devc; + int i; + char name[8]; /* Allocate memory for our private driver context. */ - devc = g_try_new0(struct dev_context, 1); - if (!devc) { - sr_err("Device context malloc failed."); - return NULL; - } + devc = g_malloc0(sizeof(struct dev_context)); /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(SR_ST_INACTIVE, - VENDOR_NAME, MODEL_NAME, NULL); - if (!sdi) { - sr_err("Failed to instantiate device."); - g_free(devc); - return NULL; - } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(VENDOR_NAME); + sdi->model = g_strdup(MODEL_NAME); /* Enable all channels to match the default channel configuration. */ devc->channel_mask = ALL_CHANNELS_MASK; devc->samplerate = DEFAULT_SAMPLERATE; sdi->priv = devc; - sdi->channels = gen_channel_list(NUM_CHANNELS); + for (i = NUM_CHANNELS; i > 0; --i) { + /* The LWLA series simply number channels from CH1 to CHxx. */ + g_snprintf(name, sizeof(name), "CH%d", i); + sr_channel_new(sdi, i - 1, SR_CHANNEL_LOGIC, TRUE, name); + } return sdi; }