Skip to content

Commit

Permalink
linters: avoid redefining Go built-in functions min/max/cap
Browse files Browse the repository at this point in the history
This is for golangci-lint to stop complaining about:

	revive  redefines-builtin-id: redefinition of the built-in function max

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Nov 25, 2024
1 parent 01423ba commit 4d79986
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/reader/caps/caps.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func AreSubset(a uint64, set uint64) bool {
}

// capToMask() returns the mask of the corresponding u32
func capToMask(cap int32) uint32 {
return uint32(1 << ((cap) & 31))
func capToMask(capability int32) uint32 {
return uint32(1 << ((capability) & 31))
}

// GetCapsFullSet() Returns up to date (go unix library) full set.
Expand Down
22 changes: 11 additions & 11 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ func (s *Sensor) loadMap(bpfDir string, m *program.Map) error {
pinPath := filepath.Join(bpfDir, m.PinPath)

if m.IsOwner() {
// If map is the owner we set configured max entries
// If map is the owner we set configured maximum entries
// directly to map spec.
if max, ok := m.GetMaxEntries(); ok {
mapSpec.MaxEntries = max
if maximum, ok := m.GetMaxEntries(); ok {
mapSpec.MaxEntries = maximum
}

if innerMax, ok := m.GetMaxInnerEntries(); ok {
Expand All @@ -334,24 +334,24 @@ func (s *Sensor) loadMap(bpfDir string, m *program.Map) error {
}
}
} else {
// If map is NOT the owner we follow the max entries
// If map is NOT the owner we follow the maximum entries
// of the pinned map and update the spec with that.
max, err := program.GetMaxEntriesPinnedMap(pinPath)
maximum, err := program.GetMaxEntriesPinnedMap(pinPath)
if err != nil {
return err
}
mapSpec.MaxEntries = max
mapSpec.MaxEntries = maximum

// 'm' is not the owner but for some reason requires max
// 'm' is not the owner but for some reason requires maximum
// entries setup, make sure it matches the pinned map.
if max, ok := m.GetMaxEntries(); ok {
if mapSpec.MaxEntries != max {
if maximum, ok := m.GetMaxEntries(); ok {
if mapSpec.MaxEntries != maximum {
return fmt.Errorf("failed to load map '%s' max entries mismatch: %d %d",
m.Name, mapSpec.MaxEntries, max)
m.Name, mapSpec.MaxEntries, maximum)
}
}

m.SetMaxEntries(int(max))
m.SetMaxEntries(int(maximum))
}

// Disable content loading at this point, we just care about the map,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sensors/program/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ func doLoadProgram(
continue
}

if max, ok := m.GetMaxEntries(); ok {
ms.MaxEntries = max
if maximum, ok := m.GetMaxEntries(); ok {
ms.MaxEntries = maximum
}

if innerMax, ok := m.GetMaxInnerEntries(); ok {
Expand Down
8 changes: 4 additions & 4 deletions pkg/sensors/program/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ func GetMaxEntriesPinnedMap(pinPath string) (uint32, error) {
return m.MaxEntries(), nil
}

func (m *Map) SetMaxEntries(max int) {
m.Entries = MaxEntries{uint32(max), true}
func (m *Map) SetMaxEntries(maximum int) {
m.Entries = MaxEntries{uint32(maximum), true}
}

func (m *Map) SetInnerMaxEntries(max int) {
m.InnerEntries = MaxEntries{uint32(max), true}
func (m *Map) SetInnerMaxEntries(maximum int) {
m.InnerEntries = MaxEntries{uint32(maximum), true}
}

func (m *Map) GetMaxEntries() (uint32, bool) {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/helpers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ func SetMinKernelVersion() env.Func {
versionsInt = append(versionsInt, kernels.KernelStringToNumeric(kVersion))
}

min := int64(math.MaxInt64)
minimum := int64(math.MaxInt64)
var minStr string
for i := range versions {
verStr := versions[i]
verInt := versionsInt[i]

if verInt < min {
min = verInt
if verInt < minimum {
minimum = verInt
minStr = verStr
}
}
Expand Down

0 comments on commit 4d79986

Please sign in to comment.