From 23ab95b5f2a5a32212f7e4f5ed7eea444547664a Mon Sep 17 00:00:00 2001 From: Apurv Mishra Date: Mon, 16 Dec 2024 16:00:08 -0500 Subject: [PATCH] rocr: multiple uninitialized and unused variables Minor modifications to multiple source and header files based on Coverity report Change-Id: I4a73d0f56640983c4d5124e13c8c280245cca672 Signed-off-by: Apurv Mishra [ROCm/ROCR-Runtime commit: 699d0140be4adef912783f78e267230a7453ce7f] --- .../runtime/hsa-runtime/core/inc/scratch_cache.h | 2 +- projects/rocr-runtime/runtime/hsa-runtime/core/inc/signal.h | 6 +++++- .../runtime/hsa-runtime/core/runtime/amd_filter_device.cpp | 4 +--- .../runtime/hsa-runtime/core/runtime/amd_memory_region.cpp | 4 ++-- .../runtime/hsa-runtime/core/runtime/default_signal.cpp | 2 +- .../runtime/hsa-runtime/core/runtime/interrupt_signal.cpp | 2 +- .../runtime/hsa-runtime/core/runtime/signal.cpp | 2 +- .../runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp | 3 ++- .../rocr-runtime/runtime/hsa-runtime/loader/executable.hpp | 3 ++- 9 files changed, 16 insertions(+), 12 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/scratch_cache.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/scratch_cache.h index aab2ec63ae..4fcb242f7e 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/scratch_cache.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/scratch_cache.h @@ -61,7 +61,7 @@ class ScratchCache { bool large; uint32_t state; - node() : base(nullptr), state(FREE) {} + node() : base(nullptr), large(false), state(FREE) {} bool isFree() const { return state == FREE; } bool trimPending() const { return state == (ALLOC | TRIM); } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/signal.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/signal.h index 4fafb113d3..a37e196389 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/signal.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/signal.h @@ -90,7 +90,11 @@ struct SharedSignal { uint64_t sdma_end_ts; uint8_t reserved2[24]; - SharedSignal() { + SharedSignal() : + sdma_start_ts(0), + reserved{}, + sdma_end_ts(0), + reserved2{} { memset(&amd_signal, 0, sizeof(amd_signal)); amd_signal.kind = AMD_SIGNAL_KIND_INVALID; core_signal = nullptr; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_filter_device.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_filter_device.cpp index 1429c444e1..4c6d1ceea2 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_filter_device.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_filter_device.cpp @@ -137,10 +137,8 @@ int32_t RvdFilter::ProcessUuidToken(const std::string& token) { uint32_t uuidLen = devUuidList_[idx].length(); // Token could match UUID of another device - if (tokenLen > uuidLen) { - compareVal = -1; + if (tokenLen > uuidLen) continue; - } // Token could match as substring of device UUID compareVal = token.compare(0, tokenLen, devUuidList_[idx], 0, tokenLen); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index 6696864ba5..485239b1dd 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -474,11 +474,11 @@ hsa_status_t MemoryRegion::AllowAccess(uint32_t num_agents, // Adjust for fragments. Make accessibility sticky for fragments since this will satisfy the // union of accessible agents between the fragments in the block. - hsa_amd_pointer_info_t info; + hsa_amd_pointer_info_t info = {}; uint32_t agent_count = 0; hsa_agent_t* accessible = nullptr; MAKE_SCOPE_GUARD([&]() { free(accessible); }); - core::Runtime::PtrInfoBlockData blockInfo; + core::Runtime::PtrInfoBlockData blockInfo = {}; std::vector union_agents; info.size = sizeof(info); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp index 827acc6e9f..38c5a20590 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp @@ -96,7 +96,7 @@ hsa_signal_value_t BusyWaitSignal::WaitRelaxed(hsa_signal_condition_t condition, // Should be a few times bigger than null kernel latency const timer::fast_clock::duration kMaxElapsed = std::chrono::microseconds(200); - uint64_t hsa_freq; + uint64_t hsa_freq = 0; HSA::hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &hsa_freq); const timer::fast_clock::duration fast_timeout = timer::duration_from_seconds( diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/interrupt_signal.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/interrupt_signal.cpp index d8f46a8d0b..d7ba2139b3 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/interrupt_signal.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/interrupt_signal.cpp @@ -170,7 +170,7 @@ hsa_signal_value_t InterruptSignal::WaitRelaxed( // Should be a few times bigger than null kernel latency const timer::fast_clock::duration kMaxElapsed = std::chrono::microseconds(200); - uint64_t hsa_freq; + uint64_t hsa_freq = 0; HSA::hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &hsa_freq); const timer::fast_clock::duration fast_timeout = timer::duration_from_seconds( diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp index 8a60e25994..932a218730 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp @@ -245,7 +245,7 @@ uint32_t Signal::WaitAny(uint32_t signal_count, const hsa_signal_t* hsa_signals, const timer::fast_clock::duration kMaxElapsed = std::chrono::microseconds(200); // Convert timeout value into the fast_clock domain - uint64_t hsa_freq; + uint64_t hsa_freq = 0; HSA::hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &hsa_freq); const timer::fast_clock::duration fast_timeout = timer::duration_from_seconds( diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp index 831c1f7a78..1005d8d60c 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp @@ -891,6 +891,8 @@ namespace elf { GElfSection::GElfSection(GElfImage* elf_) : elf(elf_), + seg(nullptr), + hdr{}, memsize_(0), align_(0), reloc_sec(nullptr), @@ -1020,7 +1022,6 @@ namespace elf { if (coffset <= offset && offset <= coffset + edata->d_size) { csize = (std::min)(size, edata->d_size - offset); memcpy(dest, (const char*) edata->d_buf + offset - coffset, csize); - coffset += csize; dest = (char*) dest + csize; size -= csize; if (!size) { return true; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.hpp b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.hpp index 9429ff9486..d8ca3d6a75 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.hpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.hpp @@ -161,7 +161,8 @@ public: , is_dynamic_callstack(_is_dynamic_callstack) , size(_size) , alignment(_alignment) - , wavefront_size(_wavefront_size) {} + , wavefront_size(_wavefront_size) + , debug_info{} {} ~KernelSymbol() {}