X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flink-mso19%2Flink-mso19.c;h=63b910318615002dfc653225232898ce5e50e464;hb=48ca6b54b0a5e7b0cd5f34fa4066523a1a3cc3a3;hp=9c6f015eb6166419366bf082119d1955e78fce9c;hpb=b08024a8363c7a019bebc05a25e2689e774326e8;p=libsigrok.git diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 9c6f015e..63b91031 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -86,12 +86,16 @@ static int mso_send_control_message(struct sr_device_instance *sdi, int i, w, ret, s = n * 2 + sizeof(mso_head) + sizeof(mso_foot); char *p, *buf; + ret = SR_ERR; + if (fd < 0) goto ret; - buf = malloc(s); - if (!buf) + if (!(buf = g_try_malloc(s))) { + sr_err("mso19: %s: buf malloc failed", __func__); + ret = SR_ERR_MALLOC; goto ret; + } p = buf; memcpy(p, mso_head, sizeof(mso_head)); @@ -114,7 +118,7 @@ static int mso_send_control_message(struct sr_device_instance *sdi, } ret = SR_OK; free: - free(buf); + g_free(buf); ret: return ret; } @@ -433,10 +437,10 @@ static int hw_init(const char *deviceinfo) strcpy(manufacturer, iProduct + s); sprintf(hwrev, "r%d", mso->hwrev); - mso = malloc(sizeof(struct mso)); - if (!mso) - continue; - memset(mso, 0, sizeof(struct mso)); + if (!(mso = g_try_malloc0(sizeof(struct mso)))) { + sr_err("mso19: %s: mso malloc failed", __func__); + continue; /* TODO: Errors handled correctly? */ + } if (mso_parse_serial(iSerial, iProduct, mso) != SR_OK) { sr_warn("Invalid iSerial: %s", iSerial); @@ -535,18 +539,23 @@ static int hw_opendev(int device_index) return SR_OK; } -static void hw_closedev(int device_index) +static int hw_closedev(int device_index) { struct sr_device_instance *sdi; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) - return; + if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + sr_err("mso19: %s: sdi was NULL", __func__); + return SR_ERR; /* TODO: SR_ERR_ARG? */ + } + /* TODO */ if (sdi->serial->fd != -1) { serial_close(sdi->serial->fd); sdi->serial->fd = -1; sdi->status = SR_ST_INACTIVE; } + + return SR_OK; } static void *hw_get_device_info(int device_index, int device_info_id) @@ -775,8 +784,8 @@ struct sr_device_plugin link_mso19_plugin_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, - .open = hw_opendev, - .close = hw_closedev, + .opendev = hw_opendev, + .closedev = hw_closedev, .get_device_info = hw_get_device_info, .get_status = hw_get_status, .get_capabilities = hw_get_capabilities,