From 1d657f47be01b2194f6caa7c55d95fc869bd86dc Mon Sep 17 00:00:00 2001 From: v1ne Date: Wed, 8 Apr 2020 17:05:16 +0200 Subject: [PATCH] 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. --- src/modbus/modbus.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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; } /**