Some drivers check in some of their driver callbacks if the driver has been initialized and return an error if it has not.
For the scan() callback the sigrok core checks if the driver has been initialized and if not returns an error. So it is not possible that the scan() callback gets called if the driver is not initialized. Without the scan() callback succeeding it is not possible to get a reference to a device which is associated with the driver, so it is not possible that any of the device specific callbacks is called without the driver first being initialized either. In conclusion these checks are not necessary since they never evaluate to true and can be dropped. If they should ever become necessary they should be done in the sigrok core so all drivers and all callbacks are equally handled. Signed-off-by: Lars-Peter Clausen <l...@metafoo.de> --- src/hardware/ikalogic-scanalogic2/api.c | 13 +------------ src/hardware/kecheng-kc-330b/api.c | 19 +------------------ src/hardware/lascar-el-usb/api.c | 31 +------------------------------ src/hardware/lecroy-logicstudio/api.c | 7 ------- src/hardware/link-mso19/api.c | 5 +---- src/hardware/sysclk-lwla/api.c | 10 ---------- src/hardware/testo/api.c | 29 +---------------------------- src/hardware/uni-t-ut32x/api.c | 19 +------------------ src/hardware/victor-dmm/api.c | 29 ----------------------------- 9 files changed, 6 insertions(+), 156 deletions(-) diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index f7480db..0641018 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -188,17 +188,12 @@ static int dev_clear(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; - struct drv_context *drvc; + struct drv_context *drvc = di->context; struct dev_context *devc; struct sr_usb_dev_inst *usb; uint8_t buffer[PACKET_LENGTH]; int ret; - if (!(drvc = di->context)) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; devc = sdi->priv; @@ -259,14 +254,8 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 1214fad..80cafa8 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -168,15 +168,10 @@ static GSList *dev_list(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; - struct drv_context *drvc; + struct drv_context *drvc = di->context; struct sr_usb_dev_inst *usb; int ret; - if (!(drvc = di->context)) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK) @@ -198,15 +193,9 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) @@ -294,7 +283,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; uint64_t p, q; unsigned int i; @@ -306,11 +294,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - devc = sdi->priv; ret = SR_OK; switch (key) { diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index d2ed303..1fc4fe8 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -97,15 +97,10 @@ static GSList *dev_list(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; - struct drv_context *drvc; + struct drv_context *drvc = di->context;; struct sr_usb_dev_inst *usb; int ret; - if (!(drvc = di->context)) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK) @@ -122,14 +117,8 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) @@ -198,7 +187,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; int ret; @@ -207,11 +195,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - devc = sdi->priv; ret = SR_OK; switch (key) { @@ -341,11 +324,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - drvc = di->context; devc = sdi->priv; usb = sdi->conn; @@ -447,13 +425,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; - - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - if (sdi->status != SR_ST_ACTIVE) { sr_err("Device inactive, can't stop acquisition."); return SR_ERR; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index b6eff9d..ef2040d 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -273,19 +273,12 @@ static int open_device(struct sr_dev_inst *sdi) static int dev_open(struct sr_dev_inst *sdi) { - struct drv_context *drvc; struct dev_context *devc; int64_t timediff_us, timediff_ms; int ret; - drvc = sdi->driver->context; devc = sdi->priv; - if (!drvc) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - /* * If we didn't need to upload FX2 firmware in scan(), open the device * right away. Otherwise, wait up to MAX_RENUM_DELAY_MS ms for the diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index e0791ac..17e7acb 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -55,15 +55,12 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info; /* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */ static int dev_clear(const struct sr_dev_driver *di) { + struct drv_context *drvc = di->context; GSList *l; struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; int ret = SR_OK; - if (!(drvc = di->context)) - return SR_OK; - /* Properly close and free all devices. */ for (l = drvc->instances; l; l = l->next) { if (!(sdi = l->data)) { diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 8ee85a6..68aaa17 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -289,10 +289,6 @@ static int dev_open(struct sr_dev_inst *sdi) devc = sdi->priv; usb = sdi->conn; - if (!drvc) { - sr_err("Driver was not initialized."); - return SR_ERR; - } if (sdi->status != SR_ST_INACTIVE) { sr_err("Device already open."); return SR_ERR; @@ -356,19 +352,13 @@ static int dev_open(struct sr_dev_inst *sdi) */ static int dev_close(struct sr_dev_inst *sdi) { - struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; int ret; - drvc = sdi->driver->context; devc = sdi->priv; usb = sdi->conn; - if (!drvc) { - sr_err("Driver was not initialized."); - return SR_ERR; - } if (sdi->status == SR_ST_INACTIVE) { sr_dbg("Device already closed."); return SR_OK; diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index c43c3c7..ad8a24f 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -165,11 +165,6 @@ static int dev_open(struct sr_dev_inst *sdi) int ret, i; char connection_id[64]; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { @@ -209,14 +204,8 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) /* Nothing to do. */ @@ -271,7 +260,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd const struct sr_channel_group *cg) { struct sr_dev_driver *di = sdi->driver; - struct dev_context *devc; + struct dev_context *devc = sdi->priv; gint64 now; int ret; @@ -280,11 +269,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - devc = sdi->priv; ret = SR_OK; switch (key) { @@ -458,10 +442,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } devc = sdi->priv; usb = sdi->conn; @@ -498,13 +478,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; - - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index fe75241..dd823c8 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -106,15 +106,10 @@ static GSList *dev_list(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; - struct drv_context *drvc; + struct drv_context *drvc = di->context; struct sr_usb_dev_inst *usb; int ret; - if (!(drvc = di->context)) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK) @@ -150,14 +145,8 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) /* Nothing to do. */ @@ -214,7 +203,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; const char *tmp_str; @@ -223,11 +211,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - devc = sdi->priv; switch (key) { diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 1bc0344..279f754 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -115,11 +115,6 @@ static int dev_open(struct sr_dev_inst *sdi) int ret, i; char connection_id[64]; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); @@ -161,14 +156,8 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; if (!usb->devhdl) @@ -224,7 +213,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; gint64 now; @@ -233,11 +221,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - devc = sdi->priv; switch (key) { @@ -371,11 +354,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - usb = sdi->conn; std_session_send_df_header(sdi, LOG_PREFIX); @@ -404,13 +382,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct sr_dev_driver *di = sdi->driver; - - if (!di->context) { - sr_err("Driver was not initialized."); - return SR_ERR; - } - if (sdi->status != SR_ST_ACTIVE) { sr_err("Device not active, can't stop acquisition."); return SR_ERR; -- 2.1.4 ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! https://ad.doubleclick.net/ddm/clk/302982198;130105516;z _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel