Skip to content

Commit

Permalink
cppcheck - various fixes
Browse files Browse the repository at this point in the history
Add nullptr check; not that this will ever trigger, but sure, cppcheck
is correct about missing nullptr check.

Use override on virtual function overrides, but leave virtual if the
override makes the function pure virtual for additional derived classes.

Use explicit to avoid converting constructors, but allow converting
constructors for classes that act more or less as alias for type.

Signed-off-by: Soren Soe <[email protected]>
  • Loading branch information
stsoe committed Nov 25, 2024
1 parent df6db61 commit 4f9707e
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 286 deletions.
2 changes: 2 additions & 0 deletions src/runtime_src/core/common/api/hw_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class hw_queue : public xrt::detail::pimpl<hw_queue_impl>
hw_queue() = default;

// Construct from hwctx
explicit
hw_queue(const xrt::hw_context& hwctx);

// Legacy construction for internal support of command execution
// that is not tied to kernel execution, .e.g for copy_bo_with_kdma
XRT_CORE_COMMON_EXPORT
explicit
hw_queue(const xrt_core::device* device);

// Start a command and manage its execution by monitoring
Expand Down
13 changes: 11 additions & 2 deletions src/runtime_src/core/common/api/xrt_bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ class bo_impl
return device.get_hwctx_handle();
}

void*
get_hbuf_or_error() const
{
if (auto hbuf = get_hbuf())
return hbuf;

throw xrt_core::error("buffer is not mapped");
}

export_handle
export_buffer() const
{
Expand All @@ -338,7 +347,7 @@ class bo_impl
{
if (sz + seek > size)
throw xrt_core::error(-EINVAL,"attempting to write past buffer size");
auto hbuf = static_cast<char*>(get_hbuf()) + seek;
auto hbuf = static_cast<char*>(get_hbuf_or_error()) + seek;
std::memcpy(hbuf, src, sz);
}

Expand All @@ -347,7 +356,7 @@ class bo_impl
{
if (sz + skip > size)
throw xrt_core::error(-EINVAL,"attempting to read past buffer size");
auto hbuf = static_cast<char*>(get_hbuf()) + skip;
auto hbuf = static_cast<char*>(get_hbuf_or_error()) + skip;
std::memcpy(dst, hbuf, sz);
}

Expand Down
3 changes: 1 addition & 2 deletions src/runtime_src/core/common/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ update_cu_info()
// It assumes that m_xclbin is the single xclbin and that
// there is only one default slot with number 0.
auto ip_layout = get_axlf_section<const ::ip_layout*>(IP_LAYOUT);
auto& cu2idx = m_cu2idx[0u]; // default slot 0
if (ip_layout != nullptr) {
m_cus = xclbin::get_cus(ip_layout);
cu2idx = xclbin::get_cu_indices(ip_layout);
m_cu2idx[0u] = xclbin::get_cu_indices(ip_layout); // default slot 0
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/runtime_src/core/common/ishim.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ishim
class not_supported_error : public xrt_core::error
{
public:
explicit
not_supported_error(const std::string& msg)
: xrt_core::error{std::errc::not_supported, msg}
{}
Expand Down Expand Up @@ -253,6 +254,7 @@ template <typename DeviceType>
struct shim : public DeviceType
{
template <typename ...Args>
explicit
shim(Args&&... args)
: DeviceType(std::forward<Args>(args)...)
{}
Expand Down Expand Up @@ -410,6 +412,7 @@ template <typename DeviceType>
struct noshim : public DeviceType
{
template <typename ...Args>
explicit
noshim(Args&&... args)
: DeviceType(std::forward<Args>(args)...)
{}
Expand Down
Loading

0 comments on commit 4f9707e

Please sign in to comment.