From c6f02b4d62d5ce2982fa87c602c5fb931d0aa5f9 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 5 Oct 2020 16:45:46 -0500 Subject: [PATCH] Fail gracefully if drm directory is not found Change-Id: I0f3ab2721108355752caf0280124469b98af4967 --- src/rocm_smi_main.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rocm_smi_main.cc b/src/rocm_smi_main.cc index cd4fc9110b..28d5bf60be 100755 --- a/src/rocm_smi_main.cc +++ b/src/rocm_smi_main.cc @@ -259,9 +259,13 @@ RocmSMI::Initialize(uint64_t flags) { ++i; } - // DiscoverAmdgpuDevices() will seach for devices and monitors and update + // DiscoverAmdgpuDevices() will search for devices and monitors and update // internal data structures. - DiscoverAmdgpuDevices(); + ret = DiscoverAmdgpuDevices(); + if (ret != 0) { + throw amd::smi::rsmi_exception(RSMI_INITIALIZATION_ERROR, + "DiscoverAmdgpuDevices() failed."); + } // IterateSMIDevices will iterate through all the known devices and apply // the provided call-back to each device found. @@ -462,7 +466,9 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) { } auto drm_dir = opendir(kPathDRMRoot); - assert(drm_dir != nullptr); + if (drm_dir == nullptr) { + return 1; + } auto dentry = readdir(drm_dir);