X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdevice.c;h=1c84a7df48d6823f03543f6c580ffe72f94dd5ad;hb=5e23fcab889c62864b92aa3ad6902ce3e9f5be49;hp=9dd2201e528b05a0848a4cf0e34135dd7232fde9;hpb=bc497772512c2fd37516964ade58b69448aae37c;p=libsigrok.git diff --git a/src/device.c b/src/device.c index 9dd2201e..1c84a7df 100644 --- a/src/device.c +++ b/src/device.c @@ -42,7 +42,8 @@ */ /** @private - * Allocate and initialize new struct sr_channel + * Allocate and initialize new struct sr_channel and add to sdi. + * @param[in] sdi The device instance the channel is connected to. * @param[in] index @copydoc sr_channel::index * @param[in] type @copydoc sr_channel::type * @param[in] enabled @copydoc sr_channel::enabled @@ -50,8 +51,8 @@ * * @return A new struct sr_channel*. */ -SR_PRIV struct sr_channel *sr_channel_new(int index, int type, - gboolean enabled, const char *name) +SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi, + int index, int type, gboolean enabled, const char *name) { struct sr_channel *ch; @@ -62,6 +63,8 @@ SR_PRIV struct sr_channel *sr_channel_new(int index, int type, if (name) ch->name = g_strdup(name); + sdi->channels = g_slist_append(sdi->channels, ch); + return ch; } @@ -227,13 +230,10 @@ SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor, */ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, const char *name) { - struct sr_channel *ch; - if (!sdi || sdi->inst_type != SR_INST_USER || index < 0) return SR_ERR_ARG; - ch = sr_channel_new(index, type, TRUE, name); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, index, type, TRUE, name); return SR_OK; }