Commit 60db8d10 authored by Jérémy Lefaure's avatar Jérémy Lefaure Committed by Greg Kroah-Hartman
Browse files

staging: rtl8723bs: use ARRAY_SIZE



Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is not always useful to use a variable to store this constant
calculated at compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: default avatarJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2595587d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <drv_types.h>
#include <rtw_debug.h>
#include <rtw_wifi_regd.h>
#include <linux/kernel.h>


static struct mlme_handler mlme_sta_tbl[] = {
@@ -559,7 +560,7 @@ void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame)

	index = GetFrameSubType(pframe) >> 4;

	if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) {
	if (index >= ARRAY_SIZE(mlme_sta_tbl)) {
		RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type =%d\n", index));
		return;
	}
@@ -2224,7 +2225,7 @@ unsigned int OnAction(struct adapter *padapter, union recv_frame *precv_frame)

	category = frame_body[0];

	for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
	for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) {
		ptable = &OnAction_tbl[i];

		if (category == ptable->num)
+3 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#define _RTW_RF_C_

#include <drv_types.h>
#include <linux/kernel.h>


struct ch_freq {
@@ -44,20 +45,18 @@ static struct ch_freq ch_freq_map[] = {
	{216, 5080},/* Japan, means J16 */
};

static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq));

u32 rtw_ch2freq(u32 channel)
{
	u8 i;
	u32 freq = 0;

	for (i = 0; i < ch_freq_map_num; i++) {
	for (i = 0; i < ARRAY_SIZE(ch_freq_map); i++) {
		if (channel == ch_freq_map[i].channel) {
			freq = ch_freq_map[i].frequency;
				break;
		}
	}
	if (i == ch_freq_map_num)
	if (i == ARRAY_SIZE(ch_freq_map))
		freq = 2412;

	return freq;
+4 −5
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
*
******************************************************************************/


#include <linux/kernel.h>
#include "odm_precomp.h"

static bool CheckPositive(
@@ -268,7 +268,7 @@ static u32 Array_MP_8723B_AGC_TAB[] = {
void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_AGC_TAB)/sizeof(u32);
	u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB);
	u32 *Array = Array_MP_8723B_AGC_TAB;

	ODM_RT_TRACE(
@@ -537,7 +537,7 @@ static u32 Array_MP_8723B_PHY_REG[] = {
void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG)/sizeof(u32);
	u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG);
	u32 *Array = Array_MP_8723B_PHY_REG;

	ODM_RT_TRACE(
@@ -617,7 +617,6 @@ static u32 Array_MP_8723B_PHY_REG_PG[] = {
void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG_PG)/sizeof(u32);
	u32 *Array = Array_MP_8723B_PHY_REG_PG;

	ODM_RT_TRACE(
@@ -630,7 +629,7 @@ void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm)
	pDM_Odm->PhyRegPgVersion = 1;
	pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE;

	for (i = 0; i < ArrayLen; i += 6) {
	for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 6) {
		u32 v1 = Array[i];
		u32 v2 = Array[i+1];
		u32 v3 = Array[i+2];
+2 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
*
******************************************************************************/


#include <linux/kernel.h>
#include "odm_precomp.h"

static bool CheckPositive(
@@ -239,7 +239,7 @@ static u32 Array_MP_8723B_MAC_REG[] = {
void ODM_ReadAndConfig_MP_8723B_MAC_REG(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_MAC_REG)/sizeof(u32);
	u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_MAC_REG);
	u32 *Array = Array_MP_8723B_MAC_REG;

	ODM_RT_TRACE(
+3 −4
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
*
******************************************************************************/


#include <linux/kernel.h>
#include "odm_precomp.h"

static bool CheckPositive(
@@ -270,7 +270,7 @@ static u32 Array_MP_8723B_RadioA[] = {
void ODM_ReadAndConfig_MP_8723B_RadioA(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_RadioA)/sizeof(u32);
	u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_RadioA);
	u32 *Array = Array_MP_8723B_RadioA;

	ODM_RT_TRACE(
@@ -766,7 +766,6 @@ static u8 *Array_MP_8723B_TXPWR_LMT[] = {
void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(PDM_ODM_T pDM_Odm)
{
	u32 i = 0;
	u32 ArrayLen = sizeof(Array_MP_8723B_TXPWR_LMT)/sizeof(u8 *);
	u8 **Array = Array_MP_8723B_TXPWR_LMT;

	ODM_RT_TRACE(
@@ -776,7 +775,7 @@ void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(PDM_ODM_T pDM_Odm)
		("===> ODM_ReadAndConfig_MP_8723B_TXPWR_LMT\n")
	);

	for (i = 0; i < ArrayLen; i += 7) {
	for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_TXPWR_LMT); i += 7) {
		u8 *regulation = Array[i];
		u8 *band = Array[i+1];
		u8 *bandwidth = Array[i+2];
Loading