labeler: fix codeql issues

Signed-off-by: Tuomas Katila <tuomas.katila@intel.com>
This commit is contained in:
Tuomas Katila 2023-12-05 15:21:45 +02:00
parent 08b76b12cc
commit a0bc682b9b
2 changed files with 53 additions and 2 deletions

View File

@ -16,6 +16,7 @@ package labeler
import ( import (
"fmt" "fmt"
"math"
"os" "os"
"os/signal" "os/signal"
"path" "path"
@ -205,12 +206,18 @@ func (l *labeler) getNumaNode(gpuName string) int {
return -1 return -1
} }
numa, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64) numa, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 32)
if err != nil { if err != nil {
klog.Warning("Can't convert numa_node: ", err) klog.Warning("Can't convert numa_node: ", err)
return -1 return -1
} }
if numa > math.MaxInt16 {
klog.Warning("Too large numa: ", numa)
return -1
}
return int(numa) return int(numa)
} }
@ -305,7 +312,9 @@ func (l *labeler) createLabels() error {
numaMapping[numaNode] = numaList numaMapping[numaNode] = numaList
} }
l.labels.addNumericLabel(labelNamespace+"memory.max", int64(memoryAmount)) if memoryAmount < math.MaxInt64 {
l.labels.addNumericLabel(labelNamespace+"memory.max", int64(memoryAmount))
}
} }
gpuCount := len(gpuNumList) gpuCount := len(gpuNumList)

View File

@ -520,6 +520,48 @@ func getTestCases() []testcase {
"gpu.intel.com/tiles": "27", "gpu.intel.com/tiles": "27",
}, },
}, },
{
sysfsdirs: []string{
"card1/device/drm/card1",
"card1/gt/gt0",
},
sysfsfiles: map[string][]byte{
"card1/device/vendor": []byte("0x8086"),
"card1/lmem_total_bytes": []byte("8000"),
"card1/device/numa_node": []byte("2147483648"), // max int32 + 1
},
name: "too large numa node",
memoryOverride: 16000000000,
expectedRetval: nil,
expectedLabels: labelMap{
"gpu.intel.com/millicores": "1000",
"gpu.intel.com/memory.max": "8000",
"gpu.intel.com/gpu-numbers": "1",
"gpu.intel.com/cards": "card1",
"gpu.intel.com/tiles": "1",
},
},
{
sysfsdirs: []string{
"card1/device/drm/card1",
"card1/gt/gt0",
},
sysfsfiles: map[string][]byte{
"card1/device/vendor": []byte("0x8086"),
"card1/lmem_total_bytes": []byte("8000"),
"card1/device/numa_node": []byte("32768"), // max int16 + 1
},
name: "too large numa node",
memoryOverride: 16000000000,
expectedRetval: nil,
expectedLabels: labelMap{
"gpu.intel.com/millicores": "1000",
"gpu.intel.com/memory.max": "8000",
"gpu.intel.com/gpu-numbers": "1",
"gpu.intel.com/cards": "card1",
"gpu.intel.com/tiles": "1",
},
},
} }
} }