On Sat, 2020-04-11 at 22:45 +0200, Wolfram Sang wrote: > > I want to fix this double-close issue: > > First close at the end of a 'scan': > > sr: [00:00.045171] openbench-logic-sniffer: Got metadata key 0x00, metadata > ends. > sr: [00:00.045178] openbench-logic-sniffer: Disabling demux mode. > sr: [00:00.045186] serial: Closing serial port /dev/ttyACM0. > > Second one as part of hwdriver cleanup: > > sr: [00:00.046088] hwdriver: Cleaning up all drivers. > sr: [00:00.046108] serial: Closing serial port /dev/ttyACM0. > sr: [00:00.046116] serial-libsp: Cannot close unopened serial port > /dev/ttyACM0. > > So, before closing a second time, check if the device is not idle.
Agreed on the motivation, and the approach to implement the fix. > I am not sure if the added condition is good enough. Yet, I'd appreciate > comments to see if I am on the right track. > [ ... ] > - if (driver->dev_close) > + if (driver->dev_close && sdi->status == SR_ST_ACTIVE) > driver->dev_close(sdi); Is the device driver's or the serial port's close an issue? Or one of them first and the other one as a consequence? Haven't checked the code base, so I'm talking from the top of my head here, and may miss something. The most reliable check would be to track the device driver's (and the serial port's) getting opened, or being open. Ideally to cope with redundant close calls at the respective layers. Each of them separately, based on their respective internal state. I'm afraid the "sdi->status == SR_ST_ACTIVE" check only will tell whether a data acquisition is running, not whether the device got opened and still is. Haven't dug up a better condition though. virtually yours Gerhard Sittig -- If you don't understand or are scared by any of the above ask your parents or an adult to help you. _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel