[mac] remove redundant checks (#3408)

This commit is contained in:
Zhanglong Xia
2019-01-03 09:16:04 -08:00
committed by Jonathan Hui
parent 2a9f8797f7
commit 0e42d0b8c9
2 changed files with 19 additions and 5 deletions
+19 -3
View File
@@ -36,6 +36,7 @@
#include "openthread-core-config.h"
#include <limits.h>
#include <openthread/platform/radio.h>
#include "common/string.hpp"
@@ -140,7 +141,10 @@ public:
* @returns TRUE if the channel @p aChannel is included in the mask, FALSE otherwise.
*
*/
bool ContainsChannel(uint8_t aChannel) const { return ((1UL << aChannel) & mMask) != 0; }
bool ContainsChannel(uint8_t aChannel) const
{
return (aChannel < sizeof(mMask) * CHAR_BIT) ? ((1UL << aChannel) & mMask) != 0 : false;
}
/**
* This method adds a channel to the channel mask.
@@ -148,7 +152,13 @@ public:
* @param[in] aChannel A channel
*
*/
void AddChannel(uint8_t aChannel) { mMask |= (1UL << aChannel); }
void AddChannel(uint8_t aChannel)
{
if (aChannel < sizeof(mMask) * CHAR_BIT)
{
mMask |= (1UL << aChannel);
}
}
/**
* This method removes a channel from the channel mask.
@@ -156,7 +166,13 @@ public:
* @param[in] aChannel A channel
*
*/
void RemoveChannel(uint8_t aChannel) { mMask &= ~(1UL << aChannel); }
void RemoveChannel(uint8_t aChannel)
{
if (aChannel < sizeof(mMask) * CHAR_BIT)
{
mMask &= ~(1UL << aChannel);
}
}
/**
* This method updates the channel mask by intersecting it with another mask.
-2
View File
@@ -355,7 +355,6 @@ otError Mac::SetPanChannel(uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(OT_RADIO_CHANNEL_MIN <= aChannel && aChannel <= OT_RADIO_CHANNEL_MAX, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mPanChannel != aChannel, GetNotifier().SignalIfFirst(OT_CHANGED_THREAD_CHANNEL));
@@ -379,7 +378,6 @@ otError Mac::SetRadioChannel(uint16_t aAcquisitionId, uint8_t aChannel)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(OT_RADIO_CHANNEL_MIN <= aChannel && aChannel <= OT_RADIO_CHANNEL_MAX, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mSupportedChannelMask.ContainsChannel(aChannel), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mRadioChannelAcquisitionId && aAcquisitionId == mRadioChannelAcquisitionId,