diff --git a/pkg/cpuid/cpuid_test.go b/pkg/cpuid/cpuid_test.go index 56ae9ba26..d7bdfda08 100644 --- a/pkg/cpuid/cpuid_test.go +++ b/pkg/cpuid/cpuid_test.go @@ -18,7 +18,7 @@ import "testing" func TestFeatureFromString(t *testing.T) { // Check that known features do match. - for feature, _ := range allFeatures { + for feature := range allFeatures { f, ok := FeatureFromString(feature.String()) if f != feature || !ok { t.Errorf("got %v, %v want %v, true", f, ok, feature) diff --git a/pkg/sentry/fs/lock/lock_test.go b/pkg/sentry/fs/lock/lock_test.go index 754f56194..2fd41bdd7 100644 --- a/pkg/sentry/fs/lock/lock_test.go +++ b/pkg/sentry/fs/lock/lock_test.go @@ -92,15 +92,15 @@ func TestCanLock(t *testing.T) { // 0 1024 2048 3072 4096 l := fill([]entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 2: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}}}, LockRange: LockRange{1024, 2048}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 3: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 3: {}}}, LockRange: LockRange{2048, 3072}, }, { @@ -217,7 +217,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -261,7 +261,7 @@ func TestSetLock(t *testing.T) { // 0 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, 4096}, }, { @@ -278,7 +278,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -296,7 +296,7 @@ func TestSetLock(t *testing.T) { LockRange: LockRange{0, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -327,7 +327,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -345,7 +345,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -359,11 +359,11 @@ func TestSetLock(t *testing.T) { // 0 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -376,7 +376,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -390,15 +390,15 @@ func TestSetLock(t *testing.T) { // 0 4096 8192 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{4096, 8192}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{8192, LockEOF}, }, }, @@ -411,7 +411,7 @@ func TestSetLock(t *testing.T) { // 0 1024 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, LockEOF}, }, }, @@ -425,7 +425,7 @@ func TestSetLock(t *testing.T) { // 0 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -438,7 +438,7 @@ func TestSetLock(t *testing.T) { // 0 4096 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, 4096}, }, }, @@ -457,11 +457,11 @@ func TestSetLock(t *testing.T) { // 0 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, LockEOF}, }, }, @@ -474,7 +474,7 @@ func TestSetLock(t *testing.T) { // 0 1024 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, LockEOF}, }, }, @@ -488,15 +488,15 @@ func TestSetLock(t *testing.T) { // 0 1024 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{1024, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -509,15 +509,15 @@ func TestSetLock(t *testing.T) { // 0 1024 2048 4096 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, 2048}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -531,7 +531,7 @@ func TestSetLock(t *testing.T) { // 0 1024 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { @@ -539,7 +539,7 @@ func TestSetLock(t *testing.T) { LockRange: LockRange{1024, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -552,15 +552,15 @@ func TestSetLock(t *testing.T) { // 0 1024 2048 4096 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, 2048}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -574,7 +574,7 @@ func TestSetLock(t *testing.T) { // 0 1024 3072 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { @@ -582,7 +582,7 @@ func TestSetLock(t *testing.T) { LockRange: LockRange{1024, 3072}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -595,11 +595,11 @@ func TestSetLock(t *testing.T) { // 0 1024 2048 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, 2048}, }, }, @@ -621,15 +621,15 @@ func TestSetLock(t *testing.T) { LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{1024, 2048}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{2048, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -725,7 +725,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 2: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -738,7 +738,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 2: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -751,7 +751,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -783,7 +783,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -796,7 +796,7 @@ func TestUnlock(t *testing.T) { // 0 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -835,7 +835,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -848,7 +848,7 @@ func TestUnlock(t *testing.T) { // 0 4096 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}}}, LockRange: LockRange{0, 4096}, }, }, @@ -887,7 +887,7 @@ func TestUnlock(t *testing.T) { // 0 1024 4096 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{0, 1024}, }, { @@ -895,7 +895,7 @@ func TestUnlock(t *testing.T) { LockRange: LockRange{1024, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -908,11 +908,11 @@ func TestUnlock(t *testing.T) { // 0 1024 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -925,7 +925,7 @@ func TestUnlock(t *testing.T) { // 0 max uint64 before: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}, 2: {}}}, LockRange: LockRange{0, LockEOF}, }, }, @@ -938,15 +938,15 @@ func TestUnlock(t *testing.T) { // 0 1024 4096 max uint64 after: []entry{ { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}, 2: {}}}, LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}, 2: {}}}, LockRange: LockRange{1024, 4096}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}, 2: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}, 2: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -963,7 +963,7 @@ func TestUnlock(t *testing.T) { LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -980,7 +980,7 @@ func TestUnlock(t *testing.T) { LockRange: LockRange{0, 8}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -997,7 +997,7 @@ func TestUnlock(t *testing.T) { LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{4096, LockEOF}, }, }, @@ -1014,11 +1014,11 @@ func TestUnlock(t *testing.T) { LockRange: LockRange{0, 1024}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{1: {}}}, LockRange: LockRange{4096, 8192}, }, { - Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: OwnerInfo{}, 1: OwnerInfo{}}}, + Lock: Lock{Readers: map[UniqueID]OwnerInfo{0: {}, 1: {}}}, LockRange: LockRange{8192, LockEOF}, }, }, diff --git a/pkg/sentry/fsimpl/cgroupfs/base.go b/pkg/sentry/fsimpl/cgroupfs/base.go index c3209573d..ed0796eb5 100644 --- a/pkg/sentry/fsimpl/cgroupfs/base.go +++ b/pkg/sentry/fsimpl/cgroupfs/base.go @@ -342,7 +342,7 @@ func (d *cgroupProcsData) Generate(ctx context.Context, buf *bytes.Buffer) error } pgidList := make([]kernel.ThreadID, 0, len(pgids)) - for pgid, _ := range pgids { + for pgid := range pgids { pgidList = append(pgidList, pgid) } sortTIDs(pgidList) diff --git a/pkg/sentry/kernel/cgroup.go b/pkg/sentry/kernel/cgroup.go index 70880f708..98f48ee8a 100644 --- a/pkg/sentry/kernel/cgroup.go +++ b/pkg/sentry/kernel/cgroup.go @@ -335,7 +335,7 @@ func (r *CgroupRegistry) Unregister(hid uint32) { // +checklocks:r.mu func (r *CgroupRegistry) unregisterLocked(hid uint32) { if h, ok := r.hierarchies[hid]; ok { - for name, _ := range h.controllers { + for name := range h.controllers { delete(r.controllers, name) } delete(r.hierarchies, hid) @@ -352,7 +352,7 @@ func (r *CgroupRegistry) computeInitialGroups(inherit map[Cgroup]struct{}) map[C cgset := make(map[Cgroup]struct{}) // Remember controllers from the inherited cgroups set... - for cg, _ := range inherit { + for cg := range inherit { cg.IncRef() // Ref transferred to caller. for _, ctl := range cg.Controllers() { ctlSet[ctl.Type()] = ctl diff --git a/pkg/sentry/kernel/task_cgroup.go b/pkg/sentry/kernel/task_cgroup.go index efdad19f6..aebe492e4 100644 --- a/pkg/sentry/kernel/task_cgroup.go +++ b/pkg/sentry/kernel/task_cgroup.go @@ -42,7 +42,7 @@ func (t *Task) EnterInitialCgroups(parent *Task) { defer t.mu.Unlock() // Transfer ownership of joinSet refs to the task's cgset. t.cgroups = joinSet - for c, _ := range t.cgroups { + for c := range t.cgroups { // Since t isn't in any cgroup yet, we can skip the check against // existing cgroups. c.Enter(t) @@ -59,7 +59,7 @@ func (t *Task) EnterCgroup(c Cgroup) error { t.mu.Lock() defer t.mu.Unlock() - for oldCG, _ := range t.cgroups { + for oldCG := range t.cgroups { if oldCG.HierarchyID() == c.HierarchyID() { log.Warningf("Cannot enter new cgroup %v due to conflicting controllers. Try migrate instead?", c) return linuxerr.EBUSY @@ -103,7 +103,7 @@ func (t *Task) LeaveCgroups() { // +checklocks:t.mu func (t *Task) findCgroupWithMatchingHierarchyLocked(other Cgroup) (Cgroup, bool) { - for c, _ := range t.cgroups { + for c := range t.cgroups { if c.HierarchyID() != other.HierarchyID() { continue } @@ -191,7 +191,7 @@ func (t *Task) GenerateProcTaskCgroup(buf *bytes.Buffer) { defer t.mu.Unlock() cgEntries := make([]taskCgroupEntry, 0, len(t.cgroups)) - for c, _ := range t.cgroups { + for c := range t.cgroups { ctls := c.Controllers() ctlNames := make([]string, 0, len(ctls)) for _, ctl := range ctls { @@ -215,7 +215,7 @@ func (t *Task) GenerateProcTaskCgroup(buf *bytes.Buffer) { // +checklocks:t.mu func (t *Task) chargeLocked(target *Task, ctl CgroupControllerType, res CgroupResourceType, value int64) error { - for c, _ := range t.cgroups { + for c := range t.cgroups { if err := c.Charge(target, c.Dentry, ctl, res, value); err != nil { return err } diff --git a/pkg/sentry/platform/platform.go b/pkg/sentry/platform/platform.go index bae31ef1f..3f99b1261 100644 --- a/pkg/sentry/platform/platform.go +++ b/pkg/sentry/platform/platform.go @@ -446,7 +446,7 @@ func Register(name string, platform Constructor) { // List lists available platforms. func List() (available []string) { - for name, _ := range platforms { + for name := range platforms { available = append(available, name) } return diff --git a/pkg/sync/locking/lockdep.go b/pkg/sync/locking/lockdep.go index 7de0bf275..d58c2c825 100644 --- a/pkg/sync/locking/lockdep.go +++ b/pkg/sync/locking/lockdep.go @@ -100,7 +100,7 @@ func AddGLock(class *MutexClass, subclass uint32) { } // Check dependencies and add locked mutexes to the ancestors list. - for prevClass, _ := range *currentLocks { + for prevClass := range *currentLocks { if prevClass == class { panic(fmt.Sprintf("nested locking: %s:\n%s", *classMap.Load(class), log.Stacks(false))) } diff --git a/pkg/tcpip/header/checksum_test.go b/pkg/tcpip/header/checksum_test.go index 020ee792a..70158297c 100644 --- a/pkg/tcpip/header/checksum_test.go +++ b/pkg/tcpip/header/checksum_test.go @@ -41,22 +41,22 @@ func TestChecksumer(t *testing.T) { { name: "OneOddView", data: [][]byte{ - []byte{1, 9, 0, 5, 4}, + {1, 9, 0, 5, 4}, }, want: 1294, }, { name: "TwoOddViews", data: [][]byte{ - []byte{1, 9, 0, 5, 4}, - []byte{4, 3, 7, 1, 2, 123}, + {1, 9, 0, 5, 4}, + {4, 3, 7, 1, 2, 123}, }, want: 33819, }, { name: "OneEvenView", data: [][]byte{ - []byte{1, 9, 0, 5}, + {1, 9, 0, 5}, }, want: 270, }, @@ -71,9 +71,9 @@ func TestChecksumer(t *testing.T) { { name: "ThreeViews", data: [][]byte{ - []byte{77, 11, 33, 0, 55, 44}, - []byte{98, 1, 9, 0, 5, 4}, - []byte{4, 3, 7, 1, 2, 123, 99}, + {77, 11, 33, 0, 55, 44}, + {98, 1, 9, 0, 5, 4}, + {4, 3, 7, 1, 2, 123, 99}, }, want: 34236, }, diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go index 820c608d6..e221557f2 100644 --- a/pkg/tcpip/network/ipv4/ipv4.go +++ b/pkg/tcpip/network/ipv4/ipv4.go @@ -1440,10 +1440,10 @@ func NewProtocolWithOptions(opts Options) stack.NetworkProtocolFactory { // Set ICMP rate limiting to Linux defaults. // See https://man7.org/linux/man-pages/man7/icmp.7.html. p.icmpRateLimitedTypes = map[header.ICMPv4Type]struct{}{ - header.ICMPv4DstUnreachable: struct{}{}, - header.ICMPv4SrcQuench: struct{}{}, - header.ICMPv4TimeExceeded: struct{}{}, - header.ICMPv4ParamProblem: struct{}{}, + header.ICMPv4DstUnreachable: {}, + header.ICMPv4SrcQuench: {}, + header.ICMPv4TimeExceeded: {}, + header.ICMPv4ParamProblem: {}, } return p } diff --git a/pkg/tcpip/tests/integration/loopback_test.go b/pkg/tcpip/tests/integration/loopback_test.go index 244119f25..98a63d5ee 100644 --- a/pkg/tcpip/tests/integration/loopback_test.go +++ b/pkg/tcpip/tests/integration/loopback_test.go @@ -739,19 +739,19 @@ func TestExternalLoopbackTraffic(t *testing.T) { } s.SetRouteTable([]tcpip.Route{ - tcpip.Route{ + { Destination: header.IPv4EmptySubnet, NIC: nicID1, }, - tcpip.Route{ + { Destination: header.IPv6EmptySubnet, NIC: nicID1, }, - tcpip.Route{ + { Destination: ipv4Loopback.WithPrefix().Subnet(), NIC: nicID2, }, - tcpip.Route{ + { Destination: header.IPv6Loopback.WithPrefix().Subnet(), NIC: nicID2, }, diff --git a/pkg/trie/trie_test.go b/pkg/trie/trie_test.go index b1ac71e4c..cadf1e53c 100644 --- a/pkg/trie/trie_test.go +++ b/pkg/trie/trie_test.go @@ -84,11 +84,11 @@ func TestAscendingSearch(t *testing.T) { tr.SetValue("abcde", "value abcde") expected := []Entry{ - Entry{Key: "a", Value: "value a"}, - Entry{Key: "ab", Value: "value ab"}, - Entry{Key: "abc", Value: "value abc"}, - Entry{Key: "abcd", Value: "value abcd"}, - Entry{Key: "abcde", Value: "value abcde"}} + {Key: "a", Value: "value a"}, + {Key: "ab", Value: "value ab"}, + {Key: "abc", Value: "value abc"}, + {Key: "abcd", Value: "value abcd"}, + {Key: "abcde", Value: "value abcde"}} arr := collectPrefixes(tr, "abcdef") if d := cmp.Diff(expected, arr); d != "" { t.Errorf("collectPrefixes(tr, 'abcdef') returned diff (-want +got):\n%s", d) @@ -124,7 +124,7 @@ func TestRoot(t *testing.T) { t.Errorf("tr.Size() = %d; want 1", tr.Size()) } - expected := []Entry{Entry{Key: "", Value: "root value"}} + expected := []Entry{{Key: "", Value: "root value"}} arr := collectPrefixes(tr, "foo") if d := cmp.Diff(expected, arr); d != "" { t.Errorf("collectPrefixes(tr, 'foo') returned diff (-want +got):\n%s", d) diff --git a/tools/checklinkname/known.go b/tools/checklinkname/known.go index aa4d61745..b68306517 100644 --- a/tools/checklinkname/known.go +++ b/tools/checklinkname/known.go @@ -41,53 +41,53 @@ package checklinkname // // TODO(b/165820485): Add option to specific per-version signatures. var knownLinknames = map[string]map[string]linknameSignatures{ - "runtime": map[string]linknameSignatures{ - "entersyscall": linknameSignatures{ + "runtime": { + "entersyscall": { local: "func()", }, - "entersyscallblock": linknameSignatures{ + "entersyscallblock": { local: "func()", }, - "exitsyscall": linknameSignatures{ + "exitsyscall": { local: "func()", }, - "fastrand": linknameSignatures{ + "fastrand": { local: "func() uint32", }, - "gopark": linknameSignatures{ + "gopark": { // TODO(b/165820485): add verification of waitReason // size and reason and traceEv values. local: "func(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int)", remote: "func(unlockf func(*runtime.g, unsafe.Pointer) bool, lock unsafe.Pointer, reason runtime.waitReason, traceEv byte, traceskip int)", }, - "goready": linknameSignatures{ + "goready": { local: "func(gp uintptr, traceskip int)", remote: "func(gp *runtime.g, traceskip int)", }, - "goyield": linknameSignatures{ + "goyield": { local: "func()", }, - "memmove": linknameSignatures{ + "memmove": { local: "func(to unsafe.Pointer, from unsafe.Pointer, n uintptr)", }, - "throw": linknameSignatures{ + "throw": { local: "func(s string)", }, - "wakep": linknameSignatures{ + "wakep": { local: "func()", }, - "nanotime": linknameSignatures{ + "nanotime": { local: "func() int64", }, }, - "sync": map[string]linknameSignatures{ - "runtime_canSpin": linknameSignatures{ + "sync": { + "runtime_canSpin": { local: "func(i int) bool", }, - "runtime_doSpin": linknameSignatures{ + "runtime_doSpin": { local: "func()", }, - "runtime_Semacquire": linknameSignatures{ + "runtime_Semacquire": { // The only difference here is the parameter names. We // can't just change our local use to match remote, as // the stdlib runtime and sync packages also disagree @@ -96,20 +96,20 @@ var knownLinknames = map[string]map[string]linknameSignatures{ local: "func(addr *uint32)", remote: "func(s *uint32)", }, - "runtime_Semrelease": linknameSignatures{ + "runtime_Semrelease": { // See above. local: "func(addr *uint32, handoff bool, skipframes int)", remote: "func(s *uint32, handoff bool, skipframes int)", }, }, - "syscall": map[string]linknameSignatures{ - "runtime_BeforeFork": linknameSignatures{ + "syscall": { + "runtime_BeforeFork": { local: "func()", }, - "runtime_AfterFork": linknameSignatures{ + "runtime_AfterFork": { local: "func()", }, - "runtime_AfterForkInChild": linknameSignatures{ + "runtime_AfterForkInChild": { local: "func()", }, }, diff --git a/tools/nogo/check/check.go b/tools/nogo/check/check.go index 19116a89f..25231d3b4 100644 --- a/tools/nogo/check/check.go +++ b/tools/nogo/check/check.go @@ -520,7 +520,7 @@ func (i *importer) checkPackage(path string, srcs []string) (*types.Package, Fin factsMu.RLock() defer factsMu.RUnlock() // Pull all local facts. - for obj, _ := range astFacts.Objects { + for obj := range astFacts.Objects { for typ := range localFactTypes { v := reflect.New(typ.Elem()) if astFacts.ImportFact(obj, v.Interface().(analysis.Fact)) { @@ -746,7 +746,7 @@ func SplitPackages(srcs []string, srcRootPrefix string) map[string][]string { // // TODO(b/201686256): remove once tooling can handle type parameters. var usesTypeParams = map[string]struct{}{ - "sync/atomic": struct{}{}, // https://go.dev/issue/50860 + "sync/atomic": {}, // https://go.dev/issue/50860 } // Bundle checks a bundle of files (typically the standard library). @@ -758,7 +758,7 @@ func Bundle(sources map[string][]string) (FindingSet, facts.Serializer, error) { cache: make(map[string]*importerEntry), imports: make(map[string]*types.Package), } - for pkg, _ := range sources { + for pkg := range sources { // Was there an error processing this package? if _, err := i.importPackage(pkg); err != nil && err != ErrSkip { return nil, nil, err diff --git a/tools/nogo/config/config_test.go b/tools/nogo/config/config_test.go index cbd2845f2..549380a41 100644 --- a/tools/nogo/config/config_test.go +++ b/tools/nogo/config/config_test.go @@ -54,7 +54,7 @@ func TestShouldReport(t *testing.T) { // has no effect on configuration below. }, Analyzers: map[string]AnalyzerConfig{ - "analyzer-suppressions": AnalyzerConfig{ + "analyzer-suppressions": { // Suppress some. "default-enabled": &ItemConfig{ Exclude: []string{"limited-exclude.go"}, @@ -63,7 +63,7 @@ func TestShouldReport(t *testing.T) { // Enable all. "default-disabled": nil, }, - "enabled-for-default-disabled": AnalyzerConfig{ + "enabled-for-default-disabled": { "default-disabled": nil, "default-disabled-omitted-from-global": nil, },