From 9cecdec977d236d363073db9f79b4580e3470124 Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Mon, 10 Apr 2017 03:16:59 +0200 Subject: [PATCH] Fix a bug where EndpointInfo would always be picked from the last alternative setting. When looking up matching EndpointInfo and InterfaceSetting for an endpoint, a reference to range variable is stored. If range is allowed to continue, the value of this variable will be updated. It's a trick to allow use of "nil" pointer as a "found" variable, but it requires a careful management of the range iterations. --- usb/device.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usb/device.go b/usb/device.go index 0a73c18..2e88e9f 100644 --- a/usb/device.go +++ b/usb/device.go @@ -132,6 +132,7 @@ func (d *Device) openEndpoint(cfgNum, ifNum, setNum, epAddr uint8) (*endpoint, e setAlternate = i != 0 debug.Printf("found setup: %+v [default: %v]\n", s, !setAlternate) ifs = &s + break } } if ifs == nil { @@ -143,6 +144,7 @@ func (d *Device) openEndpoint(cfgNum, ifNum, setNum, epAddr uint8) (*endpoint, e if endpointAddr(e.Number, e.Direction) == epAddr { debug.Printf("found ep #%d %s in %+v\n", e.Number, e.Direction, *ifs) ep = &e + break } } if ep == nil {