From 858a6ee3f742678dff809fa3014ade79b567213c Mon Sep 17 00:00:00 2001 From: Soren Soe <2106410+stsoe@users.noreply.github.com> Date: Wed, 27 Nov 2024 08:16:06 -0800 Subject: [PATCH] Cov-* Misc Coverity fixes (#8623) Mostly move related fixes, and explicit ctors. Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com> --- src/runtime_src/core/common/api/xrt_bo.cpp | 2 +- .../core/common/api/xrt_kernel.cpp | 2 +- src/runtime_src/core/common/info_aie2.cpp | 14 +-- src/runtime_src/core/common/info_platform.cpp | 2 +- src/runtime_src/core/common/message.cpp | 2 +- src/runtime_src/core/common/sensor.cpp | 5 +- src/runtime_src/core/common/utils.cpp | 2 +- src/runtime_src/core/common/utils.h | 2 +- src/runtime_src/core/common/xclbin_parser.cpp | 2 +- .../core/include/experimental/xrt_elf.h | 2 + .../core/include/experimental/xrt_kernel.h | 1 + .../core/include/experimental/xrt_module.h | 1 + src/runtime_src/core/include/xrt/xrt_bo.h | 16 ++- src/runtime_src/tools/scripts/sprite.py | 108 ------------------ 14 files changed, 35 insertions(+), 126 deletions(-) delete mode 100644 src/runtime_src/tools/scripts/sprite.py diff --git a/src/runtime_src/core/common/api/xrt_bo.cpp b/src/runtime_src/core/common/api/xrt_bo.cpp index e1b614d24bc..a1fbd66538c 100755 --- a/src/runtime_src/core/common/api/xrt_bo.cpp +++ b/src/runtime_src/core/common/api/xrt_bo.cpp @@ -1463,7 +1463,7 @@ bo:: size() const { return xdp::native::profiling_wrapper("xrt::bo::size", [this]{ - return handle->get_size(); + return handle ? handle->get_size() : 0; }) ; } diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index c2f5008f3d2..77ebeb2eaeb 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -3816,7 +3816,7 @@ add_callback(ert_cmd_state state, // the key. Note that the callback cannot pass *this (xrt::run) as // these objects are transient. auto key = handle.get(); - handle->add_callback([=](ert_cmd_state state) { fcn(key, state, data); }); + handle->add_callback([fn = std::move(fcn), key, data](ert_cmd_state state) { fn(key, state, data); }); } ert_packet* diff --git a/src/runtime_src/core/common/info_aie2.cpp b/src/runtime_src/core/common/info_aie2.cpp index 1bd113e36a8..aa72ad69e22 100644 --- a/src/runtime_src/core/common/info_aie2.cpp +++ b/src/runtime_src/core/common/info_aie2.cpp @@ -744,34 +744,34 @@ get_aie_data(const xrt_core::device* device, const aie_tiles_info& info, aie_til if (tiles_status.cols_filled == 0) throw std::runtime_error("No open HW-Context\n"); - std::vector aie_status; + std::vector aie_status_vec; // Allocate an entry for each active column // See core/xrt/src/runtime_src/core/common/design_notes.md entry 1 uint32_t cols_filled = tiles_status.cols_filled; while (cols_filled) { if (cols_filled & 0x1) - aie_status.emplace_back(info); + aie_status_vec.emplace_back(info); cols_filled >>= 1; } switch (tile_type) { case aie_tile_type::core: - parse_core_tile_buf(tiles_status.buf, info, aie_status); + parse_core_tile_buf(tiles_status.buf, info, aie_status_vec); break; case aie_tile_type::shim: - parse_shim_tile_buf(tiles_status.buf, info, aie_status); + parse_shim_tile_buf(tiles_status.buf, info, aie_status_vec); break; case aie_tile_type::mem: - parse_mem_tile_buf(tiles_status.buf, info, aie_status); + parse_mem_tile_buf(tiles_status.buf, info, aie_status_vec); break; default : throw std::runtime_error("Unknown tile type in formatting AIE tiles status info"); } - struct aie_status result; - result.status = aie_status; + aie_status result; + result.status = std::move(aie_status_vec); result.columns_filled = tiles_status.cols_filled; return result; } diff --git a/src/runtime_src/core/common/info_platform.cpp b/src/runtime_src/core/common/info_platform.cpp index ad11cfe8394..7a99c4a37f4 100644 --- a/src/runtime_src/core/common/info_platform.cpp +++ b/src/runtime_src/core/common/info_platform.cpp @@ -352,7 +352,7 @@ add_mac_info(const xrt_core::device* device, ptree_type& pt) auto mac_addr_first = xrt_core::device_query(device); // new flow - if (mac_contiguous_num!=0 && !mac_addr_first.empty()) { + if (mac_contiguous_num != 0 && !mac_addr_first.empty()) { // Convert the mac address into a number uint64_t mac_addr_first_value = xrt_core::utils::mac_addr_to_value(mac_addr_first); diff --git a/src/runtime_src/core/common/message.cpp b/src/runtime_src/core/common/message.cpp index caa8ccbfe47..c3c0d826751 100644 --- a/src/runtime_src/core/common/message.cpp +++ b/src/runtime_src/core/common/message.cpp @@ -278,7 +278,7 @@ sendv(severity_level l, const char* tag, const char* format, va_list args) } ++len; //To include null terminator std::vector buf(len, 0); - std::vsnprintf(buf.data(), len, format, args); + std::ignore = std::vsnprintf(buf.data(), len, format, args); send(l, tag, buf.data()); } diff --git a/src/runtime_src/core/common/sensor.cpp b/src/runtime_src/core/common/sensor.cpp index a2c695228c6..6ea111ad0fb 100644 --- a/src/runtime_src/core/common/sensor.cpp +++ b/src/runtime_src/core/common/sensor.cpp @@ -157,9 +157,8 @@ read_data_driven_electrical(const std::vector& c // iterate over current data, store to ptree by converting to Amps from milli Amps for (const auto& tmp : voltage) { - auto desc = tmp.label; - pt.put("id", desc); - pt.put("description", desc); + pt.put("id", tmp.label); + pt.put("description", tmp.label); /* * Use below calculation for sensor values: * actual sensor value = sensor_value * (10 ^ (unit_modifier)) diff --git a/src/runtime_src/core/common/utils.cpp b/src/runtime_src/core/common/utils.cpp index 8449d7fc3e1..1f8847a573f 100644 --- a/src/runtime_src/core/common/utils.cpp +++ b/src/runtime_src/core/common/utils.cpp @@ -317,7 +317,7 @@ mac_addr_to_value(std::string mac_addr) } std::string -value_to_mac_addr(const uint64_t mac_addr_value) +value_to_mac_addr(uint64_t mac_addr_value) { // Any bits higher than position 48 will be ignored // If any are set throw an error as they cannot be placed into the mac address diff --git a/src/runtime_src/core/common/utils.h b/src/runtime_src/core/common/utils.h index f397b391fa2..8639ffa67d8 100644 --- a/src/runtime_src/core/common/utils.h +++ b/src/runtime_src/core/common/utils.h @@ -136,7 +136,7 @@ mac_addr_to_value(std::string mac_addr); XRT_CORE_COMMON_EXPORT std::string -value_to_mac_addr(const uint64_t mac_addr_value); +value_to_mac_addr(uint64_t mac_addr_value); XRT_CORE_COMMON_EXPORT int diff --git a/src/runtime_src/core/common/xclbin_parser.cpp b/src/runtime_src/core/common/xclbin_parser.cpp index 2293f5ae1f9..dfd768afbea 100644 --- a/src/runtime_src/core/common/xclbin_parser.cpp +++ b/src/runtime_src/core/common/xclbin_parser.cpp @@ -957,7 +957,7 @@ get_kernel_arguments(const char* xml_data, size_t xml_size, const std::string& k args.emplace_back(kernel_argument{ xml_arg.second.get(".name") ,xml_arg.second.get(".type", "no-type") - ,port + ,std::move(port) ,pwidth ,index ,convert(xml_arg.second.get(".offset")) diff --git a/src/runtime_src/core/include/experimental/xrt_elf.h b/src/runtime_src/core/include/experimental/xrt_elf.h index f94ea2916c7..8cb2ad9ad78 100644 --- a/src/runtime_src/core/include/experimental/xrt_elf.h +++ b/src/runtime_src/core/include/experimental/xrt_elf.h @@ -34,6 +34,7 @@ class elf : public detail::pimpl elf() = default; XRT_API_EXPORT + explicit elf(const std::string& fnm); /** @@ -44,6 +45,7 @@ class elf : public detail::pimpl * */ XRT_API_EXPORT + explicit elf(std::istream& stream); XRT_API_EXPORT diff --git a/src/runtime_src/core/include/experimental/xrt_kernel.h b/src/runtime_src/core/include/experimental/xrt_kernel.h index fe08fe70cfc..81f13d25104 100644 --- a/src/runtime_src/core/include/experimental/xrt_kernel.h +++ b/src/runtime_src/core/include/experimental/xrt_kernel.h @@ -90,6 +90,7 @@ class runlist : public detail::pimpl * Throws is invariant per run object hwctx requirement is violated. */ XRT_API_EXPORT + explicit runlist(const xrt::hw_context& hwctx); /** diff --git a/src/runtime_src/core/include/experimental/xrt_module.h b/src/runtime_src/core/include/experimental/xrt_module.h index 41492afa982..781e50afd70 100644 --- a/src/runtime_src/core/include/experimental/xrt_module.h +++ b/src/runtime_src/core/include/experimental/xrt_module.h @@ -56,6 +56,7 @@ class module : public detail::pimpl * The constructor retains ownership of the elf object. */ XRT_API_EXPORT + explicit module(const xrt::elf& elf); /** diff --git a/src/runtime_src/core/include/xrt/xrt_bo.h b/src/runtime_src/core/include/xrt/xrt_bo.h index 17fda1af2d2..b433fe285d7 100644 --- a/src/runtime_src/core/include/xrt/xrt_bo.h +++ b/src/runtime_src/core/include/xrt/xrt_bo.h @@ -67,6 +67,12 @@ struct pid_type { pid_t pid; }; class device; class hw_context; class bo_impl; +/*! + * @class bo + * + * @brief + * xrt::bo represents a buffer object that can be used as kernel argument + */ class bo { public: @@ -138,6 +144,12 @@ class bo /** * bo() - Constructor for empty bo + * + * A default constructed bo can be assigned to and can be used in a + * Boolean check along with comparison. + * + * Unless otherwise noted, it is undefined behavior to use xrt::bo + * APIs on a default constructed object. */ bo() {} @@ -469,6 +481,8 @@ class bo * * @return * Size of buffer in bytes + * + * Returns 0 for a default constructed xrt::bo. */ XCL_DRIVER_DLLESPEC size_t @@ -498,7 +512,7 @@ class bo * get_flags() - Get the flags with which this buffer was constructed * * @return - * The xrt::bo::Flgas used when the buffer was contructed + * The xrt::bo::flags used when the buffer was contructed */ XCL_DRIVER_DLLESPEC flags diff --git a/src/runtime_src/tools/scripts/sprite.py b/src/runtime_src/tools/scripts/sprite.py deleted file mode 100644 index c6d5129efa9..00000000000 --- a/src/runtime_src/tools/scripts/sprite.py +++ /dev/null @@ -1,108 +0,0 @@ - -# SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2019-2021 Xilinx, Inc. All rights reserved. -# - -import glob -import yaml -import os, os.path -from subprocess import call -from subprocess import Popen,PIPE,STDOUT - -HALLIB = "libxclgemdrv.so" -DSA_PLATFORM = "xilinx_xil-accel-rd-ku115_4ddr-xpr_4_0" -date = '0503' -output = '/scratch/umangp/sprite_' + date -dsa = 'ku115' -ver = '4_0' -#base = '/proj/rdi-xco/fisusr/no_backup/results/sdx_2017.1/sdx_ll_hw/' -base = '/proj/rdi-xco/fisusr/no_backup/results/sdx_2017.1/sdx_unit_hw/' - - -def get_args(ymlfile): - #print get_args.__name__ - #print ymlfile - yml = glob.glob(ymlfile) - #print yml - f = open(yml[0]) - data = yaml.safe_load(f) - f.close() - return data['args'] - - -def main(): - file = open('py.log', 'w+') - os.environ["HALLIB"]= HALLIB - os.environ["DSA_PLATFORM"]= DSA_PLATFORM - call(["mkdir", "-p", output]) - search = base + '*' + dsa + '*' + ver - result = glob.glob(search) - - try: - - for i in result: - dirname = os.path.split(i)[1] - #print dirname - - design = dirname[:10] - #print design - - - abcd= raw_input() - if abcd == "n" - continue - - new_dir = output + os.sep + design - print new_dir - - call(["mkdir", "-p", new_dir]) - - ymlfile = i + os.sep + '*' + date + '*' + os.sep + 'sdainfo.yml' - args = get_args(ymlfile) - print args - - yml = glob.glob(ymlfile) - - call(["cp", "-f", yml[0], new_dir]) - - resdir = os.path.split(yml[0])[0] - - xbinst = resdir + os.sep + 'xbinst' + os.sep + '*' - #print xbinst - - xbinst_files = glob.glob(xbinst) - #for filename in os.listdir(xbinst): - for filename in xbinst_files: - #print "UKP: " + filename - if ".log" in filename: - continue - if os.path.isfile(filename): - call(["cp", "-f", filename, new_dir]) - #print "UKP2: " +filename - - - print "......Running the test now... " - #cmd = "./host.exe " + args + " | tee output.log" - #print cmd - - my_env = os.environ.copy() - my_env["HALLIB"]= HALLIB - my_env["DSA_PLATFORM"]= DSA_PLATFORM - - p = Popen(["./host.exe " + args ], shell=True, cwd=new_dir, env=my_env) - #p = Popen(["./host.exe " + args + " | tee output.log" + "; dmesg -c| tee dmesg.log"], shell=True, cwd=new_dir, env=my_env) - p.wait() - #sts = Popen(["./host.exe ", args, " | tee output.log" ], shell=False, cwd=new_dir, env=my_env) - abcd= raw_input() - - file.write("\nReturn code of " + design + " : " + str(p.returncode)) - print "Return code of " + design + " : " + str(p.returncode) - print "========================================================" - except: - print "catching exception..." - file.close() - - -if __name__ == "__main__": - main() -