Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: clean up remaining golangci-lint failures #2962

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: golangci/golangci-lint-action@v2
with:
# must be specified without patch version
version: v1.36
version: v1.40
# Only show new issues for a pull request.
only-new-issues: true

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix for this #2696 (which started as a fix for this linter issue but ended up as a rewrite of parseStat to be 7x faster and more error-prone).

stat.State = State(state)
fmt.Sscanf(parts[22-3], "%d", &stat.StartTime)
return stat, nil
Expand Down