Skip to content

Commit dbdb4c6

Browse files
committed
fix: keep direction masking consistent
1 parent 624630d commit dbdb4c6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/machine/usb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ func handleStandardSetup(setup usb.Setup) bool {
213213
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
214214
isRemoteWakeUpEnabled = false
215215
} else if setup.WValueL == 0 { // ENDPOINTHALT
216-
if setup.WIndex < usb.NumberOfEndpoints && usbStallHandler[setup.WIndex&0x7F] != nil {
216+
if idx := setup.WIndex & 0x7F; idx < usb.NumberOfEndpoints && usbStallHandler[idx] != nil {
217217
// Host has requested to clear an endpoint stall. If the request is addressed to
218218
// an endpoint with a configured StallHandler, forward the message on.
219219
// The 0x7F mask is used to clear the direction bit from the endpoint number
220-
return usbStallHandler[setup.WIndex&0x7F](setup)
220+
return usbStallHandler[idx](setup)
221221
}
222222
isEndpointHalt = false
223223
}
@@ -228,11 +228,11 @@ func handleStandardSetup(setup usb.Setup) bool {
228228
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
229229
isRemoteWakeUpEnabled = true
230230
} else if setup.WValueL == 0 { // ENDPOINTHALT
231-
if setup.WIndex < usb.NumberOfEndpoints && usbStallHandler[setup.WIndex&0x7F] != nil {
231+
if idx := setup.WIndex & 0x7F; idx < usb.NumberOfEndpoints && usbStallHandler[idx] != nil {
232232
// Host has requested to stall an endpoint. If the request is addressed to
233233
// an endpoint with a configured StallHandler, forward the message on.
234234
// The 0x7F mask is used to clear the direction bit from the endpoint number
235-
return usbStallHandler[setup.WIndex&0x7F](setup)
235+
return usbStallHandler[idx](setup)
236236
}
237237
isEndpointHalt = true
238238
}

0 commit comments

Comments
 (0)