Skip to content

Commit

Permalink
Merge pull request #2962 from cyphar/golint-fixes
Browse files Browse the repository at this point in the history
*: clean up remaining golangci-lint failures
  • Loading branch information
hqhq authored May 25, 2021
2 parents ed47810 + 37767c0 commit bfcbc94
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 33 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:
- uses: golangci/golangci-lint-action@v2
with:
# must be specified without patch version
version: v1.36
# Only show new issues for a pull request.
only-new-issues: true
version: v1.40

shfmt:
runs-on: ubuntu-20.04
Expand Down
15 changes: 6 additions & 9 deletions libcontainer/cgroups/ebpf/devicefilter/devicefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ func (p *program) appendRule(rule *devices.Rule) error {
return errors.New("the program is finalized")
}

bpfType := int32(-1)
hasType := true
var bpfType int32
switch rule.Type {
case devices.CharDevice:
bpfType = int32(unix.BPF_DEVCG_DEV_CHAR)
case devices.BlockDevice:
bpfType = int32(unix.BPF_DEVCG_DEV_BLOCK)
default:
// We do not permit 'a', nor any other types we don't know about.
return errors.Errorf("invalid Type %q", string(rule.Type))
return errors.Errorf("invalid type %q", string(rule.Type))
}
if rule.Major > math.MaxUint32 {
return errors.Errorf("invalid major %d", rule.Major)
Expand Down Expand Up @@ -150,12 +149,10 @@ func (p *program) appendRule(rule *devices.Rule) error {
nextBlockSym = "block-" + strconv.Itoa(p.blockID+1)
prevBlockLastIdx = len(p.insts) - 1
)
if hasType {
p.insts = append(p.insts,
// if (R2 != bpfType) goto next
asm.JNE.Imm(asm.R2, bpfType, nextBlockSym),
)
}
p.insts = append(p.insts,
// if (R2 != bpfType) goto next
asm.JNE.Imm(asm.R2, bpfType, nextBlockSym),
)
if hasAccess {
p.insts = append(p.insts,
// if (R3 & bpfAccess != R3 /* use R1 as a temp var */) goto next
Expand Down
8 changes: 0 additions & 8 deletions libcontainer/cgroups/fs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,6 @@ func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error {
return nil
}

func memoryAssigned(cgroup *configs.Cgroup) bool {
return cgroup.Resources.Memory != 0 ||
cgroup.Resources.MemoryReservation != 0 ||
cgroup.Resources.MemorySwap > 0 ||
cgroup.Resources.OomKillDisable ||
(cgroup.Resources.MemorySwappiness != nil && int64(*cgroup.Resources.MemorySwappiness) != -1)
}

func getMemoryData(path, name string) (cgroups.MemoryData, error) {
memoryData := cgroups.MemoryData{}

Expand Down
8 changes: 4 additions & 4 deletions libcontainer/integration/seccomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSeccompDenyGetcwdWithErrno(t *testing.T) {

container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
defer container.Destroy() //nolint:errcheck

buffers := newStdBuffers()
pwd := &libcontainer.Process{
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestSeccompDenyGetcwd(t *testing.T) {

container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
defer container.Destroy() //nolint:errcheck

buffers := newStdBuffers()
pwd := &libcontainer.Process{
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestSeccompPermitWriteConditional(t *testing.T) {

container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
defer container.Destroy() //nolint:errcheck

buffers := newStdBuffers()
dmesg := &libcontainer.Process{
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestSeccompDenyWriteConditional(t *testing.T) {

container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
defer container.Destroy() //nolint:errcheck

buffers := newStdBuffers()
dmesg := &libcontainer.Process{
Expand Down
8 changes: 0 additions & 8 deletions libcontainer/seccomp/patchbpf/enosys_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ var testArches = []string{
"s390x",
}

func archStringToNative(arch string) (nativeArch, error) {
scmpArch, err := libseccomp.GetArchFromString(arch)
if err != nil {
return 0, fmt.Errorf("unknown architecture %q: %v", arch, err)
}
return archToNative(scmpArch)
}

func testEnosysStub(t *testing.T, defaultAction configs.Action, arches []string) {
explicitSyscalls := []string{
"setns",
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/system/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func parseStat(data string) (stat Stat_t, err error) {
// one (PID) and two (Name) in the paren-split.
parts = strings.Split(data[i+2:], " ")
var state int
fmt.Sscanf(parts[3-3], "%c", &state)
fmt.Sscanf(parts[3-3], "%c", &state) //nolint:staticcheck // "3-3" is more readable in this context.
stat.State = State(state)
fmt.Sscanf(parts[22-3], "%d", &stat.StartTime)
return stat, nil
Expand Down

0 comments on commit bfcbc94

Please sign in to comment.