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.
This commit is contained in:
v1ne 2020-04-08 17:05:16 +02:00 committed by Uwe Hermann
parent 8f3c77db26
commit 1d657f47be
1 changed files with 5 additions and 4 deletions

View File

@ -51,13 +51,14 @@ static struct sr_dev_inst *sr_modbus_scan_resource(const char *resource,
return NULL; return NULL;
}; };
if ((sdi = probe_device(modbus))) sdi = probe_device(modbus);
return sdi;
sr_modbus_close(modbus); sr_modbus_close(modbus);
sr_modbus_free(modbus);
return NULL; if (!sdi)
sr_modbus_free(modbus);
return sdi;
} }
/** /**