All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers
@ 2007-02-05 16:54 Ahmed S. Darwish
  2007-02-05 16:55 ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
                   ` (7 more replies)
  0 siblings, 8 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:54 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi all,

Follows is a sereis of patches to use ARRAY_SIZE macro in drivers/net. 
Patches are sent separately according to their maintaners as replies to 
this thread.

 apne.c                     |    2 +-
 arm/am79c961a.c            |    2 +-
 atarilance.c               |    2 +-
 cs89x0.c                   |    6 +++---
 e1000/e1000_ethtool.c      |    2 +-
 fec_8xx/fec_mii.c          |    4 ++--
 ibm_emac/ibm_emac_debug.c  |    8 ++++----
 irda/actisys-sir.c         |    3 ++-
 ixgb/ixgb_param.c          |    2 +-
 lp486e.c                   |    2 +-
 ne-h8300.c                 |    2 +-
 ne.c                       |    2 +-
 ne2.c                      |    2 +-
 ne2k-pci.c                 |    2 +-
 netxen/netxen_nic_hw.c     |    2 +-
 pcmcia/axnet_cs.c          |    2 +-
 pcmcia/pcnet_cs.c          |    2 +-
 sk98lin/skgemib.c          |    4 +++-
 sk98lin/skgesirq.c         |    3 ++-
 skfp/smt.c                 |    3 ++-
 skfp/srf.c                 |    6 ++++--
 wireless/airo.c            |    4 ++--
 wireless/hostap/hostap.h   |    3 ++-
 wireless/ipw2100.c         |   14 ++++++--------
 wireless/prism54/oid_mgt.c |    4 +++-
 wireless/wavelan.p.h       |    2 +-
 zorro8390.c                |    2 +-
 27 files changed, 50 insertions(+), 42 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
@ 2007-02-05 16:55 ` Ahmed S. Darwish
  2007-02-06 17:16   ` Auke Kok
  2007-02-05 16:56 ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:55 UTC (permalink / raw)
  To: cramerj, john.ronciak; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index fb96c87..d21706e 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -746,7 +746,7 @@ err_setup:
 	uint32_t pat, value;                                                   \
 	uint32_t test[] =                                                      \
 		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};              \
-	for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
+	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {              \
 		E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
 		value = E1000_READ_REG(&adapter->hw, R);                       \
 		if (value != (test[pat] & W & M)) {                             \

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] ipw2100: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
  2007-02-05 16:55 ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-05 16:56 ` Ahmed S. Darwish
  2007-02-05 16:56 ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:56 UTC (permalink / raw)
  To: yi.zhu, linville; +Cc: linux-kernel, netdev

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b85857a..a9d944a 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -2888,7 +2888,7 @@ static int __ipw2100_tx_process(struct ipw2100_priv *priv)
 
 #ifdef CONFIG_IPW2100_DEBUG
 		if (packet->info.c_struct.cmd->host_command_reg <
-		    sizeof(command_types) / sizeof(*command_types))
+		    ARRAY_SIZE(command_types))
 			IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
 				     command_types[packet->info.c_struct.cmd->
 						   host_command_reg],
