usbip: modernize loops and drop unused test helpers

Address `golangci-lint` modernize and unused warnings:
- replace map copy loops with `maps.Copy`
- collapse `if x > y { x = y }` clamps to `min`/`max`
- switch `for i := 0; i < n; i++` to `for i := range n`
- use `t.Context()` in the relay handoff test
- delete the unused `removeOnce` field and `openBinaryDevice` helper
This commit is contained in:
世界
2026-05-15 15:01:07 +08:00
parent 05b34a4b11
commit 37065daccf
9 changed files with 20 additions and 46 deletions
+3 -4
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"net"
"os"
"path/filepath"
@@ -197,9 +198,7 @@ func (h *linuxExportHost) Reconcile(ctx context.Context, isBusy func(busid strin
h.access.Lock()
current := make(map[string]*linuxExport, len(h.exports))
for busid, exp := range h.exports {
current[busid] = exp
}
maps.Copy(current, h.exports)
h.access.Unlock()
for busid, device := range desired {
@@ -258,7 +257,7 @@ func (h *linuxExportHost) bindOne(d *sysfsDevice) (*linuxExport, error) {
exp *linuxExport
err error
)
for attempt := 0; attempt < 2; attempt++ {
for attempt := range 2 {
exp, err = h.bindOneOnce(d)
if err == nil {
return exp, nil