X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdevice.c;h=99ccd42f1d9be3b78693a7f626c79e4d2b5010cd;hb=4d33f5e112d9f77ab3ae4cbdb7fea596f4f9a644;hp=9ba8bfc570cb43ed9bec54a661904b45ec6f7e88;hpb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;p=libsigrok.git diff --git a/src/device.c b/src/device.c index 9ba8bfc5..99ccd42f 100644 --- a/src/device.c +++ b/src/device.c @@ -135,10 +135,18 @@ SR_API int sr_dev_channel_enable(struct sr_channel *channel, gboolean state) return SR_OK; } -/* Returns the next enabled channel, wrapping around if necessary. */ -/** @private */ +/** + * Returns the next enabled channel, wrapping around if necessary. + * + * @param[in] sdi The device instance the channel is connected to. + * Must not be NULL. + * @param[in] cur_channel The current channel. + * + * @return A pointer to the next enabled channel of this device. + * + * @private + */ SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi, - struct sr_channel *cur_channel) { struct sr_channel *next_channel; @@ -529,19 +537,24 @@ SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver) */ SR_API int sr_dev_clear(const struct sr_dev_driver *driver) { - int ret; - if (!driver) { sr_err("Invalid driver."); return SR_ERR_ARG; } - if (driver->dev_clear) - ret = driver->dev_clear(driver); - else - ret = std_dev_clear(driver, NULL); + if (!driver->context) { + /* + * Driver was never initialized, nothing to do. + * + * No log message since this usually gets called for all + * drivers, whether they were initialized or not. + */ + return SR_OK; + } - return ret; + /* No log message here, too verbose and not very useful. */ + + return driver->dev_clear(driver); } /** @@ -605,8 +618,6 @@ SR_API int sr_dev_open(struct sr_dev_inst *sdi) */ SR_API int sr_dev_close(struct sr_dev_inst *sdi) { - int ret; - if (!sdi || !sdi->driver || !sdi->driver->dev_close) return SR_ERR_ARG; @@ -620,9 +631,7 @@ SR_API int sr_dev_close(struct sr_dev_inst *sdi) sr_dbg("%s: Closing device instance.", sdi->driver->name); - ret = sdi->driver->dev_close(sdi); - - return ret; + return sdi->driver->dev_close(sdi); } /** @@ -752,7 +761,9 @@ SR_API const char *sr_dev_inst_connid_get(const struct sr_dev_inst *sdi) if (b != usb->bus || a != usb->address) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id); break; }