From 140656e176d5ddbc28ba52ceede616b90193caef Mon Sep 17 00:00:00 2001 From: Kent Russell Date: Thu, 16 Jun 2022 10:58:00 -0400 Subject: [PATCH] rocm_smi.py: Handle corrupted serial number If the FRU has been corrupted, then the serial number will come in with any manner of random bytes, which will cause decode() to fail spectacularily. Check that the serial returned by the kernel is alphanumeric, and print to the error log if not (then continue to the next device). Change-Id: If4f35b140b6089e02729b1490ed6b48d614a122a [ROCm/rocm_smi_lib commit: 6b6e8403378ae84ba8ee5d7f17f64ed7663332b5] --- projects/rocm-smi-lib/python_smi_tools/rocm_smi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py index a1eb198e09..de014a77f3 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -2161,6 +2161,10 @@ def showSerialNumber(deviceList): for device in deviceList: sn = create_string_buffer(256) ret = rocmsmi.rsmi_dev_serial_number_get(device, sn, 256) + if not str(sn).isalnum(): + printErrLog(device, "FRU Serial Number contains non-alphanumeric characters. FRU is likely corrupted") + continue + if rsmi_ret_ok(ret, device) and sn.value.decode(): printLog(device, 'Serial Number', sn.value.decode()) else: