Merge pull request #2962 from cyphar/golint-fixes

*: clean up remaining golangci-lint failures
This commit is contained in:
Qiang Huang
2021-05-25 14:10:47 +08:00
committed by GitHub
6 changed files with 12 additions and 33 deletions
+1 -3
View File
@@ -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
@@ -110,8 +110,7 @@ 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)
@@ -119,7 +118,7 @@ func (p *program) appendRule(rule *devices.Rule) error {
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)
@@ -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
-8
View File
@@ -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{}
+4 -4
View File
@@ -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{
@@ -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{
@@ -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{
@@ -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{
@@ -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",
+1 -1
View File
@@ -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