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

fix gocritic lint issues #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ linters:
enable:
- asciicheck
- contextcheck
- gocritic
- godot
- gofmt
- goimports
- misspell
# TODO: re-enable once we have addressed the warnings
disable:
- unused
- gocritic
- stylecheck
- forcetypeassert

Expand Down
2 changes: 1 addition & 1 deletion pkg/nvlib/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (d *device) GetBrandAsString() (string, error) {
case nvml.BRAND_NVIDIA_VWS:
return "NvidiaVWS", nil
// Deprecated in favor of nvml.BRAND_NVIDIA_CLOUD_GAMING
//case nvml.BRAND_NVIDIA_VGAMING:
// case nvml.BRAND_NVIDIA_VGAMING:
// return "VGaming", nil
case nvml.BRAND_NVIDIA_CLOUD_GAMING:
return "NvidiaCloudGaming", nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/nvpci/nvpci.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func (p *nvpci) getGPUByPciBusID(address string, cache map[string]*NvidiaPCIDevi
}

driver, err := filepath.EvalSymlinks(path.Join(devicePath, "driver"))
// nolint:gocritic
if err == nil {
driver = filepath.Base(driver)
} else if os.IsNotExist(err) {
Expand All @@ -291,6 +292,7 @@ func (p *nvpci) getGPUByPciBusID(address string, cache map[string]*NvidiaPCIDevi

var iommuGroup int64
iommu, err := filepath.EvalSymlinks(path.Join(devicePath, "iommu_group"))
// nolint:gocritic
if err == nil {
iommuGroupStr := strings.TrimSpace(filepath.Base(iommu))
iommuGroup, err = strconv.ParseInt(iommuGroupStr, 0, 64)
Expand Down Expand Up @@ -359,6 +361,7 @@ func (p *nvpci) getGPUByPciBusID(address string, cache map[string]*NvidiaPCIDevi
var sriovInfo SriovInfo
// Device is a virtual function (VF) if "physfn" symlink exists.
physFnAddress, err := filepath.EvalSymlinks(path.Join(devicePath, "physfn"))
// nolint:gocritic
if err == nil {
physFn, err := p.getGPUByPciBusID(filepath.Base(physFnAddress), cache)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/nvpci/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (mrs MemoryResources) GetTotalAddressableMemory(roundUp bool) (uint64, uint
if key >= pciIOVNumBAR || numBAR == pciIOVNumBAR {
break
}
numBAR = numBAR + 1
numBAR++

region := mrs[key]

Expand All @@ -123,10 +123,10 @@ func (mrs MemoryResources) GetTotalAddressableMemory(roundUp bool) (uint64, uint
memSize := (region.End - region.Start) + 1

if memType32bit {
memSize32bit = memSize32bit + uint64(memSize)
memSize32bit += uint64(memSize)
}
if memType64bit {
memSize64bit = memSize64bit + uint64(memSize)
memSize64bit += uint64(memSize)
}

}
Expand Down
10 changes: 5 additions & 5 deletions pkg/pciids/pciids.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (p *parser) parse() Interface {
hkClass = db.classes[uint32(id)]

hkFullID = uint32(id) << 16
hkFullID = hkFullID & 0xFFFF0000
hkFullID &= 0xFFFF0000
hkFullName[0] = fmt.Sprintf("%s (%02x)", lit.name, id)
}

Expand All @@ -408,11 +408,11 @@ func (p *parser) parse() Interface {
}
hkSubClass = hkClass.subClasses[uint32(id)]

// Clear the last detected sub class.
hkFullID = hkFullID & 0xFFFF0000
hkFullID = hkFullID | uint32(id)<<8
// Clear the last detected subclass.
hkFullID &= 0xFFFF0000
hkFullID |= uint32(id) << 8
// Clear the last detected prog iface.
hkFullID = hkFullID & 0xFFFFFF00
hkFullID &= 0xFFFFFF00
hkFullName[1] = fmt.Sprintf("%s (%02x)", lit.name, id)

db.classes[uint32(hkFullID)] = class{
Expand Down