From 27737f616e1e53c0a6247091731760a95bd00498 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 14 May 2026 22:56:29 -0700 Subject: [PATCH] [tlv] remove unused `Tlv::FindTlv()` method variations (#13105) This commit removes the legacy `Tlv::FindTlv()` method variations that read a TLV into a local buffer. These methods are no longer used across the codebase, having been replaced by safer and more efficient alternatives such as `Tlv::Find()`, `Tlv::FindTlvValueOffsetRange()`, or `Tlv::Info::FindIn()`. The removed methods were prone to misuse, as they did not always handle Extended TLVs correctly if the caller provided a fixed-size buffer. Removing these variations forces new code to use the modern helper functions, which provide better validation and correctly handle the decoupling of the TLV header from its value. --- src/core/common/tlvs.cpp | 22 ------------- src/core/common/tlvs.hpp | 68 ---------------------------------------- 2 files changed, 90 deletions(-) diff --git a/src/core/common/tlvs.cpp b/src/core/common/tlvs.cpp index 22a4269bd..9e9db1b98 100644 --- a/src/core/common/tlvs.cpp +++ b/src/core/common/tlvs.cpp @@ -57,28 +57,6 @@ const uint8_t *Tlv::GetValue(void) const Error Tlv::AppendTo(Message &aMessage) const { return aMessage.AppendBytes(this, static_cast(GetSize())); } -Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv) -{ - uint16_t offset; - - return FindTlv(aMessage, aType, aMaxSize, aTlv, offset); -} - -Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv, uint16_t &aOffset) -{ - Error error; - Info info; - - SuccessOrExit(error = info.FindIn(aMessage, aType)); - - info.mTlvOffsetRange.ShrinkLength(aMaxSize); - aMessage.ReadBytes(info.mTlvOffsetRange, &aTlv); - aOffset = info.GetTlvOffset(); - -exit: - return error; -} - Error Tlv::FindTlvValueOffsetRange(const Message &aMessage, uint8_t aType, OffsetRange &aOffsetRange) { Error error; diff --git a/src/core/common/tlvs.hpp b/src/core/common/tlvs.hpp index 0e42d10df..12a46835a 100644 --- a/src/core/common/tlvs.hpp +++ b/src/core/common/tlvs.hpp @@ -439,74 +439,6 @@ public: OffsetRange mValueOffsetRange; }; - /** - * Searches for and reads a requested TLV out of a given message. - * - * Can be used independent of whether the read TLV (from message) is an Extended TLV or not. - * - * @param[in] aMessage A reference to the message. - * @param[in] aType The Type value to search for. - * @param[in] aMaxSize Maximum number of bytes to read. - * @param[out] aTlv A reference to the TLV that will be copied to. - * - * @retval kErrorNone Successfully copied the TLV. - * @retval kErrorNotFound Could not find the TLV with Type @p aType. - */ - static Error FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv); - - /** - * Searches for and reads a requested TLV out of a given message. - * - * Can be used independent of whether the read TLV (from message) is an Extended TLV or not. - * - * @param[in] aMessage A reference to the message. - * @param[in] aType The Type value to search for. - * @param[in] aMaxSize Maximum number of bytes to read. - * @param[out] aTlv A reference to the TLV that will be copied to. - * @param[out] aOffset A reference to return the offset to start of the TLV in @p aMessage. - * - * @retval kErrorNone Successfully copied the TLV. - * @retval kErrorNotFound Could not find the TLV with Type @p aType. - */ - static Error FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv, uint16_t &aOffset); - - /** - * Searches for and reads a requested TLV out of a given message. - * - * Can be used independent of whether the read TLV (from message) is an Extended TLV or not. - * - * @tparam TlvType The TlvType to search for (must be a sub-class of `Tlv`). - * - * @param[in] aMessage A reference to the message. - * @param[out] aTlv A reference to the TLV that will be copied to. - * - * @retval kErrorNone Successfully copied the TLV. - * @retval kErrorNotFound Could not find the TLV with Type @p aType. - */ - template static Error FindTlv(const Message &aMessage, TlvType &aTlv) - { - return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv); - } - - /** - * Searches for and reads a requested TLV out of a given message. - * - * Can be used independent of whether the read TLV (from message) is an Extended TLV or not. - * - * @tparam TlvType The TlvType to search for (must be a sub-class of `Tlv`). - * - * @param[in] aMessage A reference to the message. - * @param[out] aTlv A reference to the TLV that will be copied to. - * @param[out] aOffset A reference to return the offset to start of the TLV in @p aMessage. - * - * @retval kErrorNone Successfully copied the TLV. - * @retval kErrorNotFound Could not find the TLV with Type @p aType. - */ - template static Error FindTlv(const Message &aMessage, TlvType &aTlv, uint16_t &aOffset) - { - return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv, aOffset); - } - /** * Finds the offset range of the TLV value for a given TLV type within @p aMessage. *