usbip: fix E.New(fmt.Sprintf) and banned if-init error checks
Replace E.New(fmt.Sprintf("...0x%04x", v)) with variadic E.New(..., fmt.Sprintf("0x%04x", v)) so plain text and integer args flow through F.ToString (sing-box/common/stun/stun.go precedent). Hoist three sysfs_linux.go if-init error checks per .claude/rules/go-syntax.md ("assign first, then check"); two of them also shadowed the outer err.
This commit is contained in:
@@ -196,10 +196,10 @@ func (c *ClientService) attemptAttach(ctx context.Context, busid string) (Attach
|
||||
return nil, E.Cause(err, "read OP_REP_IMPORT header")
|
||||
}
|
||||
if header.Version != ProtocolVersion {
|
||||
return nil, E.New(fmt.Sprintf("unexpected reply version 0x%04x", header.Version))
|
||||
return nil, E.New("unexpected reply version ", fmt.Sprintf("0x%04x", header.Version))
|
||||
}
|
||||
if header.Code != expectedReply {
|
||||
return nil, E.New(fmt.Sprintf("unexpected reply code 0x%04x", header.Code))
|
||||
return nil, E.New("unexpected reply code ", fmt.Sprintf("0x%04x", header.Code))
|
||||
}
|
||||
if header.Status != OpStatusOK {
|
||||
return nil, E.New("remote rejected import (status=", header.Status, ")")
|
||||
|
||||
@@ -502,10 +502,10 @@ func (c *ClientService) fetchDevList(ctx context.Context) ([]DeviceEntry, error)
|
||||
return nil, E.Cause(err, "read OP_REP_DEVLIST header")
|
||||
}
|
||||
if header.Version != ProtocolVersion {
|
||||
return nil, E.New(fmt.Sprintf("unexpected reply version 0x%04x", header.Version))
|
||||
return nil, E.New("unexpected reply version ", fmt.Sprintf("0x%04x", header.Version))
|
||||
}
|
||||
if header.Code != OpRepDevList || header.Status != OpStatusOK {
|
||||
return nil, E.New(fmt.Sprintf("OP_REP_DEVLIST status=%d code=0x%04x", header.Status, header.Code))
|
||||
return nil, E.New("OP_REP_DEVLIST status=", header.Status, " code=", fmt.Sprintf("0x%04x", header.Code))
|
||||
}
|
||||
return ReadOpRepDevListBody(conn)
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@ func (s *darwinServerDataSession) serve() error {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return E.New(fmt.Sprintf("unexpected USB/IP command 0x%08x", header.Command))
|
||||
return E.New("unexpected USB/IP command ", fmt.Sprintf("0x%08x", header.Command))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +107,13 @@ func readSysfsDevice(busid, path string) (sysfsDevice, error) {
|
||||
d.VendorID = vendor
|
||||
d.ProductID, _ = readHexU16(path, "idProduct")
|
||||
d.BCDDevice, _ = readHexU16(path, "bcdDevice")
|
||||
if v, err := readDecU32(path, "busnum"); err == nil {
|
||||
d.BusNum = v
|
||||
busNum, err := readDecU32(path, "busnum")
|
||||
if err == nil {
|
||||
d.BusNum = busNum
|
||||
}
|
||||
if v, err := readDecU32(path, "devnum"); err == nil {
|
||||
d.DevNum = v
|
||||
devNum, err := readDecU32(path, "devnum")
|
||||
if err == nil {
|
||||
d.DevNum = devNum
|
||||
}
|
||||
d.Speed = speedCodeFromString(readString(path, "speed"))
|
||||
d.DeviceClass, _ = readHexU8(path, "bDeviceClass")
|
||||
@@ -334,13 +336,14 @@ func ensureKernelPath(path string, module string, description string) error {
|
||||
}
|
||||
|
||||
func findModprobePath() (string, error) {
|
||||
if path, err := exec.LookPath("modprobe"); err == nil {
|
||||
return path, nil
|
||||
modprobePath, err := exec.LookPath("modprobe")
|
||||
if err == nil {
|
||||
return modprobePath, nil
|
||||
}
|
||||
for _, path := range []string{"/usr/sbin/modprobe", "/sbin/modprobe", "/usr/bin/modprobe", "/bin/modprobe"} {
|
||||
info, err := os.Stat(path)
|
||||
if err == nil && info.Mode().IsRegular() && info.Mode()&0o111 != 0 {
|
||||
return path, nil
|
||||
for _, candidate := range []string{"/usr/sbin/modprobe", "/sbin/modprobe", "/usr/bin/modprobe", "/bin/modprobe"} {
|
||||
info, statErr := os.Stat(candidate)
|
||||
if statErr == nil && info.Mode().IsRegular() && info.Mode()&0o111 != 0 {
|
||||
return candidate, nil
|
||||
}
|
||||
}
|
||||
return "", E.New("modprobe executable not found")
|
||||
|
||||
@@ -270,7 +270,7 @@ func (p *UsbIpPeer) readLoop() {
|
||||
}
|
||||
transaction.finalize(SubmitResponse{}, ErrCanceled)
|
||||
default:
|
||||
p.setReadError(E.New(fmt.Sprintf("unexpected USB/IP response 0x%08x", header.Command)))
|
||||
p.setReadError(E.New("unexpected USB/IP response ", fmt.Sprintf("0x%08x", header.Command)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user