From a60c09f4470a8223830a02c341f71fdb4cb5ac7d Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 17 Oct 2024 08:05:17 -0300 Subject: [PATCH] refactor: fix cppcoreguidelines-non-private-member-variables-in-classes lint errors --- .clang-tidy | 1 - src/virtio-device.h | 8 ++++++-- src/virtio-p9fs.cpp | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 38ab2abb8..79376d7d8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,7 +8,6 @@ Checks: >- -clang-analyzer-optin.cplusplus.VirtualCall, cppcoreguidelines*, -cppcoreguidelines-avoid-magic-numbers, - -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, diff --git a/src/virtio-device.h b/src/virtio-device.h index 9bf0f2cc2..a3e285f17 100644 --- a/src/virtio-device.h +++ b/src/virtio-device.h @@ -245,7 +245,6 @@ struct virtq { /// \brief VirtIO device common interface class virtio_device { -protected: uint32_t virtio_idx = 0; ///< VirtIO device index uint32_t int_status = 0; ///< Interrupt status mask (see virtio_status) uint32_t device_id = 0; ///< Device id (see virtio_devices) @@ -258,12 +257,17 @@ class virtio_device { uint32_t device_status = 0; ///< Device status mask (see virtio_status) uint32_t config_generation = 0; ///< Configuration generation counter uint32_t config_space_size = 0; ///< Configuration size - bool driver_ok = false; ///< True when the device was successfully initialized by the driver + +protected: + // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes) + bool driver_ok = false; ///< True when the device was successfully initialized by the driver // Use an array of uint32 instead of uint8, to make sure we can perform 4-byte aligned reads on config space std::array config_space{}; ///< Configuration space std::array queue{}; ///< Virtqueues + // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes) + public: explicit virtio_device(uint32_t virtio_idx, uint32_t device_id, uint64_t device_features, uint32_t config_space_size); diff --git a/src/virtio-p9fs.cpp b/src/virtio-p9fs.cpp index 22ce41c5c..070f6c9c1 100644 --- a/src/virtio-p9fs.cpp +++ b/src/virtio-p9fs.cpp @@ -511,7 +511,7 @@ static bool is_name_legal(const std::string &name) { virtio_p9fs_device::virtio_p9fs_device(uint32_t virtio_idx, const std::string &mount_tag, const std::string &root_path) : - virtio_device(virtio_idx, VIRTIO_DEVICE_9P, VIRTIO_9P_F_MOUNT_TAG, VIRTIO_MAX_CONFIG_SPACE_SIZE), + virtio_device(virtio_idx, VIRTIO_DEVICE_9P, VIRTIO_9P_F_MOUNT_TAG, mount_tag.length() + sizeof(uint16_t)), m_msize(P9_MAX_MSIZE), m_root_path(root_path) { if (root_path.length() + 1 >= P9_ROOT_PATH_MAX) { @@ -528,7 +528,6 @@ virtio_p9fs_device::virtio_p9fs_device(uint32_t virtio_idx, const std::string &m virtio_p9fs_config_space *config = get_config(); strncpy(config->mount_tag.data(), mount_tag.c_str(), mount_tag.length()); config->mount_tag_len = mount_tag.length(); - config_space_size = mount_tag.length() + sizeof(uint16_t); } virtio_p9fs_device::~virtio_p9fs_device() {