Skip to contentSkip to conversation

use ARRAY_SIZE macro

PATCH Applied Nikitas Angelinas 5 participants 14 messages Sep 8, 2010 – Sep 10, 2010

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover use ARRAY_SIZE macro

This patch series replaces occurrences of the type sizeof(buffer) / sizeof(buffer[0]) with ARRAY_SIZE(buffer) in different places throughout the source tree.

#1 lore raw

PATCH 1/8 arch/ia64/xen: use ARRAY_SIZE macro in xen_pv_ops.c

Replace sizeof(xen_branch_target) / sizeof(xen_branch_target[0]) with ARRAY_SIZE(xen_branch_target) in arch/ia64/xen/xen_pv_ops.c

---
 arch/ia64/xen/xen_pv_ops.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
arch/ia64/xen/xen_pv_ops.c +2 -3
index 8adc6a1..3e8d350 100644
@@ -1136,7 +1136,6 @@ __initconst = {
 static void __init
 xen_patch_branch(unsigned long tag, unsigned long type)
 {
-	const unsigned long nelem =
-		sizeof(xen_branch_target) / sizeof(xen_branch_target[0]);
-	__paravirt_patch_apply_branch(tag, type, xen_branch_target, nelem);
+	__paravirt_patch_apply_branch(tag, type, xen_branch_target,
+					ARRAY_SIZE(xen_branch_target));
 }
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/8 arch/parisc/include/asm: use ARRAY_SIZE macro in mmzone.h

In reply to Nikitas Angelinas

Replace sizeof(pfnnid_map) / sizeof(pfnnid_map[0]) with ARRAY_SIZE(pfnnid_map) in mmzone.h

---
 arch/parisc/include/asm/mmzone.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
arch/parisc/include/asm/mmzone.h +3 -1
index 9608d2c..85b23b6 100644
@@ -3,6 +3,8 @@
 
 #ifdef CONFIG_DISCONTIGMEM
 
+#include <linux/kernel.h>
+
 #define MAX_PHYSMEM_RANGES 8 /* Fix the size for now (current known max is 3) */
 extern int npmem_ranges;
 
@@ -51,7 +53,7 @@ static inline int pfn_to_nid(unsigned long pfn)
 		return 0;
 
 	i = pfn >> PFNNID_SHIFT;
-	BUG_ON(i >= sizeof(pfnnid_map) / sizeof(pfnnid_map[0]));
+	BUG_ON(i >= ARRAY_SIZE(pfnnid_map));
 	r = pfnnid_map[i];
 	BUG_ON(r == 0xff);
 
Signature · 1 line
1.7.2.3
#4 lore raw

PATCH 3/8 drivers/gpu/drm: use ARRAY_SIZE macro in drm_edid_modes.h

In reply to Nikitas Angelinas

Replace sizeof(est3_modes) / sizeof(est3_modes[0]) with ARRAY_SIZE(est3_modes) in drivers/gpu/drm/drm_edid_modes.h

---
 drivers/gpu/drm/drm_edid_modes.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_edid_modes.h +1 -1
index 6eb7592..7601284 100644
@@ -377,4 +377,4 @@ static const struct {
 	{ 1920, 1440, 60, 0 },
 	{ 1920, 1440, 75, 0 },
 };
-static const int num_est3_modes = sizeof(est3_modes) / sizeof(est3_modes[0]);
+static const int num_est3_modes = ARRAY_SIZE(est3_modes);
Signature · 1 line
1.7.2.3
#5 lore raw

PATCH 4/8 drivers/gpu/drm/i915: use ARRAY_SIZE macro in intel_tv.c

In reply to Nikitas Angelinas

Replace sizeof(tv_modes) / sizeof (tv_modes[0]) with ARRAY_SIZE(tv_modes) in drivers/gpu/drm/i915/intel_tv.c

---
 drivers/gpu/drm/i915/intel_tv.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/gpu/drm/i915/intel_tv.c +2 -1
index d2029ef..6dc19f6 100644
@@ -30,6 +30,7 @@
  * Integrated TV-out support for the 915GM and 945GM.
  */
 
+#include <linux/kernel.h>
 #include "drmP.h"
 #include "drm.h"
 #include "drm_crtc.h"
@@ -926,7 +927,7 @@ intel_tv_mode_lookup (char *tv_format)
 {
 	int i;
 
-	for (i = 0; i < sizeof(tv_modes) / sizeof (tv_modes[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
 		const struct tv_mode *tv_mode = &tv_modes[i];
 
 		if (!strcmp(tv_format, tv_mode->name))
Signature · 1 line
1.7.2.3
#3 lore raw

Re: [PATCH 2/8] arch/parisc/include/asm: use ARRAY_SIZE macro in mmzone.h

In reply to Nikitas Angelinas
Quoted 3 lines · Nikitas Angelinas

Replace sizeof(pfnnid_map) / sizeof(pfnnid_map[0]) with ARRAY_SIZE(pfnnid_map) in mmzone.h

Thanks. Let me think about this, I don't really like the tangled web of include dependencies this results in...

regards, Kyle

Quoted 31 lines
---
 arch/parisc/include/asm/mmzone.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
arch/parisc/include/asm/mmzone.h +3 -1
index 9608d2c..85b23b6 100644
@@ -3,6 +3,8 @@
 
 #ifdef CONFIG_DISCONTIGMEM
 
+#include <linux/kernel.h>
+
 #define MAX_PHYSMEM_RANGES 8 /* Fix the size for now (current known max is 3) */
 extern int npmem_ranges;
 
@@ -51,7 +53,7 @@ static inline int pfn_to_nid(unsigned long pfn)
 		return 0;
 
 	i = pfn >> PFNNID_SHIFT;
-	BUG_ON(i >= sizeof(pfnnid_map) / sizeof(pfnnid_map[0]));
+	BUG_ON(i >= ARRAY_SIZE(pfnnid_map));
 	r = pfnnid_map[i];
 	BUG_ON(r == 0xff);
 
Signature · 1 line
1.7.2.3
#6 lore raw

PATCH 5/8 drivers/net/bnx2x: use ARRAY_SIZE macro in bnx2x_main.c

In reply to Nikitas Angelinas

Replace sizeof(bnx2x_parity_mask)/(sizeof(bnx2x_parity_mask[0]) with ARRAY_SIZE(bnx2x_parity_mask) in drivers/net/bnx2x/bnx2x_main.c

---
 drivers/net/bnx2x/bnx2x_main.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/bnx2x/bnx2x_main.c +2 -3
index f8c3f08..e534ae8 100644
@@ -3803,10 +3803,9 @@ static const struct {
 
 static void enable_blocks_parity(struct bnx2x *bp)
 {
-	int i, mask_arr_len =
-		sizeof(bnx2x_parity_mask)/(sizeof(bnx2x_parity_mask[0]));
+	int i;
 
-	for (i = 0; i < mask_arr_len; i++)
+	for (i = 0; i < ARRAY_SIZE(bnx2x_parity_mask); i++)
 		REG_WR(bp, bnx2x_parity_mask[i].addr,
 			bnx2x_parity_mask[i].mask);
 }
Signature · 1 line
1.7.2.3
#8 lore raw

PATCH 6/8 drivers/net/wireless/ath/ath9k: use ARRAY_SIZE macro in ani.c

In reply to Nikitas Angelinas

Replace (sizeof(ofdm_level_table)/sizeof(ofdm_level_table[0]) with ARRAY_SIZE(ofdm_level_table), and (sizeof(cck_level_table)/ sizeof(cck_level_table[0]) with ARRAY_SIZE(cck_level_table) in drivers/net/wireless/ath/ath9k/ani.c

---
 drivers/net/wireless/ath/ath9k/ani.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath9k/ani.c +3 -2
index cc648b6..0496f96 100644
@@ -14,6 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <linux/kernel.h>
 #include "hw.h"
 #include "hw-ops.h"
 
@@ -48,7 +49,7 @@ static const struct ani_ofdm_level_entry ofdm_level_table[] = {
 	{  7,  8,  0  }  /* lvl 9 */
 };
 #define ATH9K_ANI_OFDM_NUM_LEVEL \
-	(sizeof(ofdm_level_table)/sizeof(ofdm_level_table[0]))
+	ARRAY_SIZE(ofdm_level_table)
 #define ATH9K_ANI_OFDM_MAX_LEVEL \
 	(ATH9K_ANI_OFDM_NUM_LEVEL-1)
 #define ATH9K_ANI_OFDM_DEF_LEVEL \
@@ -94,7 +95,7 @@ static const struct ani_cck_level_entry cck_level_table[] = {
 };
 
 #define ATH9K_ANI_CCK_NUM_LEVEL \
-	(sizeof(cck_level_table)/sizeof(cck_level_table[0]))
+	ARRAY_SIZE(cck_level_table)
 #define ATH9K_ANI_CCK_MAX_LEVEL \
 	(ATH9K_ANI_CCK_NUM_LEVEL-1)
 #define ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI \
Signature · 1 line
1.7.2.3
#10 lore raw

PATCH 7/8 drivers/staging/vt6656: use ARRAY_SIZE macro in channel.c

In reply to Nikitas Angelinas

Replace (sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0])) with ARRAY_SIZE(ChannelRuleTab) in drivers/staging/vt6656/channel.c

---
 drivers/staging/vt6656/channel.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/vt6656/channel.c +2 -1
index 6ad03e4..a2460ae 100644
@@ -34,6 +34,7 @@
  *
  */
 
+#include <linux/kernel.h>
 #include "country.h"
 #include "channel.h"
 #include "rf.h"
@@ -367,7 +368,7 @@ static  struct
 /*                                           1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
 };
 
-#define NUM_RULES	(sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0]))
+#define NUM_RULES	ARRAY_SIZE(ChannelRuleTab)
 
 /*---------------------  Export function  -------------------------*/
 /************************************************************************
Signature · 1 line
1.7.2.3
#13 lore raw

PATCH 8/8 net/wireless: use ARRAY_SIZE macro in radiotap.c

In reply to Nikitas Angelinas

Replace sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]) with ARRAY_SIZE(rtap_namespace_sizes) in net/wireless/radiotap.c

---
 net/wireless/radiotap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/wireless/radiotap.c +2 -1
index 1332c44..c774bc0 100644
@@ -14,6 +14,7 @@
  * See COPYING for more details.
  */
 
+#include <linux/kernel.h>
 #include <net/cfg80211.h>
 #include <net/ieee80211_radiotap.h>
 #include <asm/unaligned.h>
@@ -45,7 +46,7 @@ static const struct radiotap_align_size rtap_namespace_sizes[] = {
 };
 
 static const struct ieee80211_radiotap_namespace radiotap_ns = {
-	.n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]),
+	.n_bits = ARRAY_SIZE(rtap_namespace_sizes),
 	.align_size = rtap_namespace_sizes,
 };
 
Signature · 1 line
1.7.2.3
#9 lore raw

Re: [PATCH 6/8] drivers/net/wireless/ath/ath9k: use ARRAY_SIZE macro in ani.c

In reply to Nikitas Angelinas
Quoted 6 lines · Nikitas Angelinas

Replace (sizeof(ofdm_level_table)/sizeof(ofdm_level_table[0]) with ARRAY_SIZE(ofdm_level_table), and (sizeof(cck_level_table)/ sizeof(cck_level_table[0]) with ARRAY_SIZE(cck_level_table) in drivers/net/wireless/ath/ath9k/ani.c

Sure.

Luis

#11 lore raw

Re: [PATCH 7/8] drivers/staging/vt6656: use ARRAY_SIZE macro in channel.c

In reply to Nikitas Angelinas

I think this definition is not used anywhere in the driver and thus can be removed.

Quoted 36 lines · Nikitas Angelinas

Replace (sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0])) with ARRAY_SIZE(ChannelRuleTab) in drivers/staging/vt6656/channel.c

---
 drivers/staging/vt6656/channel.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/vt6656/channel.c +2 -1
index 6ad03e4..a2460ae 100644
@@ -34,6 +34,7 @@
  *
  */
 
+#include <linux/kernel.h>
 #include "country.h"
 #include "channel.h"
 #include "rf.h"
@@ -367,7 +368,7 @@ static  struct
 /*                                           1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
 };
 
-#define NUM_RULES	(sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0]))
+#define NUM_RULES	ARRAY_SIZE(ChannelRuleTab)
 
 /*---------------------  Export function  -------------------------*/
 /************************************************************************
Signature · 6 lines
1.7.2.3

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel
Signature · 1 line
Charles Clément
#12 lore raw

Re: [PATCH 7/8] drivers/staging/vt6656: use ARRAY_SIZE macro in channel.c

Quoted 36 lines · Charles Clément

I think this definition is not used anywhere in the driver and thus can be removed.

Quoted 32 lines · Nikitas Angelinas

Replace (sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0])) with ARRAY_SIZE(ChannelRuleTab) in drivers/staging/vt6656/channel.c

---
 drivers/staging/vt6656/channel.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/vt6656/channel.c +2 -1
index 6ad03e4..a2460ae 100644
@@ -34,6 +34,7 @@
  *
  */
 
+#include <linux/kernel.h>
 #include "country.h"
 #include "channel.h"
 #include "rf.h"
@@ -367,7 +368,7 @@ static  struct
 /*                                           1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
 };
 
-#define NUM_RULES	(sizeof(ChannelRuleTab) / sizeof(ChannelRuleTab[0]))
+#define NUM_RULES	ARRAY_SIZE(ChannelRuleTab)
 
 /*---------------------  Export function  -------------------------*/
 /************************************************************************
Signature · 1 line
1.7.2.3
Quoted 7 lines
Quoted 4 lines

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Signature · 1 line
Charles Clément

Yup, doesn't seem to be used anywhere; the file also has some coding style issues, so perhaps removing the macro can be part of a cleanup patch for whoever may carry out that task.

In that case, I guess reverting the patch from staging-next might be an option, but I think what's really needed is for someone to go through the driver source and do what's necessary... At first glance, it seems possible that the macro (NUM_RULES) may indeed have to be used as a replacement for the hard-coded CB_MAX_CHANNEL, but the author may not have gotten around to it or didn't make use of it for some other reason.