From: v1ne Date: Wed, 8 Apr 2020 15:05:16 +0000 (+0200) Subject: modbus: Close device after scan X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1d657f47be01b2194f6caa7c55d95fc869bd86dc;p=libsigrok.git modbus: Close device after scan Since the device should be closed after the scan, close it in sr_modbus_scan. Alternatively, every single driver could close the device after calling sr_modbus_scan. This causes duplicated code, is prone to forgetting it and it wasn't the calling driver who opened the device in the first place. This change unbreaks maynuo-m97 and rdtech-dps. --- diff --git a/src/modbus/modbus.c b/src/modbus/modbus.c index 88be136c..b7bf2e5e 100644 --- a/src/modbus/modbus.c +++ b/src/modbus/modbus.c @@ -51,13 +51,14 @@ static struct sr_dev_inst *sr_modbus_scan_resource(const char *resource, return NULL; }; - if ((sdi = probe_device(modbus))) - return sdi; + sdi = probe_device(modbus); sr_modbus_close(modbus); - sr_modbus_free(modbus); - return NULL; + if (!sdi) + sr_modbus_free(modbus); + + return sdi; } /**