Skip to content

Commit

Permalink
Merge pull request #1621 from kolyshkin/govet
Browse files Browse the repository at this point in the history
ci: enable govet and gosimple linters, fix found bugs
  • Loading branch information
rhatdan authored May 26, 2023
2 parents 55ee2d1 + e2e5530 commit 3a452d1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ run:
linters:
disable:
- errcheck
- gosimple
- govet
- staticcheck
2 changes: 1 addition & 1 deletion drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func getMountProgramFlagFile(path string) string {
}

func checkSupportVolatile(home, runhome string) (bool, error) {
feature := fmt.Sprintf("volatile")
const feature = "volatile"
volatileCacheResult, _, err := cachedFeatureCheck(runhome, feature)
var usingVolatile bool
if err == nil {
Expand Down
8 changes: 3 additions & 5 deletions pkg/devicemapper/devmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ func RemoveDeviceDeferred(name string) error {
// disable udev dm rules and delete the symlink under /dev/mapper by itself,
// even if the removal is deferred by the kernel.
cookie := new(uint)
var flags uint16
flags = DmUdevDisableLibraryFallback
flags := uint16(DmUdevDisableLibraryFallback)
if err := task.setCookie(cookie, flags); err != nil {
return fmt.Errorf("devicemapper: Can not set cookie: %s", err)
}
Expand Down Expand Up @@ -384,7 +383,7 @@ func CancelDeferredRemove(deviceName string) error {
return fmt.Errorf("devicemapper: Can't set sector %s", err)
}

if err := task.setMessage(fmt.Sprintf("@cancel_deferred_remove")); err != nil {
if err := task.setMessage("@cancel_deferred_remove"); err != nil {
return fmt.Errorf("devicemapper: Can't set message %s", err)
}

Expand Down Expand Up @@ -459,8 +458,7 @@ func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize
}

cookie := new(uint)
var flags uint16
flags = DmUdevDisableSubsystemRulesFlag | DmUdevDisableDiskRulesFlag | DmUdevDisableOtherRulesFlag
flags := uint16(DmUdevDisableSubsystemRulesFlag | DmUdevDisableDiskRulesFlag | DmUdevDisableOtherRulesFlag)
if err := task.setCookie(cookie, flags); err != nil {
return fmt.Errorf("devicemapper: Can't set cookie %s", err)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/devicemapper/devmapper_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ func dmTaskGetDepsFct(task *cdmTask) *Deps {
}

// golang issue: https://github.com/golang/go/issues/11925
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps))),
Len: int(Cdeps.count),
Cap: int(Cdeps.count),
}
devices := *(*[]C.uint64_t)(unsafe.Pointer(&hdr))
var devices []C.uint64_t
devicesHdr := (*reflect.SliceHeader)(unsafe.Pointer(&devices))
devicesHdr.Data = uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps)))
devicesHdr.Len = int(Cdeps.count)
devicesHdr.Cap = int(Cdeps.count)

deps := &Deps{
Count: uint32(Cdeps.count),
Expand Down
3 changes: 2 additions & 1 deletion pkg/ioutils/readers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func (p *perpetualReader) Read(buf []byte) (n int, err error) {
}

func TestCancelReadCloser(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
cancelReadCloser := NewCancelReadCloser(ctx, io.NopCloser(&perpetualReader{}))
for {
var buf [128]byte
Expand Down
5 changes: 4 additions & 1 deletion pkg/regexp/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// of apps that want to use global regex variables. This library initializes them on
// first use as opposed to the start of the executable.
type Regexp struct {
once sync.Once
once *sync.Once
regexp *regexp.Regexp
val string
}
Expand All @@ -22,7 +22,10 @@ func Delayed(val string) Regexp {
}
if precompile {
re.regexp = regexp.MustCompile(re.val)
} else {
re.once = &sync.Once{}
}

return re
}

Expand Down

0 comments on commit 3a452d1

Please sign in to comment.