Skip to content

Commit 2a542b4

Browse files
committed
fix: correct error return values
1 parent 6f4ed4b commit 2a542b4

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/machine/usb/msc/scsi_unmap.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ func (m *msc) scsiUnmap(b []byte) {
5151
for i := 8; i < descEnd; i += 16 {
5252
err := m.unmapBlocksFromDescriptor(b[i:], uint64(m.blockCount))
5353
if err != nil {
54-
// TODO: Might need a better error code here for device errors?
55-
m.sendScsiError(csw.StatusFailed, scsi.SenseVolumeOverflow, scsi.SenseCodeLBAOutOfRange)
54+
m.sendScsiError(csw.StatusFailed, scsi.SenseIllegalRequest, scsi.SenseCodeLBAOutOfRange)
5655
return
5756
}
5857
}

src/machine/usb/msc/setup.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package msc
33
import (
44
"machine"
55
"machine/usb"
6-
"machine/usb/msc/csw"
76
)
87

98
func setupPacketHandler(setup usb.Setup) bool {
@@ -36,6 +35,10 @@ func (m *msc) handleClearFeature(setup usb.Setup, wValue uint16) bool {
3635
if wValue != 0 {
3736
return ok
3837
}
38+
39+
// Clear the direction bit from the endpoint address for comparison
40+
wIndex := setup.WIndex & 0x7F
41+
3942
// Clearing the stall is not enough, continue stalling until a reset is received first
4043
// 6.6.1 CBW Not Valid
4144
// If the CBW is not valid, the device shall STALL the Bulk-In pipe. Also, the device
@@ -47,7 +50,6 @@ func (m *msc) handleClearFeature(setup usb.Setup, wValue uint16) bool {
4750
// (c) a Clear Feature HALT to the Bulk-Out endpoint (clear stall OUT)
4851
// https://usb.org/sites/default/files/usbmassbulk_10.pdf
4952
if m.state == mscStateNeedReset {
50-
wIndex := setup.WIndex & 0x7F // Clear the direction bit from the endpoint address for comparison
5153
if wIndex == usb.MSC_ENDPOINT_IN {
5254
m.stallEndpoint(usb.MSC_ENDPOINT_IN)
5355
} else if wIndex == usb.MSC_ENDPOINT_OUT {
@@ -56,9 +58,6 @@ func (m *msc) handleClearFeature(setup usb.Setup, wValue uint16) bool {
5658
return ok
5759
}
5860

59-
// Clear the direction bit from the endpoint address for comparison
60-
wIndex := setup.WIndex & 0x7F
61-
6261
// Clear the IN/OUT stalls if addressed to the endpoint, or both if addressed to the interface
6362
if wIndex == usb.MSC_ENDPOINT_IN || wIndex == mscInterface {
6463
m.clearStallEndpoint(usb.MSC_ENDPOINT_IN)
@@ -70,7 +69,7 @@ func (m *msc) handleClearFeature(setup usb.Setup, wValue uint16) bool {
7069
}
7170
// Send a CSW if needed to resume after the IN endpoint stall is cleared
7271
if m.state == mscStateStatus && wIndex == usb.MSC_ENDPOINT_IN {
73-
m.sendCSW(csw.StatusPassed)
72+
m.sendCSW(m.respStatus)
7473
ok = true
7574
}
7675

0 commit comments

Comments
 (0)