@@ -3736,7 +3736,7 @@ static ssize_t show_registers(struct device *d, struct device_attribute *attr,
 
 	out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
 
-	for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
+	for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
 		read_register(dev, hw_data[i].addr, &val);
 		out += sprintf(out, "%30s [%08X] : %08X\n",
 			       hw_data[i].name, hw_data[i].addr, val);
@@ -3757,7 +3757,7 @@ static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
 
 	out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
 
-	for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
+	for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
 		u8 tmp8;
 		u16 tmp16;
 		u32 tmp32;
@@ -3894,13 +3894,11 @@ static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
 	if (priv->status & STATUS_RF_KILL_MASK)
 		return 0;
 
-	if (loop >= sizeof(ord_data) / sizeof(*ord_data))
+	if (loop >= ARRAY_SIZE(ord_data))
 		loop = 0;
 
 	/* sysfs provides us PAGE_SIZE buffer */
-	while (len < PAGE_SIZE - 128 &&
-	       loop < (sizeof(ord_data) / sizeof(*ord_data))) {
-
+	while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
 		val_len = sizeof(u32);
 
 		if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
@@ -6589,7 +6587,7 @@ static const long ipw2100_rates_11b[] = {
 	11000000
 };
 
-#define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
+#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
 
 static int ipw2100_wx_get_name(struct net_device *dev,
 			       struct iw_request_info *info,


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 01/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
  2007-02-05 16:55 ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  2007-02-05 16:56 ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
@ 2007-02-05 16:56 ` Ahmed S. Darwish
  2007-02-05 16:57   ` [PATCH 02/02] " Ahmed S. Darwish
  2007-02-05 16:58 ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:56 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
[PATCH 01/02] is compile tested.
[PATCH 02/02] isn't compile tested cause of missing hardware.

diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 4612f71..d48196c 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -806,7 +806,7 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
 		        i = cs8900_irq_map[0];
 #else
 			/* Translate the IRQ using the IRQ mapping table. */
-			if (i >= sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+			if (i >= ARRAY_SIZE(cs8900_irq_map))
 				printk("\ncs89x0: invalid ISA interrupt number %d\n", i);
 			else
 				i = cs8900_irq_map[i];
@@ -1248,11 +1248,11 @@ write_irq(struct net_device *dev, int chip_type, int irq)
 
 	if (chip_type == CS8900) {
 		/* Search the mapping table for the corresponding IRQ pin. */
-		for (i = 0; i != sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]); i++)
+		for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++)
 			if (cs8900_irq_map[i] == irq)
 				break;
 		/* Not found */
-		if (i == sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+		if (i == ARRAY_SIZE(cs8900_irq_map))
 			i = 3;
 		writereg(dev, PP_CS8900_ISAINT, i);
 	} else {
diff --git a/drivers/net/irda/actisys-sir.c b/drivers/net/irda/actisys-sir.c
index 9715ab5..84d7bb0 100644
--- a/drivers/net/irda/actisys-sir.c
+++ b/drivers/net/irda/actisys-sir.c
@@ -43,6 +43,7 @@
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 
 #include <net/irda/irda.h>
 
@@ -67,7 +68,7 @@ static int actisys_reset(struct sir_dev *);
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
+#define MAX_SPEEDS ARRAY_SIZE(baud_rates)
 
 static struct dongle_driver act220l = {
 	.owner		= THIS_MODULE,
diff --git a/drivers/net/lp486e.c b/drivers/net/lp486e.c
index 177c502..4b016aa 100644
--- a/drivers/net/lp486e.c
+++ b/drivers/net/lp486e.c
@@ -515,7 +515,7 @@ CLEAR_INT(void) {
 	outb(0, IOADDR+8);
 }
 
-#define SIZE(x)	(sizeof(x)/sizeof((x)[0]))
+#define SIZE(x)	ARRAY_SIZE(x)
 
 #if 0
 /* selftest or dump */
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index a5c4199..7081d08 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -379,7 +379,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/ne2.c b/drivers/net/ne2.c
index 089b5bb..c6c2a91 100644
--- a/drivers/net/ne2.c
+++ b/drivers/net/ne2.c
@@ -432,7 +432,7 @@ static int __init ne2_probe1(struct net_device *dev, int slot)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, base_addr +
 				program_seq[i].offset);
 
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index 589785d..6bafdda 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -309,7 +309,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
 			{0x00,	EN0_RSARHI},
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index f263232..7f93c08 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -395,7 +395,7 @@ int netxen_is_flash_supported(struct netxen_adapter *adapter)
 	/* if the flash size less than 4Mb, make huge war cry and die */
 	for (j = 1; j < 4; j++) {
 		addr = j * NETXEN_NIC_WINDOW_MARGIN;
-		for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
+		for (i = 0; i < ARRAY_SIZE(locs); i++) {
 			if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
 			    && netxen_rom_fast_read(adapter, (addr + locs[i]),
 						    &val02) == 0) {
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 6139048..6b64ea4 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -232,7 +232,7 @@ static int get_prom(struct pcmcia_device *link)
     axnet_reset_8390(dev);
     mdelay(10);
 
-    for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 	outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
     for (i = 0; i < 6; i += 2) {
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index d88e9b2..e652246 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -375,7 +375,7 @@ static hw_info_t *get_prom(struct pcmcia_device *link)
     pcnet_reset_8390(dev);
     mdelay(10);
 
-    for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 	outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
     for (i = 0; i < 32; i++)
diff --git a/drivers/net/sk98lin/skgemib.c b/drivers/net/sk98lin/skgemib.c
index 0a6f67a..625cb25 100644
--- a/drivers/net/sk98lin/skgemib.c
+++ b/drivers/net/sk98lin/skgemib.c
@@ -22,6 +22,8 @@
  *
  ******************************************************************************/
 
+#include <linux/kernel.h>
+
 /*
  * PRIVATE OID handler function prototypes
  */
@@ -82,7 +84,7 @@ PNMI_STATIC int DiagActions(SK_AC *pAC, SK_IOC IoC, int action, SK_U32 Id,
 
 
 /* defines *******************************************************************/
-#define ID_TABLE_SIZE (sizeof(IdTable)/sizeof(IdTable[0]))
+#define ID_TABLE_SIZE ARRAY_SIZE(IdTable)
 
 
 /* global variables **********************************************************/
diff --git a/drivers/net/sk98lin/skgesirq.c b/drivers/net/sk98lin/skgesirq.c
index 3e7aa49..83e1544 100644
--- a/drivers/net/sk98lin/skgesirq.c
+++ b/drivers/net/sk98lin/skgesirq.c
@@ -51,6 +51,7 @@ static const char SysKonnectFileId[] =
 	"@(#) $Id: skgesirq.c,v 1.92 2003/09/16 14:37:07 rschmidt Exp $ (C) Marvell.";
 #endif
 
+#include <linux/kernel.h>
 #include "h/skdrv1st.h"		/* Driver Specific Definitions */
 #ifndef SK_SLIM
 #include "h/skgepnmi.h"		/* PNMI Definitions */
@@ -892,7 +893,7 @@ int		Port)		/* Which port should be checked */
 	 */
 	RxCts = 0;
 
-	for (i = 0; i < sizeof(SkGeRxRegs)/sizeof(SkGeRxRegs[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(SkGeRxRegs); i++) {
 		
 		(void)SkXmMacStatistic(pAC, IoC, Port, SkGeRxRegs[i], &RxTmp);
 		
diff --git a/drivers/net/skfp/smt.c b/drivers/net/skfp/smt.c
index 99a776a..6820989 100644
--- a/drivers/net/skfp/smt.c
+++ b/drivers/net/skfp/smt.c
@@ -14,6 +14,7 @@
  *
  ******************************************************************************/
 
+#include <linux/kernel.h>
 #include "h/types.h"
 #include "h/fddi.h"
 #include "h/smc.h"
@@ -1655,7 +1656,7 @@ static const struct smt_pdef {
 	{ SMT_P4053,	0,	SWAP_SMT_P4053			} ,
 } ;
 
-#define N_SMT_PLEN	(sizeof(smt_pdef)/sizeof(smt_pdef[0]))
+#define N_SMT_PLEN	ARRAY_SIZE(smt_pdef)
 
 int smt_check_para(struct s_smc *smc, struct smt_header	*sm,
 		   const u_short list[])
diff --git a/drivers/net/skfp/srf.c b/drivers/net/skfp/srf.c
index 16573ac..0f47297 100644
--- a/drivers/net/skfp/srf.c
+++ b/drivers/net/skfp/srf.c
@@ -19,6 +19,8 @@
 	SRF state machine and frame generation
 */
 
+#include <linux/kernel.h>
+
 #include "h/types.h"
 #include "h/fddi.h"
 #include "h/smc.h"
@@ -43,7 +45,7 @@ static void clear_reported(struct s_smc *smc);
 static void smt_send_srf(struct s_smc *smc);
 static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index);
 
-#define MAX_EVCS	(sizeof(smc->evcs)/sizeof(smc->evcs[0]))
+#define MAX_EVCS	ARRAY_SIZE(smc->evcs)
 
 struct evc_init {
 	u_char code ;
@@ -67,7 +69,7 @@ static const struct evc_init evc_inits[] = {
 	{ SMT_EVENT_PORT_PATH_CHANGE,		INDEX_PORT,NUMPHYS,SMT_P4053 } ,
 } ;
 
-#define MAX_INIT_EVC	(sizeof(evc_inits)/sizeof(evc_inits[0]))
+#define MAX_INIT_EVC	ARRAY_SIZE(evc_inits)
 
 void smt_init_evc(struct s_smc *smc)
 {


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 02/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:56 ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
@ 2007-02-05 16:57   ` Ahmed S. Darwish
  0 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:57 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile-tested due to missing hardware.

diff --git a/drivers/net/apne.c b/drivers/net/apne.c
index 9541911..8806151 100644
--- a/drivers/net/apne.c
+++ b/drivers/net/apne.c
@@ -247,7 +247,7 @@ static int __init apne_probe1(struct net_device *dev, int ioaddr)
 	    {0x00,	NE_EN0_RSARHI},
 	    {E8390_RREAD+E8390_START, NE_CMD},
 	};
-	for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
 	    outb(program_seq[i].value, ioaddr + program_seq[i].offset);
 	}
 
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index ddd12d4..200cbc0 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -414,7 +414,7 @@ static void am79c961_setmulticastlist (struct net_device *dev)
 	/*
 	 * Update the multicast hash table
 	 */
-	for (i = 0; i < sizeof(multi_hash) / sizeof(multi_hash[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(multi_hash); i++)
 		write_rreg(dev->base_addr, i + LADRL, multi_hash[i]);
 
 	/*
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index 7e37ac8..ef18428 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -263,7 +263,7 @@ struct lance_addr {
 									   (highest byte stripped) */
 };
 
-#define	N_LANCE_ADDR	(sizeof(lance_addr_list)/sizeof(*lance_addr_list))
+#define	N_LANCE_ADDR	ARRAY_SIZE(lance_addr_list)
 
 
 /* Definitions for the Lance */
diff --git a/drivers/net/fec_8xx/fec_mii.c b/drivers/net/fec_8xx/fec_mii.c
index d3c16b8..1fc2b43 100644
--- a/drivers/net/fec_8xx/fec_mii.c
+++ b/drivers/net/fec_8xx/fec_mii.c
@@ -310,12 +310,12 @@ int fec_mii_phy_id_detect(struct net_device *dev)
 		return -1;
 	}
 
-	for (i = 0, phy = phy_info; i < sizeof(phy_info) / sizeof(phy_info[0]);
+	for (i = 0, phy = phy_info; i < ARRAY_SIZE(phy_info));
 	     i++, phy++)
 		if (phy->id == (phy_hwid >> 4) || phy->id == 0)
 			break;
 
-	if (i >= sizeof(phy_info) / sizeof(phy_info[0])) {
+	if (i >= ARRAY_SIZE(phy_info)) {
 		printk(KERN_ERR DRV_MODULE_NAME
 		       ": %s PHY id 0x%08x is not supported!\n",
 		       dev->name, phy_hwid);
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index 38fd525..7599d77 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -259,7 +259,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c
index d85e2ea..29f9750 100644
--- a/drivers/net/zorro8390.c
+++ b/drivers/net/zorro8390.c
@@ -191,7 +191,7 @@ static int __devinit zorro8390_init(struct net_device *dev,
 	    {0x00,	NE_EN0_RSARHI},
 	    {E8390_RREAD+E8390_START, NE_CMD},
 	};
-	for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
 	    z_writeb(program_seq[i].value, ioaddr + program_seq[i].offset);
 	}
     }


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] misc-wireless: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2007-02-05 16:56 ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
@ 2007-02-05 16:58 ` Ahmed S. Darwish
  2007-02-05 16:58 ` [PATCH 2.6.20] hostap: " Ahmed S. Darwish
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:58 UTC (permalink / raw)
  To: linville; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous wireless drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 44a2270..4ad910b 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1623,7 +1623,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
 
 	crypto_cipher_setkey(tfm, pkey, 16);
 	counter = 0;
-	for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
+	for (i = 0; i < ARRAY_SIZE(context->coeff); ) {
 		aes_counter[15] = (u8)(counter >> 0);
 		aes_counter[14] = (u8)(counter >> 8);
 		aes_counter[13] = (u8)(counter >> 16);
@@ -1632,7 +1632,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
 		memcpy (plain, aes_counter, 16);
 		crypto_cipher_encrypt_one(tfm, plain, plain);
 		cipher = plain;
-		for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
+		for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
 			context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
 			j += 4;
 		}
diff --git a/drivers/net/wireless/prism54/oid_mgt.c b/drivers/net/wireless/prism54/oid_mgt.c
index e6cf9df..4278032 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -16,6 +16,8 @@
  *
  */
 
+#include <linux/kernel.h>
+
 #include "prismcompat.h"
 #include "islpci_dev.h"
 #include "islpci_mgt.h"
@@ -692,7 +694,7 @@ mgt_update_addr(islpci_private *priv)
 	return ret;
 }
 
-#define VEC_SIZE(a) (sizeof(a)/sizeof(a[0]))
+#define VEC_SIZE(a) ARRAY_SIZE(a)
 
 int
 mgt_commit(islpci_private *priv)



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] hostap: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2007-02-05 16:58 ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
@ 2007-02-05 16:58 ` Ahmed S. Darwish
  2007-02-05 16:59   ` Ahmed S. Darwish
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:58 UTC (permalink / raw)
  To: jkmaline, linville; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro in the Host AP wireless driver.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/hostap/hostap.h b/drivers/net/wireless/hostap/hostap.h
index e89c890..ef37a75 100644
--- a/drivers/net/wireless/hostap/hostap.h
+++ b/drivers/net/wireless/hostap/hostap.h
@@ -2,13 +2,14 @@
 #define HOSTAP_H
 
 #include <linux/ethtool.h>
+#include <linux/kernel.h>
 
 #include "hostap_wlan.h"
 #include "hostap_ap.h"
 
 static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
 				  2447, 2452, 2457, 2462, 2467, 2472, 2484 };
-#define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
+#define FREQ_COUNT ARRAY_SIZE(freq_list)
 
 /* hostap.c */
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
@ 2007-02-05 16:59   ` Ahmed S. Darwish
  2007-02-05 16:56 ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:59 UTC (permalink / raw)
  To: ebs; +Cc: linux-kernel, netdev, linuxppc-embedded

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile-tested cause I don't have the needed hardware.

diff --git a/drivers/net/ibm_emac/ibm_emac_debug.c b/drivers/net/ibm_emac/ibm_emac_debug.c
index 92f970d..1f70906 100644
--- a/drivers/net/ibm_emac/ibm_emac_debug.c
+++ b/drivers/net/ibm_emac/ibm_emac_debug.c
@@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private *dev)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
+	if (idx >= ARRAY_SIZE(__emacs)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering EMAC for debugging\n",
 		       idx);
@@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
+	if (idx >= ARRAY_SIZE(__mals)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering MAL for debugging\n",
 		       idx);
@@ -167,11 +167,11 @@ void emac_dbg_dump_all(void)
 
 	local_irq_save(flags);
 
-	for (i = 0; i < sizeof(__mals) / sizeof(__mals[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__mals); ++i)
 		if (__mals[i])
 			emac_mal_dump(__mals[i]);
 
-	for (i = 0; i < sizeof(__emacs) / sizeof(__emacs[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__emacs); ++i)
 		if (__emacs[i])
 			emac_mac_dump(i, __emacs[i]);
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
@ 2007-02-05 16:59   ` Ahmed S. Darwish
  0 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:59 UTC (permalink / raw)
  To: ebs; +Cc: netdev, linux-kernel, linuxppc-embedded

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile-tested cause I don't have the needed hardware.

diff --git a/drivers/net/ibm_emac/ibm_emac_debug.c b/drivers/net/ibm_emac/ibm_emac_debug.c
index 92f970d..1f70906 100644
--- a/drivers/net/ibm_emac/ibm_emac_debug.c
+++ b/drivers/net/ibm_emac/ibm_emac_debug.c
@@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private *dev)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
+	if (idx >= ARRAY_SIZE(__emacs)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering EMAC for debugging\n",
 		       idx);
@@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
+	if (idx >= ARRAY_SIZE(__mals)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering MAL for debugging\n",
 		       idx);
@@ -167,11 +167,11 @@ void emac_dbg_dump_all(void)
 
 	local_irq_save(flags);
 
-	for (i = 0; i < sizeof(__mals) / sizeof(__mals[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__mals); ++i)
 		if (__mals[i])
 			emac_mal_dump(__mals[i]);
 
-	for (i = 0; i < sizeof(__emacs) / sizeof(__emacs[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__emacs); ++i)
 		if (__emacs[i])
 			emac_mac_dump(i, __emacs[i]);
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2007-02-05 16:59   ` Ahmed S. Darwish
@ 2007-02-05 16:59 ` Ahmed S. Darwish
  2007-02-05 20:18   ` Alexey Dobriyan
  2007-02-05 17:00 ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
  7 siblings, 1 reply; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 16:59 UTC (permalink / raw)
  To: jeffrey.t.kirsher; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..26031fe 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
 	return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
+#define LIST_LEN(l) ARRAY_SIZE(l)
 
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2007-02-05 16:59 ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
@ 2007-02-05 17:00 ` Ahmed S. Darwish
  2007-02-05 20:17   ` Alexey Dobriyan
  7 siblings, 1 reply; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-05 17:00 UTC (permalink / raw)
  To: jt, linville; +Cc: linux-kernel, netdev

Hi,

A trivial patch to use ARRAY_SIZE macro.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe12c77 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -450,7 +450,7 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
 #define	WATCHDOG_JIFFIES	(512*HZ/100)
 
 /* Macro to get the number of elements in an array */
-#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
+#define	NELS(a)				ARRAY_SIZE(a)
 
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate
  2007-02-05 17:00 ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
@ 2007-02-05 20:17   ` Alexey Dobriyan
  2007-02-06  9:34     ` Ahmed S. Darwish
  0 siblings, 1 reply; 22+ messages in thread
From: Alexey Dobriyan @ 2007-02-05 20:17 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: jt, linville, linux-kernel, netdev

On Mon, Feb 05, 2007 at 07:00:44PM +0200, Ahmed S. Darwish wrote:
> A trivial patch to use ARRAY_SIZE macro.

You're supposed to remove it ans use ARRAY_SIZE where old macro is used.

> --- a/drivers/net/wireless/wavelan.p.h
> +++ b/drivers/net/wireless/wavelan.p.h
> @@ -450,7 +450,7 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
>  #define	WATCHDOG_JIFFIES	(512*HZ/100)
>
>  /* Macro to get the number of elements in an array */
> -#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
> +#define	NELS(a)				ARRAY_SIZE(a)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:59 ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
@ 2007-02-05 20:18   ` Alexey Dobriyan
  2007-02-05 20:31     ` Auke Kok
  0 siblings, 1 reply; 22+ messages in thread
From: Alexey Dobriyan @ 2007-02-05 20:18 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: jeffrey.t.kirsher, linux-kernel, netdev

On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
> A patch to use ARRAY_SIZE macro already defined in kernel.h.

Remove it and use ARRAY_SIZE instead.

> --- a/drivers/net/ixgb/ixgb_param.c
> +++ b/drivers/net/ixgb/ixgb_param.c
> @@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
>  	return -1;
>  }
>  
> -#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
> +#define LIST_LEN(l) ARRAY_SIZE(l)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:59   ` Ahmed S. Darwish
@ 2007-02-05 20:22     ` Alexey Dobriyan
  -1 siblings, 0 replies; 22+ messages in thread
From: Alexey Dobriyan @ 2007-02-05 20:22 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: ebs, linux-kernel, netdev, linuxppc-embedded

On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
> A patch to use ARRAY_SIZE macro already defined in kernel.h.

OK, but checks you're changing are strange. idx there is signed so

	BUG_ON(idx < 0 || idx > ARRAY_SIZE());

should be more appropriate.

> --- a/drivers/net/ibm_emac/ibm_emac_debug.c
> +++ b/drivers/net/ibm_emac/ibm_emac_debug.c
> @@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private *dev)
>  {
>  	unsigned long flags;
>  
> -	if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
> +	if (idx >= ARRAY_SIZE(__emacs)) {

no __vi, no cookie. :)

>  		printk(KERN_WARNING
>  		       "invalid index %d when registering EMAC for debugging\n",
>  		       idx);
> @@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
>  {
>  	unsigned long flags;
>  
> -	if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
> +	if (idx >= ARRAY_SIZE(__mals)) {
>  		printk(KERN_WARNING
>  		       "invalid index %d when registering MAL for debugging\n",
>  		       idx);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
@ 2007-02-05 20:22     ` Alexey Dobriyan
  0 siblings, 0 replies; 22+ messages in thread
From: Alexey Dobriyan @ 2007-02-05 20:22 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: netdev, linuxppc-embedded, linux-kernel

On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
> A patch to use ARRAY_SIZE macro already defined in kernel.h.

OK, but checks you're changing are strange. idx there is signed so

	BUG_ON(idx < 0 || idx > ARRAY_SIZE());

should be more appropriate.

> --- a/drivers/net/ibm_emac/ibm_emac_debug.c
> +++ b/drivers/net/ibm_emac/ibm_emac_debug.c
> @@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private *dev)
>  {
>  	unsigned long flags;
>  
> -	if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
> +	if (idx >= ARRAY_SIZE(__emacs)) {

no __vi, no cookie. :)

>  		printk(KERN_WARNING
>  		       "invalid index %d when registering EMAC for debugging\n",
>  		       idx);
> @@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
>  {
>  	unsigned long flags;
>  
> -	if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
> +	if (idx >= ARRAY_SIZE(__mals)) {
>  		printk(KERN_WARNING
>  		       "invalid index %d when registering MAL for debugging\n",
>  		       idx);

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-05 20:18   ` Alexey Dobriyan
@ 2007-02-05 20:31     ` Auke Kok
  2007-02-06 10:00       ` Ahmed S. Darwish
  0 siblings, 1 reply; 22+ messages in thread
From: Auke Kok @ 2007-02-05 20:31 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Alexey Dobriyan, jeffrey.t.kirsher, linux-kernel, netdev

Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
>> A patch to use ARRAY_SIZE macro already defined in kernel.h.
> 
> Remove it and use ARRAY_SIZE instead.
> 
>> --- a/drivers/net/ixgb/ixgb_param.c
>> +++ b/drivers/net/ixgb/ixgb_param.c
>> @@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
>>  	return -1;
>>  }
>>  
>> -#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
>> +#define LIST_LEN(l) ARRAY_SIZE(l)

yes, well spotted. Please change line 338 in this file to read:

      .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),

instead, so you can remove the LIST_LEN macro completely.

Thanks,

Auke

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
  2007-02-05 20:22     ` Alexey Dobriyan
@ 2007-02-06  9:12       ` Ahmed S. Darwish
  -1 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06  9:12 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: ebs, linux-kernel, netdev, linuxppc-embedded

On Mon, Feb 05, 2007 at 11:22:06PM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
> > A patch to use ARRAY_SIZE macro already defined in kernel.h.
> 
> OK, but checks you're changing are strange. idx there is signed so
> 
> 	BUG_ON(idx < 0 || idx > ARRAY_SIZE());
> 
> should be more appropriate.

It's just a janitor patch. I don't like to mess with code logic in such
kind of patches (to minimize errors and because I can't find time to
understand all affected files since they are scattered allover the tree).

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
@ 2007-02-06  9:12       ` Ahmed S. Darwish
  0 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06  9:12 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: netdev, linuxppc-embedded, linux-kernel

On Mon, Feb 05, 2007 at 11:22:06PM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
> > A patch to use ARRAY_SIZE macro already defined in kernel.h.
> 
> OK, but checks you're changing are strange. idx there is signed so
> 
> 	BUG_ON(idx < 0 || idx > ARRAY_SIZE());
> 
> should be more appropriate.

It's just a janitor patch. I don't like to mess with code logic in such
kind of patches (to minimize errors and because I can't find time to
understand all affected files since they are scattered allover the tree).

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate
  2007-02-05 20:17   ` Alexey Dobriyan
@ 2007-02-06  9:34     ` Ahmed S. Darwish
  0 siblings, 0 replies; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06  9:34 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: jt, linville, linux-kernel, netdev

On Mon, Feb 05, 2007 at 11:17:09PM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 07:00:44PM +0200, Ahmed S. Darwish wrote:
> > A trivial patch to use ARRAY_SIZE macro.
> 
> You're supposed to remove it ans use ARRAY_SIZE where old macro is used.
> 
> > --- a/drivers/net/wireless/wavelan.p.h
> > +++ b/drivers/net/wireless/wavelan.p.h
> > @@ -450,7 +450,7 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
> >  #define	WATCHDOG_JIFFIES	(512*HZ/100)
> >
> >  /* Macro to get the number of elements in an array */
> > -#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
> > +#define	NELS(a)				ARRAY_SIZE(a)

Ooh, how dumb the original patch is :). Thanks, here's the modified patch.

A patch to use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 24221e4..2aa3c76 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -28,7 +28,7 @@
  */
 static u8 wv_irq_to_psa(int irq)
 {
-	if (irq < 0 || irq >= NELS(irqvals))
+	if (irq < 0 || irq >= ARRAY_SIZE(irqvals))
 		return 0;
 
 	return irqvals[irq];
@@ -42,7 +42,7 @@ static int __init wv_psa_to_irq(u8 irqval)
 {
 	int irq;
 
-	for (irq = 0; irq < NELS(irqvals); irq++)
+	for (irq = 0; irq < ARRAY_SIZE(irqvals); irq++)
 		if (irqvals[irq] == irqval)
 			return irq;
 
@@ -1695,7 +1695,7 @@ static int wv_frequency_list(unsigned long ioaddr,	/* I/O port of the card */
 		/* Look in the table if the frequency is allowed */
 		if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
 			/* Compute approximate channel number */
-			while ((c < NELS(channel_bands)) &&
+			while ((c < ARRAY_SIZE(channel_bands)) &&
 				(((channel_bands[c] >> 1) - 24) < freq)) 
 				c++;
 			list[i].i = c;	/* Set the list index */
@@ -4269,7 +4269,7 @@ struct net_device * __init wavelan_probe(int unit)
 		printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
 #endif
 	} else { /* Scan all possible addresses of the WaveLAN hardware. */
-		for (i = 0; i < NELS(iobase); i++) {
+		for (i = 0; i < ARRAY_SIZE(iobase); i++) {
 			dev->irq = def_irq;
 			if (wavelan_config(dev, iobase[i]) == 0) {
 #ifdef DEBUG_CALLBACK_TRACE
@@ -4280,7 +4280,7 @@ struct net_device * __init wavelan_probe(int unit)
 				break;
 			}
 		}
-		if (i == NELS(iobase))
+		if (i == ARRAY_SIZE(iobase))
 			r = -ENODEV;
 	}
 	if (r) 
@@ -4327,14 +4327,14 @@ int __init init_module(void)
 #endif
 
 		/* Copy the basic set of address to be probed. */
-		for (i = 0; i < NELS(iobase); i++)
+		for (i = 0; i < ARRAY_SIZE(iobase); i++)
 			io[i] = iobase[i];
 	}
 
 
 	/* Loop on all possible base addresses. */
 	i = -1;
-	while ((io[++i] != 0) && (i < NELS(io))) {
+	while ((io[++i] != 0) && (i < ARRAY_SIZE(io))) {
 		struct net_device *dev = alloc_etherdev(sizeof(net_local));
 		if (!dev)
 			break;
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe24281 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -449,9 +449,6 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
 /* Watchdog temporisation */
 #define	WATCHDOG_JIFFIES	(512*HZ/100)
 
-/* Macro to get the number of elements in an array */
-#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
-
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 
 #define SIOCSIPQTHR	SIOCIWFIRSTPRIV		/* Set quality threshold */

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-05 20:31     ` Auke Kok
@ 2007-02-06 10:00       ` Ahmed S. Darwish
  2007-02-06 16:48         ` Auke Kok
  0 siblings, 1 reply; 22+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 10:00 UTC (permalink / raw)
  To: Auke Kok; +Cc: Alexey Dobriyan, jeffrey.t.kirsher, linux-kernel, netdev

On Mon, Feb 05, 2007 at 12:31:26PM -0800, Auke Kok wrote:
> Alexey Dobriyan wrote:
> >On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
> >>A patch to use ARRAY_SIZE macro already defined in kernel.h.
> >
> >Remove it and use ARRAY_SIZE instead.
> >
> >>--- a/drivers/net/ixgb/ixgb_param.c
> >>+++ b/drivers/net/ixgb/ixgb_param.c
> >>@@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option 
> >>*opt)
> >> 	return -1;
> >> }
> >> 
> >>-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
> >>+#define LIST_LEN(l) ARRAY_SIZE(l)
> 
> yes, well spotted. Please change line 338 in this file to read:
> 
>      .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
> 
> instead, so you can remove the LIST_LEN macro completely.
 
Thanks, Here's the new patch.

Use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..c38ce73 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,8 +245,6 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
 	return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
-
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters
  * @adapter: board private structure
@@ -335,7 +333,7 @@ ixgb_check_options(struct ixgb_adapter *adapter)
 			.name = "Flow Control",
 			.err  = "reading default settings from EEPROM",
 			.def  = ixgb_fc_tx_pause,
-			.arg  = { .l = { .nr = LIST_LEN(fc_list),
+			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
 					 .p = fc_list }}
 		};


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-06 10:00       ` Ahmed S. Darwish
@ 2007-02-06 16:48         ` Auke Kok
  0 siblings, 0 replies; 22+ messages in thread
From: Auke Kok @ 2007-02-06 16:48 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Alexey Dobriyan, jeffrey.t.kirsher, linux-kernel, netdev

Ahmed S. Darwish wrote:
> On Mon, Feb 05, 2007 at 12:31:26PM -0800, Auke Kok wrote:
>> Alexey Dobriyan wrote:
>>> On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
>>>> A patch to use ARRAY_SIZE macro already defined in kernel.h.
>>> Remove it and use ARRAY_SIZE instead.
>>>
>>>> --- a/drivers/net/ixgb/ixgb_param.c
>>>> +++ b/drivers/net/ixgb/ixgb_param.c
>>>> @@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option 
>>>> *opt)
>>>> 	return -1;
>>>> }
>>>>
>>>> -#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
>>>> +#define LIST_LEN(l) ARRAY_SIZE(l)
>> yes, well spotted. Please change line 338 in this file to read:
>>
>>      .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
>>
>> instead, so you can remove the LIST_LEN macro completely.
>  
> Thanks, Here's the new patch.
> 
> Use ARRAY_SIZE macro when appropriate.
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>

Acked-by: Auke Kok <auke-jan.h.kok@intel.com>

Cheers,

Auke

> ---
> diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
> index b27442a..c38ce73 100644
> --- a/drivers/net/ixgb/ixgb_param.c
> +++ b/drivers/net/ixgb/ixgb_param.c
> @@ -245,8 +245,6 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
>  	return -1;
>  }
>  
> -#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
> -
>  /**
>   * ixgb_check_options - Range Checking for Command Line Parameters
>   * @adapter: board private structure
> @@ -335,7 +333,7 @@ ixgb_check_options(struct ixgb_adapter *adapter)
>  			.name = "Flow Control",
>  			.err  = "reading default settings from EEPROM",
>  			.def  = ixgb_fc_tx_pause,
> -			.arg  = { .l = { .nr = LIST_LEN(fc_list),
> +			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
>  					 .p = fc_list }}
>  		};
> 
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:55 ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-06 17:16   ` Auke Kok
  0 siblings, 0 replies; 22+ messages in thread
From: Auke Kok @ 2007-02-06 17:16 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: cramerj, john.ronciak, linux-kernel, netdev

Ahmed S. Darwish wrote:
> Hi,
> 
> A patch to use ARRAY_SIZE macro already defined in kernel.h.
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>

Acked-by: Auke Kok <auke-jan.h.kok@intel.com>

Cheers,

Auke

> ---
> Patch is compile tested.
> 
> diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
> index fb96c87..d21706e 100644
> --- a/drivers/net/e1000/e1000_ethtool.c
> +++ b/drivers/net/e1000/e1000_ethtool.c
> @@ -746,7 +746,7 @@ err_setup:
>  	uint32_t pat, value;                                                   \
>  	uint32_t test[] =                                                      \
>  		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};              \
> -	for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
> +	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {              \
>  		E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
>  		value = E1000_READ_REG(&adapter->hw, R);                       \
>  		if (value != (test[pat] & W & M)) {                             \
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2007-02-06 17:17 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-05 16:54 [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
2007-02-05 16:55 ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-06 17:16   ` Auke Kok
2007-02-05 16:56 ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
2007-02-05 16:56 ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
2007-02-05 16:57   ` [PATCH 02/02] " Ahmed S. Darwish
2007-02-05 16:58 ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
2007-02-05 16:58 ` [PATCH 2.6.20] hostap: " Ahmed S. Darwish
2007-02-05 16:59 ` [PATCH 2.6.20] ibm_emac: " Ahmed S. Darwish
2007-02-05 16:59   ` Ahmed S. Darwish
2007-02-05 20:22   ` Alexey Dobriyan
2007-02-05 20:22     ` Alexey Dobriyan
2007-02-06  9:12     ` Ahmed S. Darwish
2007-02-06  9:12       ` Ahmed S. Darwish
2007-02-05 16:59 ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
2007-02-05 20:18   ` Alexey Dobriyan
2007-02-05 20:31     ` Auke Kok
2007-02-06 10:00       ` Ahmed S. Darwish
2007-02-06 16:48         ` Auke Kok
2007-02-05 17:00 ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
2007-02-05 20:17   ` Alexey Dobriyan
2007-02-06  9:34     ` Ahmed S. Darwish

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.