X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmic-985xx%2Fapi.c;h=737febafc5818d4a3694b1d01eeb31f44ba8057f;hb=16aca7661b7ab34a399c323bb9214721e2b1be0c;hp=d2ce842b07d39b9f88e984ba9e62e0f4207bb15a;hpb=e07edc83d6311e36f2cbb5f3ae8a0f0edb526d18;p=libsigrok.git diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index d2ce842b..737febaf 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -71,12 +71,10 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; - if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) - return NULL; + serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; @@ -91,36 +89,24 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sr_info("Found device on port %s.", conn); /* TODO: Fill in version from protocol response. */ - sdi = sr_dev_inst_new(); + sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(mic_devs[idx].vendor); sdi->model = g_strdup(mic_devs[idx].device); - - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_err("Device context malloc failed."); - goto scan_cleanup; - } - + devc = g_malloc0(sizeof(struct dev_context)); sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; - sdi->priv = devc; sdi->driver = mic_devs[idx].di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temperature"))) - goto scan_cleanup; - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temperature"); - if (mic_devs[idx].has_humidity) { - if (!(ch = sr_channel_new(1, SR_CHANNEL_ANALOG, TRUE, "Humidity"))) - goto scan_cleanup; - sdi->channels = g_slist_append(sdi->channels, ch); - } + if (mic_devs[idx].has_humidity) + sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "Humidity"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); -scan_cleanup: serial_close(serial); return devices;