Skip to content

Commit 34d2302

Browse files
fix(mocknvml): address golangci-lint issues
Fix linter errors reported by CI: - Remove embedded field "Device" from selectors (QF1008 staticcheck) - Check error return values from fmt.Sscanf (errcheck) - Add nolint directive for intentional uintptr to unsafe.Pointer conversion Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent 3741a1c commit 34d2302

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

pkg/gpu/mocknvml/engine/device.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ func NewConfigurableDevice(index int, baseDevice *dgxa100.Device, config *Device
5050
// Override base device properties from config
5151
if config != nil {
5252
if config.Name != "" {
53-
dev.Device.Name = config.Name
53+
dev.Name = config.Name
5454
}
5555
if config.Architecture != "" {
56-
dev.Device.Architecture = parseArchitecture(config.Architecture)
56+
dev.Architecture = parseArchitecture(config.Architecture)
5757
}
5858
if config.Brand != "" {
59-
dev.Device.Brand = parseBrand(config.Brand)
59+
dev.Brand = parseBrand(config.Brand)
6060
}
6161
if config.ComputeCapability != nil {
62-
dev.Device.CudaComputeCapability = dgxa100.CudaComputeCapability{
62+
dev.CudaComputeCapability = dgxa100.CudaComputeCapability{
6363
Major: config.ComputeCapability.Major,
6464
Minor: config.ComputeCapability.Minor,
6565
}
6666
}
6767
if config.Memory != nil {
68-
dev.Device.MemoryInfo = nvml.Memory{
68+
dev.MemoryInfo = nvml.Memory{
6969
Total: config.Memory.TotalBytes,
7070
Free: config.Memory.FreeBytes,
7171
Used: config.Memory.UsedBytes,
@@ -75,22 +75,22 @@ func NewConfigurableDevice(index int, baseDevice *dgxa100.Device, config *Device
7575

7676
// Override UUID if provided
7777
if uuid != "" {
78-
dev.Device.UUID = uuid
78+
dev.UUID = uuid
7979
}
8080

8181
// Override PCI bus ID if provided
8282
if pciBusID != "" {
83-
dev.Device.PciBusID = pciBusID
83+
dev.PciBusID = pciBusID
8484
}
8585

8686
// Set minor number
87-
dev.Device.Minor = minorNumber
87+
dev.Minor = minorNumber
8888

8989
// Initialize cached values
9090
dev.initBAR1Memory()
9191
dev.initPciInfo()
9292

93-
debugLog("[DEVICE %d] Created: name=%s uuid=%s pci=%s\n", index, dev.Device.Name, dev.Device.UUID, dev.Device.PciBusID)
93+
debugLog("[DEVICE %d] Created: name=%s uuid=%s pci=%s\n", index, dev.Name, dev.UUID, dev.PciBusID)
9494

9595
return dev
9696
}
@@ -118,7 +118,7 @@ func (d *ConfigurableDevice) initPciInfo() {
118118
n, _ := fmt.Sscanf(d.PciBusID, "%x:%x:%x.%x", &domain, &bus, &device, &function)
119119
if n != 4 {
120120
// Try alternate format with full domain
121-
fmt.Sscanf(d.PciBusID, "%08x:%02x:%02x.%x", &domain, &bus, &device, &function)
121+
_, _ = fmt.Sscanf(d.PciBusID, "%08x:%02x:%02x.%x", &domain, &bus, &device, &function)
122122
}
123123

124124
d.pciInfo = nvml.PciInfo{
@@ -167,18 +167,18 @@ func (d *ConfigurableDevice) GetBAR1MemoryInfo() (nvml.BAR1Memory, nvml.Return)
167167

168168
// GetMemoryInfo returns GPU memory information
169169
func (d *ConfigurableDevice) GetMemoryInfo() (nvml.Memory, nvml.Return) {
170-
debugLog("[NVML] nvmlDeviceGetMemoryInfo -> total=%d\n", d.Device.MemoryInfo.Total)
171-
return d.Device.MemoryInfo, nvml.SUCCESS
170+
debugLog("[NVML] nvmlDeviceGetMemoryInfo -> total=%d\n", d.MemoryInfo.Total)
171+
return d.MemoryInfo, nvml.SUCCESS
172172
}
173173

174174
// GetMemoryInfo_v2 returns GPU memory information (v2 API)
175175
func (d *ConfigurableDevice) GetMemoryInfo_v2() (nvml.Memory_v2, nvml.Return) {
176176
mem := nvml.Memory_v2{
177177
Version: 2,
178-
Total: d.Device.MemoryInfo.Total,
178+
Total: d.MemoryInfo.Total,
179179
Reserved: 0,
180-
Free: d.Device.MemoryInfo.Free,
181-
Used: d.Device.MemoryInfo.Used,
180+
Free: d.MemoryInfo.Free,
181+
Used: d.MemoryInfo.Used,
182182
}
183183
// If we have config with reserved bytes, use it
184184
if d.config != nil && d.config.Memory != nil {
@@ -519,7 +519,7 @@ func (d *ConfigurableDevice) GetFanSpeed() (uint32, nvml.Return) {
519519
speed := uint32(0)
520520
if d.config != nil && d.config.Fan != nil {
521521
if d.config.Fan.SpeedPercent != "" && d.config.Fan.SpeedPercent != "N/A" {
522-
fmt.Sscanf(d.config.Fan.SpeedPercent, "%d", &speed)
522+
_, _ = fmt.Sscanf(d.config.Fan.SpeedPercent, "%d", &speed)
523523
}
524524
}
525525
debugLog("[NVML] nvmlDeviceGetFanSpeed -> %d%%\n", speed)
@@ -797,22 +797,22 @@ func (d *ConfigurableDevice) GetMigMode() (int, int, nvml.Return) {
797797

798798
// GetArchitecture returns GPU architecture
799799
func (d *ConfigurableDevice) GetArchitecture() (nvml.DeviceArchitecture, nvml.Return) {
800-
debugLog("[NVML] nvmlDeviceGetArchitecture -> %d\n", d.Device.Architecture)
801-
return d.Device.Architecture, nvml.SUCCESS
800+
debugLog("[NVML] nvmlDeviceGetArchitecture -> %d\n", d.Architecture)
801+
return d.Architecture, nvml.SUCCESS
802802
}
803803

804804
// GetCudaComputeCapability returns CUDA compute capability
805805
func (d *ConfigurableDevice) GetCudaComputeCapability() (int, int, nvml.Return) {
806-
major := d.Device.CudaComputeCapability.Major
807-
minor := d.Device.CudaComputeCapability.Minor
806+
major := d.CudaComputeCapability.Major
807+
minor := d.CudaComputeCapability.Minor
808808
debugLog("[NVML] nvmlDeviceGetCudaComputeCapability -> %d.%d\n", major, minor)
809809
return major, minor, nvml.SUCCESS
810810
}
811811

812812
// GetBrand returns device brand
813813
func (d *ConfigurableDevice) GetBrand() (nvml.BrandType, nvml.Return) {
814-
debugLog("[NVML] nvmlDeviceGetBrand -> %d\n", d.Device.Brand)
815-
return d.Device.Brand, nvml.SUCCESS
814+
debugLog("[NVML] nvmlDeviceGetBrand -> %d\n", d.Brand)
815+
return d.Brand, nvml.SUCCESS
816816
}
817817

818818
// GetEncoderUtilization returns encoder utilization

pkg/gpu/mocknvml/engine/handles.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (ht *HandleTable) Clear() {
110110

111111
// Free all allocated C handle blocks
112112
for handle := range ht.devices {
113+
//nolint:govet // Converting uintptr back to unsafe.Pointer is intentional here -
114+
// the handle was originally allocated as C memory and stored as uintptr for map key use
113115
C.freeHandle(unsafe.Pointer(handle))
114116
}
115117

0 commit comments

Comments
 (0)