All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00] A series of patches to use ARRAY_SIZE macro
@ 2007-02-06 16:02 Ahmed S. Darwish
  2007-02-06 16:03 ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
                   ` (15 more replies)
  0 siblings, 16 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:02 UTC (permalink / raw)
  To: linux-kernel

Hi lovely list :),

Follows (as thread replies) is a series of patches to use ARRAY_SIZE 
macro defined in kernel.h.

It's complementary to previous patch serieses that dealt with this 
issue under `video' (drivers/media/video), `net' (drivers/net) and 
`arch' subtrees.

 drivers/acpi/toshiba_acpi.c            |    2 +-
 drivers/atm/he.c                       |    2 +-
 drivers/atm/idt77252.c                 |    8 ++++----
 drivers/atm/nicstarmac.c               |    4 +++-
 drivers/char/agp/intel-agp.c           |    3 ++-
 drivers/char/drm/drm_proc.c            |    2 +-
 drivers/infiniband/core/device.c       |    3 ++-
 drivers/isdn/capi/capi.c               |    4 ++--
 drivers/isdn/capi/capidrv.c            |    4 ++--
 drivers/isdn/hardware/eicon/debug.c    |   30 +++++++++++++++---------------
 drivers/isdn/hardware/eicon/message.c  |   23 +++++++++++------------
 drivers/isdn/hardware/eicon/platform.h |    4 ----
 drivers/kvm/kvm_svm.h                  |    3 ++-
 drivers/kvm/svm.c                      |    5 +++--
 drivers/kvm/vmx.c                      |    6 +++---
 drivers/md/md.c                        |    6 +++---
 drivers/media/dvb/bt8xx/dst.c          |    2 +-
 drivers/media/dvb/bt8xx/dvb-bt8xx.c    |    3 ++-
 drivers/media/dvb/frontends/cx24110.c  |    4 ++--
 drivers/media/dvb/frontends/cx24123.c  |    6 +++---
 drivers/media/dvb/ttpci/av7110_ir.c    |    3 ++-
 drivers/s390/cio/device_id.c           |    3 ++-
 drivers/w1/slaves/w1_therm.c           |    6 +++---
 fs/reiserfs/do_balan.c                 |    5 +++--
 kernel/rcutorture.c                    |    2 +-
 sound/oss/au1550_ac97.c                |    4 ++--
 sound/oss/es1371.c                     |    3 ++-
 sound/oss/nec_vrc5477.c                |    4 ++--
 sound/oss/soundcard.c                  |    5 +++--
 sound/oss/swarm_cs4297a.c              |    3 ++-
 30 files changed, 85 insertions(+), 77 deletions(-)

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

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

* [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
@ 2007-02-06 16:03 ` Ahmed S. Darwish
  2007-02-06 16:03 ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:03 UTC (permalink / raw)
  To: v4l-dvb-maintainer; +Cc: linux-kernel

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/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 9f72b70..0393a3d 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1161,7 +1161,7 @@ static int dst_get_device_id(struct dst_state *state)
 		}
 	}
 
-	if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
+	if (i >= ARRAY_SIZE(dst_tlist)) {
 		dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
 		dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
 		use_dst_type = DST_TYPE_IS_SAT;
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 3e35931..5185a3c 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -213,7 +214,7 @@ static int cx24108_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend
 		freq = 2150000; /* satellite IF is 950..2150MHz */
 
 	/* decide which VCO to use for the input frequency */
-	for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
+	for(i=1;(i<ARRAY_SIZE(osci))&&(osci[i]<freq);i++);
 	printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
 	band=bandsel[i];
 	/* the gain values must be set by SetSymbolrate */
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ae96395..96ae6b1 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -254,7 +254,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
 	if (srate<500000)
 		srate=500000;
 
-	for(i=0;(i<sizeof(bands)/sizeof(bands[0]))&&(srate>bands[i]);i++)
+	for(i=0;(i<ARRAY_SIZE(bands))&&(srate>bands[i]);i++)
 		;
 	/* first, check which sample rate is appropriate: 45, 60 80 or 90 MHz,
 	   and set the PLL accordingly (R07[1:0] Fclk, R06[7:4] PLLmult,
@@ -361,7 +361,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
 
 	dprintk("%s: init chip\n", __FUNCTION__);
 
-	for(i=0;i<sizeof(cx24110_regdata)/sizeof(cx24110_regdata[0]);i++) {
+	for(i=0;i<ARRAY_SIZE(cx24110_regdata);i++) {
 		cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data);
 	};
 
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index a356d28..732e94a 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -507,7 +507,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	int i = 0;
 	int pump = 2;
 	int band = 0;
-	int num_bands = sizeof(cx24123_bandselect_vals) / sizeof(cx24123_bandselect_vals[0]);
+	int num_bands = ARRAY_SIZE(cx24123_bandselect_vals);
 
 	/* Defaults for low freq, low rate */
 	state->VCAarg = cx24123_AGC_vals[0].VCAprogdata;
@@ -516,7 +516,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	vco_div = cx24123_bandselect_vals[0].VCOdivider;
 
 	/* For the given symbol rate, determine the VCA, VGA and FILTUNE programming bits */
-	for (i = 0; i < sizeof(cx24123_AGC_vals) / sizeof(cx24123_AGC_vals[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++)
 	{
 		if ((cx24123_AGC_vals[i].symbolrate_low <= p->u.qpsk.symbol_rate) &&
 		    (cx24123_AGC_vals[i].symbolrate_high >= p->u.qpsk.symbol_rate) ) {
@@ -658,7 +658,7 @@ static int cx24123_initfe(struct dvb_frontend* fe)
 	dprintk("%s:  init frontend\n",__FUNCTION__);
 
 	/* Configure the demod to a good set of defaults */
-	for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
 		cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data);
 
 	/* Set the LNB polarity */
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index e4544ea..c281d78 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -4,6 +4,7 @@
 #include <linux/moduleparam.h>
 #include <linux/input.h>
 #include <linux/proc_fs.h>
+#include <linux/kernel.h>
 #include <asm/bitops.h>
 
 #include "av7110.h"
@@ -217,7 +218,7 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
 	static struct proc_dir_entry *e;
 	int err;
 
-	if (av_cnt >= sizeof av_list/sizeof av_list[0])
+	if (av_cnt >= ARRAY_SIZE(av_list))
 		return -ENOSPC;
 
 	av7110_setup_irc_config(av7110, 0x0001);

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

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

* [PATCH 2.6.20] KVM: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
  2007-02-06 16:03 ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-06 16:03 ` Ahmed S. Darwish
  2007-02-06 16:56     ` Dor Laor
  2007-02-06 16:04 ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:03 UTC (permalink / raw)
  To: avi; +Cc: linux-kernel, kvm-devel

Hi all,

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/kvm/kvm_svm.h b/drivers/kvm/kvm_svm.h
index 74cc862..624f1ca 100644
--- a/drivers/kvm/kvm_svm.h
+++ b/drivers/kvm/kvm_svm.h
@@ -1,6 +1,7 @@
 #ifndef __KVM_SVM_H
 #define __KVM_SVM_H
 
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/list.h>
 #include <asm/msr.h>
@@ -18,7 +19,7 @@ static const u32 host_save_msrs[] = {
 	MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/
 };
 
-#define NR_HOST_SAVE_MSRS (sizeof(host_save_msrs) / sizeof(*host_save_msrs))
+#define NR_HOST_SAVE_MSRS ARRAY_SIZE(host_save_msrs)
 #define NUM_DB_REGS 4
 
 struct vcpu_svm {
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index c79df79..dc5c172 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
 #include <linux/profile.h>
@@ -75,7 +76,7 @@ struct svm_init_data {
 
 static u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000};
 
-#define NUM_MSR_MAPS (sizeof(msrpm_ranges) / sizeof(*msrpm_ranges))
+#define NUM_MSR_MAPS ARRAY_SIZE(msrpm_ranges)
 #define MSRS_RANGE_SIZE 2048
 #define MSRS_IN_RANGE (MSRS_RANGE_SIZE * 8 / 2)
 
@@ -1287,7 +1288,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		       __FUNCTION__, vcpu->svm->vmcb->control.exit_int_info,
 		       exit_code);
 
-	if (exit_code >= sizeof(svm_exit_handlers) / sizeof(*svm_exit_handlers)
+	if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
 	    || svm_exit_handlers[exit_code] == 0) {
 		kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
 		printk(KERN_ERR "%s: 0x%x @ 0x%llx cr0 0x%lx rflags 0x%llx\n",
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 54c35c0..072965b 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -19,6 +19,7 @@
 #include "vmx.h"
 #include "kvm_vmx.h"
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/profile.h>
@@ -76,7 +77,7 @@ static const u32 vmx_msr_index[] = {
 #endif
 	MSR_EFER, MSR_K6_STAR,
 };
-#define NR_VMX_MSR (sizeof(vmx_msr_index) / sizeof(*vmx_msr_index))
+#define NR_VMX_MSR ARRAY_SIZE(vmx_msr_index)
 
 static inline int is_page_fault(u32 intr_info)
 {
@@ -1645,8 +1646,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
 	[EXIT_REASON_HLT]                     = handle_halt,
 };
 
-static const int kvm_vmx_max_exit_handlers =
-	sizeof(kvm_vmx_exit_handlers) / sizeof(*kvm_vmx_exit_handlers);
+static const int kvm_vmx_max_exit_handlers = ARRAY_SIZE(kvm_vmx_exit_handlers);
 
 /*
  * The guest has exited.  See if we can fix it or if we need userspace


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

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

* [PATCH 2.6.20] isdn-eicon: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
  2007-02-06 16:03 ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  2007-02-06 16:03 ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
@ 2007-02-06 16:04 ` Ahmed S. Darwish
  2007-02-06 16:04 ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:04 UTC (permalink / raw)
  To: mac, kkeil; +Cc: linux-kernel, isdn4linux

Hi all,

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

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Also remove the macro 
`#define DIM(array)  (sizeof (array)/sizeof ((array)[0]))'
that reimplements ARRAY_SIZE. Encourage new code to use ARRAY_SIZE ;).

 debug.c    |   30 +++++++++++++++---------------
 message.c  |   23 +++++++++++------------
 platform.h |    4 ----
 3 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/drivers/isdn/hardware/eicon/debug.c b/drivers/isdn/hardware/eicon/debug.c
index d835e74..0db9cc6 100644
--- a/drivers/isdn/hardware/eicon/debug.c
+++ b/drivers/isdn/hardware/eicon/debug.c
@@ -287,7 +287,7 @@ void* diva_maint_finit (void) {
   }
   external_dbg_queue = 0;
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].pmem) {
       diva_os_free (0, clients[i].pmem);
     }
@@ -391,7 +391,7 @@ static void DI_register (void *arg) {
 
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
 
-  for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) {
+  for (id = 1; id < ARRAY_SIZE(clients); id++) {
     if (clients[id].hDbg == hDbg) {
       /*
         driver already registered
@@ -494,7 +494,7 @@ static void DI_deregister (pDbgHandle hDbg) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg == hDbg) {
       diva_dbg_entry_head_t* pmsg;
       char tmp[256];
@@ -736,7 +736,7 @@ int diva_get_driver_info (dword id, byte* data, int data_length) {
   int to_copy;
 
   if (!data || !id || (data_length < 17) ||
-      (id >= (sizeof(clients)/sizeof(clients[0])))) {
+      (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
 
@@ -786,7 +786,7 @@ int diva_get_driver_dbg_mask (dword id, byte* data) {
   diva_os_spin_lock_magic_t old_irql;
   int ret = -1;
 
-  if (!data || !id || (id >= (sizeof(clients)/sizeof(clients[0])))) {
+  if (!data || !id || (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info");
@@ -809,7 +809,7 @@ int diva_set_driver_dbg_mask (dword id, dword mask) {
   int ret = -1;
   
 
-  if (!id || (id >= (sizeof(clients)/sizeof(clients[0])))) {
+  if (!id || (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
 
@@ -887,7 +887,7 @@ void diva_mnt_add_xdi_adapter (const DESCRIPTOR* d) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
 
-  for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) {
+  for (id = 1; id < ARRAY_SIZE(clients); id++) {
     if (clients[id].hDbg && (clients[id].request == d->request)) {
       diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
       diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
@@ -1037,7 +1037,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && (clients[i].request == d->request)) {
       diva_dbg_entry_head_t* pmsg;
       char tmp[256];
@@ -1115,7 +1115,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
 void* SuperTraceOpenAdapter   (int AdapterNumber) {
   int i;
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].request && (clients[i].logical == AdapterNumber)) {
       return (&clients[i]);
     }
@@ -1508,7 +1508,7 @@ static void diva_maint_state_change_notify (void* user_context,
 					int ch = TraceFilterChannel;
 					int id = TraceFilterIdent;
 
-					if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+					if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
 						(clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
 						if (ch != (int)modem->ChannelNumber) {
 							break;
@@ -1555,7 +1555,7 @@ static void diva_maint_state_change_notify (void* user_context,
 					int ch = TraceFilterChannel;
 					int id = TraceFilterIdent;
 
-					if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+					if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
 						(clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
 						if (ch != (int)fax->ChannelNumber) {
 							break;
@@ -1803,7 +1803,7 @@ static void diva_maint_trace_notify (void* user_context,
   /*
     Selective trace
     */
-  if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+  if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
       (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
     const char* p = NULL;
     int ch_value = -1;
@@ -1925,7 +1925,7 @@ int diva_mnt_shutdown_xdi_adapters (void) {
   byte * pmem;
 
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     pmem = NULL;
 
     diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "unload");
@@ -2006,7 +2006,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
 
   on = (TraceFilter[0] == 0);
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) {
       client_b_on    = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0);
       client_atap_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO)    != 0);
@@ -2017,7 +2017,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
     }
   }
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) {
       diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
       clients[i].request_pending = 0;
diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
index f9b00f1..4e29d38 100644
--- a/drivers/isdn/hardware/eicon/message.c
+++ b/drivers/isdn/hardware/eicon/message.c
@@ -6812,7 +6812,7 @@ void nl_ind(PLCI   * plci)
         }
         if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
         {
-          if (((T30_INFO   *)plci->NL.RBuffer->P)->code < sizeof(fax_info) / sizeof(fax_info[0]))
+	  if (((T30_INFO   *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
             info = fax_info[((T30_INFO   *)plci->NL.RBuffer->P)->code];
           else
             info = _FAX_PROTOCOL_ERROR;
@@ -9564,7 +9564,7 @@ static struct
 
 };
 
-#define DTMF_DIGIT_MAP_ENTRIES (sizeof(dtmf_digit_map) / sizeof(dtmf_digit_map[0]))
+#define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
 
 
 static void dtmf_enable_receiver (PLCI   *plci, byte enable_mask)
@@ -10069,8 +10069,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER   *a, PLCI
           PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
           break;
         }
-        if (plci->dtmf_send_requests >=
-          sizeof(plci->dtmf_msg_number_queue) / sizeof(plci->dtmf_msg_number_queue[0]))
+        if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
         {
           dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
             UnMapId (Id), (char   *)(FILE_), __LINE__));
@@ -11018,9 +11017,9 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
           }
           n++;
-        } while ((n < sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
+        } while ((n < ARRAY_SIZE(xconnect_write_prog))
           && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
-        if (n == sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
+        if (n == ARRAY_SIZE(xconnect_write_prog))
         {
           do
           {
@@ -11090,7 +11089,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             ch_map[j+1] = (byte)(j+1);
           }
         }
-        for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
         {
           i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
           j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -11140,7 +11139,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
           w |= MIXER_FEATURE_ENABLE_RX_DATA;
         *(p++) = (byte) w;
         *(p++) = (byte)(w >> 8);
-        for (n = 0; n < sizeof(mixer_write_prog_pri) / sizeof(mixer_write_prog_pri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
         {
           *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
           for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
@@ -11196,7 +11195,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             ch_map[j+1] = (byte)(j+1);
           }
         }
-        for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
         {
           i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
           j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -13178,7 +13177,7 @@ static void adv_voice_write_coefs (PLCI   *plci, word write_command)
         ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
         ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
       }
-      for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+      for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
       {
         i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
         j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -14603,7 +14602,7 @@ static void channel_request_xon (PLCI   * plci, byte ch) {
 
 static void channel_xmit_extended_xon (PLCI   * plci) {
   DIVA_CAPI_ADAPTER   * a;
-  int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
+  int max_ch = ARRAY_SIZE(a->ch_flow_control);
   int i, one_requested = 0;
 
   if ((!plci) || (!plci->Id) || ((a = plci->adapter) == 0)) {
@@ -14628,7 +14627,7 @@ static void channel_xmit_extended_xon (PLCI   * plci) {
   Try to xmit next X_ON
   */
 static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER   * a, PLCI   * plci) {
-  int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
+  int max_ch = ARRAY_SIZE(a->ch_flow_control);
   int i;
 
   if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index 2444811..9ddae43 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -131,10 +131,6 @@
 #define DIVA_OS_MEM_DETACH_CONFIG(a, x)	do { } while(0)
 #define DIVA_OS_MEM_DETACH_CONTROL(a, x)	do { } while(0)
 
-#if !defined(DIM)
-#define DIM(array)  (sizeof (array)/sizeof ((array)[0]))
-#endif
-
 #define DIVA_INVALID_FILE_HANDLE  ((dword)(-1))
 
 #define DIVAS_CONTAINING_RECORD(address, type, field) \

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

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

* [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2007-02-06 16:04 ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
@ 2007-02-06 16:04 ` Ahmed S. Darwish
  2007-02-06 17:52   ` Joe Perches
  2007-02-06 16:05 ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:04 UTC (permalink / raw)
  To: kkeil, kai.germaschewski; +Cc: linux-kernel, isdn4linux

Hi all,

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

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
 capi.c    |    4 ++--
 capidrv.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c022..3804591 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1456,7 +1456,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -1468,7 +1468,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c..8cec9c3 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,7 +2218,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -2230,7 +2230,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {

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

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

* [PATCH 2.6.20 1/2] OSS: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2007-02-06 16:04 ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
@ 2007-02-06 16:05 ` Ahmed S. Darwish
  2007-02-06 16:05 ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:05 UTC (permalink / raw)
  To: linux-kernel

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 1/2] compile-tested
[PATCH 2/2] couldn't be compile-tested (orphaned hardware ?)

diff --git a/sound/oss/es1371.c b/sound/oss/es1371.c
index cc282a0..e1fbcca 100644
--- a/sound/oss/es1371.c
+++ b/sound/oss/es1371.c
@@ -131,6 +131,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/mutex.h>
 #include <linux/mm.h>
+#include <linux/kernel.h>
 
 #include <asm/io.h>
 #include <asm/page.h>
@@ -2998,7 +2999,7 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
 	set_fs(KERNEL_DS);
 	val = SOUND_MASK_LINE;
 	mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
-	for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(initvol); i++) {
 		val = initvol[i].vol;
 		mixdev_ioctl(s->codec, initvol[i].mixch, (unsigned long)&val);
 	}
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index a89108c..b92c8cd 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -32,6 +32,7 @@
 #include <linux/ctype.h>
 #include <linux/stddef.h>
 #include <linux/kmod.h>
+#include <linux/kernel.h>
 #include <asm/dma.h>
 #include <asm/io.h>
 #include <linux/wait.h>
@@ -557,7 +558,7 @@ static int __init oss_init(void)
 	/* Protecting the innocent */
 	sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
 
-	for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
+	for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
 		device_create(sound_class, NULL,
 			      MKDEV(SOUND_MAJOR, dev_list[i].minor),
 			      "%s", dev_list[i].name);
@@ -581,7 +582,7 @@ static void __exit oss_cleanup(void)
 {
 	int i, j;
 
-	for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
+	for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
 		device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
 		if (!dev_list[i].num)
 			continue;

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

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

* [PATCH 2.6.20 2/2] OSS: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (4 preceding siblings ...)
  2007-02-06 16:05 ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
@ 2007-02-06 16:05 ` Ahmed S. Darwish
  2007-02-06 16:06 ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:05 UTC (permalink / raw)
  To: linux-kernel

Hi all,

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

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
I couldn't compile-test this patch with `allyesconfig' or `allmodconfig'.

 au1550_ac97.c   |    4 ++--
 nec_vrc5477.c   |    4 ++--
 swarm_cs4297a.c |    3 ++-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c
index 2197951..a339f0c 100644
--- a/sound/oss/au1550_ac97.c
+++ b/sound/oss/au1550_ac97.c
@@ -1354,11 +1354,11 @@ au1550_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 		((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
 
 #ifdef DEBUG
-	for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
+	for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) {
 		if (ioctl_str[count].cmd == cmd)
 			break;
 	}
-	if (count < sizeof(ioctl_str) / sizeof(ioctl_str[0]))
+	if (count < ARRAY_SIZE(ioctl_str))
 		pr_debug("ioctl %s, arg=0x%lxn", ioctl_str[count].str, arg);
 	else
 		pr_debug("ioctl 0x%x unknown, arg=0x%lx\n", cmd, arg);
diff --git a/sound/oss/nec_vrc5477.c b/sound/oss/nec_vrc5477.c
index da9728e..d459bdb 100644
--- a/sound/oss/nec_vrc5477.c
+++ b/sound/oss/nec_vrc5477.c
@@ -1381,11 +1381,11 @@ static int vrc5477_ac97_ioctl(struct inode *inode, struct file *file,
 	int val, ret;
 
 #ifdef VRC5477_AC97_DEBUG
-	for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
+	for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) {
 		if (ioctl_str[count].cmd == cmd)
 			break;
 	}
-	if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
+	if (count < ARRAY_SIZE(ioctl_str))
 		printk(KERN_INFO PFX "ioctl %s\n", ioctl_str[count].str);
 	else
 		printk(KERN_INFO PFX "ioctl unknown, 0x%x\n", cmd);
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
index 471c274..9f7e5f5 100644
--- a/sound/oss/swarm_cs4297a.c
+++ b/sound/oss/swarm_cs4297a.c
@@ -77,6 +77,7 @@
 #include <linux/poll.h>
 #include <linux/smp_lock.h>
 #include <linux/mutex.h>
+#include <linux/kernel.h>
 
 #include <asm/byteorder.h>
 #include <asm/dma.h>
@@ -2676,7 +2677,7 @@ static int __init cs4297a_init(void)
 #if 0
                 val = SOUND_MASK_LINE;
                 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
-                for (i = 0; i < sizeof(initvol) / sizeof(initvol[0]); i++) {
+                for (i = 0; i < ARRAY_SIZE(initvol); i++) {
                         val = initvol[i].vol;
                         mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
                 }

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

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

* [PATCH 2.6.20] atm: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2007-02-06 16:05 ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
@ 2007-02-06 16:06 ` Ahmed S. Darwish
  2007-02-06 16:06 ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:06 UTC (permalink / raw)
  To: chas; +Cc: linux-kernel

Hi all,

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

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index db33f6f..8510026 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -3017,7 +3017,7 @@ read_prom_byte(struct he_dev *he_dev, int addr)
 	he_writel(he_dev, val, HOST_CNTL);
        
 	/* Send READ instruction */
-	for (i = 0; i < sizeof(readtab)/sizeof(readtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(readtab); i++) {
 		he_writel(he_dev, val | readtab[i], HOST_CNTL);
 		udelay(EEPROM_DELAY);
 	}
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index f407861..b4b8014 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -388,7 +388,7 @@ idt77252_eeprom_read_status(struct idt77252_dev *card)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(rdsrtab)/sizeof(rdsrtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
 		idt77252_write_gp(card, gp | rdsrtab[i]);
 		udelay(5);
 	}
@@ -422,7 +422,7 @@ idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(rdtab)/sizeof(rdtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
 		idt77252_write_gp(card, gp | rdtab[i]);
 		udelay(5);
 	}
@@ -469,14 +469,14 @@ idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(wrentab)/sizeof(wrentab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
 		idt77252_write_gp(card, gp | wrentab[i]);
 		udelay(5);
 	}
 	idt77252_write_gp(card, gp | SAR_GP_EECS);
 	udelay(5);
 
-	for (i = 0; i < sizeof(wrtab)/sizeof(wrtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
 		idt77252_write_gp(card, gp | wrtab[i]);
 		udelay(5);
 	}
diff --git a/drivers/atm/nicstarmac.c b/drivers/atm/nicstarmac.c
index 2c5e3ae..480947f 100644
--- a/drivers/atm/nicstarmac.c
+++ b/drivers/atm/nicstarmac.c
@@ -7,6 +7,8 @@
  * Read this ForeRunner's MAC address from eprom/eeprom
  */
 
+#include <linux/kernel.h>
+
 typedef void __iomem *virt_addr_t;
 
 #define CYCLE_DELAY 5
@@ -176,7 +178,7 @@ read_eprom_byte(virt_addr_t base, u_int8_t offset)
    val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0;
 
    /* Send READ instruction */
-   for (i=0; i<sizeof readtab/sizeof readtab[0]; i++)
+   for (i=0; i<ARRAY_SIZE(readtab); i++)
    {
 	NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE,
 		(val | readtab[i]) );


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

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

* [PATCH 2.6.20] drivers/md.c: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2007-02-06 16:06 ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
@ 2007-02-06 16:06 ` Ahmed S. Darwish
  2007-02-06 16:07 ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:06 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, linux-raid

Hi all,

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/md/md.c b/drivers/md/md.c
index e8807ea..6f6d9e5 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -33,6 +33,7 @@
 */
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/linkage.h>
 #include <linux/raid/md.h>
@@ -2635,8 +2636,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
 	minor = simple_strtoul(buf, &e, 10);
 	if (e==buf || (*e && *e != '\n') )
 		return -EINVAL;
-	if (major >= sizeof(super_types)/sizeof(super_types[0]) ||
-	    super_types[major].name == NULL)
+	if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL)
 		return -ENOENT;
 	mddev->major_version = major;
 	mddev->minor_version = minor;
@@ -3973,7 +3973,7 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
 	if (info->raid_disks == 0) {
 		/* just setting version number for superblock loading */
 		if (info->major_version < 0 ||
-		    info->major_version >= sizeof(super_types)/sizeof(super_types[0]) ||
+		    info->major_version >= ARRAY_SIZE(super_types) ||
 		    super_types[info->major_version].name == NULL) {
 			/* maybe try to auto-load a module? */
 			printk(KERN_INFO 


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

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

* [PATCH 2.6.20] infinband: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (7 preceding siblings ...)
  2007-02-06 16:06 ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
@ 2007-02-06 16:07 ` Ahmed S. Darwish
  2007-02-06 18:57   ` Roland Dreier
  2007-02-06 16:07 ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:07 UTC (permalink / raw)
  To: rolandd; +Cc: linux-kernel, openib-general

Hi all,

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/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 63d2a39..7fabb42 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -36,6 +36,7 @@
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
@@ -93,7 +94,7 @@ static int ib_device_check_mandatory(struct ib_device *device)
 	};
 	int i;
 
-	for (i = 0; i < sizeof mandatory_table / sizeof mandatory_table[0]; ++i) {
+	for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
 		if (!*(void **) ((void *) device + mandatory_table[i].offset)) {
 			printk(KERN_WARNING "Device %s is missing mandatory function %s\n",
 			       device->name, mandatory_table[i].name);

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

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

* [PATCH 2.6.20] s390-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (8 preceding siblings ...)
  2007-02-06 16:07 ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
@ 2007-02-06 16:07 ` Ahmed S. Darwish
  2007-02-07  6:32   ` Cornelia Huck
  2007-02-06 16:08 ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:07 UTC (permalink / raw)
  To: schwidefsky; +Cc: linux-kernel, linux-390

Hi all,

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

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Not compile tested due to (ofcourse ;)) missing hardware.

diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index f172759..997f468 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -11,6 +11,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 
 #include <asm/ccwdev.h>
 #include <asm/delay.h>
@@ -138,7 +139,7 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
 		ps->cu_model = 0x60;
 		return;
 	}
-	for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
 		if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
 		    diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
 			ps->cu_type = vm_devices[i].cu_type;


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

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

* [PATCH 2.6.20] rcutorture: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (9 preceding siblings ...)
  2007-02-06 16:07 ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
@ 2007-02-06 16:08 ` Ahmed S. Darwish
  2007-02-07 18:29   ` Josh Triplett
  2007-02-06 16:08 ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: josh; +Cc: linux-kernel

Hi all,

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/kernel/rcutorture.c b/kernel/rcutorture.c
index 482b11f..97c2277 100644
--- a/kernel/rcutorture.c
+++ b/kernel/rcutorture.c
@@ -899,7 +899,7 @@ rcu_torture_init(void)
 	/* Set up the freelist. */
 
 	INIT_LIST_HEAD(&rcu_torture_freelist);
-	for (i = 0; i < sizeof(rcu_tortures) / sizeof(rcu_tortures[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
 		rcu_tortures[i].rtort_mbtest = 0;
 		list_add_tail(&rcu_tortures[i].rtort_free,
 			      &rcu_torture_freelist);


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

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

* [PATCH 2.6.20] intel-agp: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (10 preceding siblings ...)
  2007-02-06 16:08 ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
@ 2007-02-06 16:08 ` Ahmed S. Darwish
  2007-02-06 16:08 ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: davej; +Cc: linux-kernel

Hi all,

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/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index ab0a9c0..7233310 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -5,6 +5,7 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/pagemap.h>
 #include <linux/agp_backend.h>
 #include "agp.h"
@@ -803,7 +804,7 @@ static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
  */
 static int intel_i9xx_fetch_size(void)
 {
-	int num_sizes = sizeof(intel_i830_sizes) / sizeof(*intel_i830_sizes);
+	int num_sizes = ARRAY_SIZE(intel_i830_sizes);
 	int aper_size; /* size in megabytes */
 	int i;
 


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

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

* [PATCH 2.6.20] reiserfs: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (11 preceding siblings ...)
  2007-02-06 16:08 ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
@ 2007-02-06 16:08 ` Ahmed S. Darwish
  2007-02-06 16:09 ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: reiserfs-dev; +Cc: linux-kernel, reiserfs-list

Hi all,

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/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index fba304e..f85c5cf 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -19,6 +19,7 @@
 #include <linux/time.h>
 #include <linux/reiserfs_fs.h>
 #include <linux/buffer_head.h>
+#include <linux/kernel.h>
 
 #ifdef CONFIG_REISERFS_CHECK
 
@@ -1756,7 +1757,7 @@ static void store_thrown(struct tree_balance *tb, struct buffer_head *bh)
 	if (buffer_dirty(bh))
 		reiserfs_warning(tb->tb_sb,
 				 "store_thrown deals with dirty buffer");
-	for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(tb->thrown); i++)
 		if (!tb->thrown[i]) {
 			tb->thrown[i] = bh;
 			get_bh(bh);	/* free_thrown puts this */
@@ -1769,7 +1770,7 @@ static void free_thrown(struct tree_balance *tb)
 {
 	int i;
 	b_blocknr_t blocknr;
-	for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) {
 		if (tb->thrown[i]) {
 			blocknr = tb->thrown[i]->b_blocknr;
 			if (buffer_dirty(tb->thrown[i]))


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

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

* [PATCH 2.6.20] toshiba-acpi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (12 preceding siblings ...)
  2007-02-06 16:08 ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
@ 2007-02-06 16:09 ` Ahmed S. Darwish
  2007-02-06 16:09 ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
  2007-02-06 16:10 ` [PATCH 2.6.20] drm: " Ahmed S. Darwish
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:09 UTC (permalink / raw)
  To: toshiba_acpi; +Cc: linux-kernel

Hi all,

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/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index d9b651f..0208d3a 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -125,7 +125,7 @@ static int write_acpi_int(const char *methodName, int val)
 	union acpi_object in_objs[1];
 	acpi_status status;
 
-	params.count = sizeof(in_objs) / sizeof(in_objs[0]);
+	params.count = ARRAY_SIZE(in_objs);
 	params.pointer = in_objs;
 	in_objs[0].type = ACPI_TYPE_INTEGER;
 	in_objs[0].integer.value = val;

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

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

* [PATCH 2.6.20] w1: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (13 preceding siblings ...)
  2007-02-06 16:09 ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
@ 2007-02-06 16:09 ` Ahmed S. Darwish
  2007-02-06 16:19   ` Evgeniy Polyakov
  2007-02-06 16:10 ` [PATCH 2.6.20] drm: " Ahmed S. Darwish
  15 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:09 UTC (permalink / raw)
  To: johnpol; +Cc: linux-kernel

Hi all,

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/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index b022fff..732db47 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -141,7 +141,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid)
 {
 	int i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
 		if (w1_therm_families[i].f->fid == fid)
 			return w1_therm_families[i].convert(rom);
 
@@ -238,7 +238,7 @@ static int __init w1_therm_init(void)
 {
 	int err, i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) {
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i) {
 		err = w1_register_family(w1_therm_families[i].f);
 		if (err)
 			w1_therm_families[i].broken = 1;
@@ -251,7 +251,7 @@ static void __exit w1_therm_fini(void)
 {
 	int i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
 		if (!w1_therm_families[i].broken)
 			w1_unregister_family(w1_therm_families[i].f);
 }


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

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

* [PATCH 2.6.20] drm: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (14 preceding siblings ...)
  2007-02-06 16:09 ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
@ 2007-02-06 16:10 ` Ahmed S. Darwish
  15 siblings, 0 replies; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 16:10 UTC (permalink / raw)
  To: airlied; +Cc: linux-kernel, dri-devel

Hi all,

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/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
index 62d5fe1..8943ad1 100644
--- a/drivers/char/drm/drm_proc.c
+++ b/drivers/char/drm/drm_proc.c
@@ -72,7 +72,7 @@ static struct drm_proc_list {
 #endif
 };
 
-#define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
+#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
 
 /**
  * Initialize the DRI proc filesystem for a device.


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

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

* Re: [PATCH 2.6.20] w1: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:09 ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
@ 2007-02-06 16:19   ` Evgeniy Polyakov
  0 siblings, 0 replies; 30+ messages in thread
From: Evgeniy Polyakov @ 2007-02-06 16:19 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: linux-kernel, GregKH, Andrew Morton

On Tue, Feb 06, 2007 at 06:09:33PM +0200, Ahmed S. Darwish (darwish.07@gmail.com) wrote:
> Hi all,
> 
> A patch to use ARRAY_SIZE macro already defined in kernel.h
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>

Your patch is corrent, thanks Ahmed.

Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>

Andrew, Greg will you pick it up, or should I resend it alone?

-- 
	Evgeniy Polyakov

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

* RE: [PATCH 2.6.20] KVM: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:03 ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
@ 2007-02-06 16:56     ` Dor Laor
  0 siblings, 0 replies; 30+ messages in thread
From: Dor Laor @ 2007-02-06 16:56 UTC (permalink / raw)
  To: Ahmed S. Darwish, Avi Kivity; +Cc: linux-kernel, kvm-devel

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

Applied, 10x

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

* Re: [PATCH 2.6.20] KVM: Use ARRAY_SIZE macro when appropriate
@ 2007-02-06 16:56     ` Dor Laor
  0 siblings, 0 replies; 30+ messages in thread
From: Dor Laor @ 2007-02-06 16:56 UTC (permalink / raw)
  To: Ahmed S. Darwish, Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

>
>Hi all,
>
>A patch to use ARRAY_SIZE macro already defined in kernel.h
>
>Signed-off-by: Ahmed S. Darwish <darwish.07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Applied, 10x

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:04 ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
@ 2007-02-06 17:52   ` Joe Perches
  2007-02-06 20:41     ` Ahmed S. Darwish
  0 siblings, 1 reply; 30+ messages in thread
From: Joe Perches @ 2007-02-06 17:52 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
> 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/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index d22c022..3804591 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -1456,7 +1456,7 @@ static struct procfsentries {
>  
>  static void __init proc_init(void)
>  {
> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
> +    int nelem = ARRAY_SIZE(procfsentries);
>      int i;
>  
>      for (i=0; i < nelem; i++) {

For these patches, perhaps you can eliminate the temporary
variable and change the loop to the more common form of

	for (i = 0; i < ARRAY_SIZE(array); i++) {



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

* Re: [PATCH 2.6.20] infinband: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:07 ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
@ 2007-02-06 18:57   ` Roland Dreier
  0 siblings, 0 replies; 30+ messages in thread
From: Roland Dreier @ 2007-02-06 18:57 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: linux-kernel, openib-general

Thanks, queued in my tree for 2.6.21

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 17:52   ` Joe Perches
@ 2007-02-06 20:41     ` Ahmed S. Darwish
  2007-02-06 21:18       ` Philippe De Muyter
  0 siblings, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-06 20:41 UTC (permalink / raw)
  To: Joe Perches; +Cc: kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:
> On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
> > A patch to use ARRAY_SIZE macro already defined in kernel.h
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
[...]
> > -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
> > +    int nelem = ARRAY_SIZE(procfsentries);
> >      int i;
> >  
> >      for (i=0; i < nelem; i++) {
> 
> For these patches, perhaps you can eliminate the temporary
> variable and change the loop to the more common form of
> 
> 	for (i = 0; i < ARRAY_SIZE(array); i++) {

Thanks, I think it's better too. 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/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c022..87fe89c 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1456,10 +1456,9 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=0; i < nelem; i++) {
+    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
         struct procfsentries *p = procfsentries + i;
 	p->procent = create_proc_entry(p->name, p->mode, NULL);
 	if (p->procent) p->procent->read_proc = p->read_proc;
@@ -1468,10 +1467,9 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=nelem-1; i >= 0; i--) {
+    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
         struct procfsentries *p = procfsentries + i;
 	if (p->procent) {
 	   remove_proc_entry(p->name, NULL);
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c..cff5d1e 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,10 +2218,9 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=0; i < nelem; i++) {
+    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
         struct procfsentries *p = procfsentries + i;
 	p->procent = create_proc_entry(p->name, p->mode, NULL);
 	if (p->procent) p->procent->read_proc = p->read_proc;
@@ -2230,10 +2229,9 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=nelem-1; i >= 0; i--) {
+    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
         struct procfsentries *p = procfsentries + i;
 	if (p->procent) {
 	   remove_proc_entry(p->name, NULL);


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

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 20:41     ` Ahmed S. Darwish
@ 2007-02-06 21:18       ` Philippe De Muyter
  2007-02-07 19:41         ` Ahmed S. Darwish
  2007-02-08 15:53         ` Bill Davidsen
  0 siblings, 2 replies; 30+ messages in thread
From: Philippe De Muyter @ 2007-02-06 21:18 UTC (permalink / raw)
  To: Ahmed S. Darwish
  Cc: Joe Perches, kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
> On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:
> > On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
> > > A patch to use ARRAY_SIZE macro already defined in kernel.h
> > > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> [...]
> > > -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
> > > +    int nelem = ARRAY_SIZE(procfsentries);
> > >      int i;
> > >  
> > >      for (i=0; i < nelem; i++) {
> > 
> > For these patches, perhaps you can eliminate the temporary
> > variable and change the loop to the more common form of
> > 
> > 	for (i = 0; i < ARRAY_SIZE(array); i++) {
> 
> Thanks, I think it's better too. 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/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index d22c022..87fe89c 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -1456,10 +1456,9 @@ static struct procfsentries {
>  
>  static void __init proc_init(void)
>  {
> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>      int i;
>  
> -    for (i=0; i < nelem; i++) {
> +    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
>          struct procfsentries *p = procfsentries + i;
>  	p->procent = create_proc_entry(p->name, p->mode, NULL);
>  	if (p->procent) p->procent->read_proc = p->read_proc;
> @@ -1468,10 +1467,9 @@ static void __init proc_init(void)
>  
>  static void __exit proc_exit(void)
>  {
> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>      int i;
>  
> -    for (i=nelem-1; i >= 0; i--) {
> +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {

I would write such decrementing loops as :

       for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {

Long time ago, that produced better code.  I did not check recently though.

>          struct procfsentries *p = procfsentries + i;
>  	if (p->procent) {
>  	   remove_proc_entry(p->name, NULL);
> diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
> index c4d438c..cff5d1e 100644
> --- a/drivers/isdn/capi/capidrv.c
> +++ b/drivers/isdn/capi/capidrv.c
> @@ -2218,10 +2218,9 @@ static struct procfsentries {
>  
>  static void __init proc_init(void)
>  {
> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>      int i;
>  
> -    for (i=0; i < nelem; i++) {
> +    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
>          struct procfsentries *p = procfsentries + i;
>  	p->procent = create_proc_entry(p->name, p->mode, NULL);
>  	if (p->procent) p->procent->read_proc = p->read_proc;
> @@ -2230,10 +2229,9 @@ static void __init proc_init(void)
>  
>  static void __exit proc_exit(void)
>  {
> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>      int i;
>  
> -    for (i=nelem-1; i >= 0; i--) {
> +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {

Same here

>          struct procfsentries *p = procfsentries + i;
>  	if (p->procent) {
>  	   remove_proc_entry(p->name, NULL);
> 
> 
Philippe

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

* Re: [PATCH 2.6.20] s390-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:07 ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
@ 2007-02-07  6:32   ` Cornelia Huck
  0 siblings, 0 replies; 30+ messages in thread
From: Cornelia Huck @ 2007-02-07  6:32 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: schwidefsky, linux-kernel, linux-390

On Tue, 6 Feb 2007 18:07:44 +0200,
"Ahmed S. Darwish" <darwish.07@gmail.com> wrote:

> Hi all,
> 
> A patch to use ARRAY_SIZE macro already defined in kernel.h
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> ---
> Not compile tested due to (ofcourse ;)) missing hardware.
> 
> diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
> index f172759..997f468 100644
> --- a/drivers/s390/cio/device_id.c
> +++ b/drivers/s390/cio/device_id.c
> @@ -11,6 +11,7 @@
> 
>  #include <linux/module.h>
>  #include <linux/init.h>
> +#include <linux/kernel.h>
> 
>  #include <asm/ccwdev.h>
>  #include <asm/delay.h>
> @@ -138,7 +139,7 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
>  		ps->cu_model = 0x60;
>  		return;
>  	}
> -	for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
> +	for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
>  		if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
>  		    diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
>  			ps->cu_type = vm_devices[i].cu_type;
> 
> 

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>

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

* Re: [PATCH 2.6.20] rcutorture: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:08 ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
@ 2007-02-07 18:29   ` Josh Triplett
  0 siblings, 0 replies; 30+ messages in thread
From: Josh Triplett @ 2007-02-07 18:29 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

Ahmed S. Darwish wrote:
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>

Thanks.  I've applied to my local tree, and I'll push it out shortly along
with some other cleanup patches.

- Josh Triplett


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 21:18       ` Philippe De Muyter
@ 2007-02-07 19:41         ` Ahmed S. Darwish
  2007-02-07 21:02           ` Philippe De Muyter
  2007-02-08 15:53         ` Bill Davidsen
  1 sibling, 1 reply; 30+ messages in thread
From: Ahmed S. Darwish @ 2007-02-07 19:41 UTC (permalink / raw)
  To: Philippe De Muyter
  Cc: Joe Perches, kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, Feb 06, 2007 at 10:18:14PM +0100, Philippe De Muyter wrote:
> On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
> >  
> > -    for (i=nelem-1; i >= 0; i--) {
> > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> 
> I would write such decrementing loops as :
> 
>        for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {
> 
> Long time ago, that produced better code.  I did not check recently though.
[...]
> > -    for (i=nelem-1; i >= 0; i--) {
> > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> 
> Same here

Hi Philippe,

Won't this hurt readability ?. I'm not a gcc guru anyway to have an
opinion on such stuff :).

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

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-07 19:41         ` Ahmed S. Darwish
@ 2007-02-07 21:02           ` Philippe De Muyter
  0 siblings, 0 replies; 30+ messages in thread
From: Philippe De Muyter @ 2007-02-07 21:02 UTC (permalink / raw)
  To: Ahmed S. Darwish
  Cc: Joe Perches, kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Wed, Feb 07, 2007 at 09:41:00PM +0200, Ahmed S. Darwish wrote:
> On Tue, Feb 06, 2007 at 10:18:14PM +0100, Philippe De Muyter wrote:
> > On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
> > >  
> > > -    for (i=nelem-1; i >= 0; i--) {
> > > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> > 
> > I would write such decrementing loops as :
> > 
> >        for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {
> > 
> > Long time ago, that produced better code.  I did not check recently though.
> [...]
> > > -    for (i=nelem-1; i >= 0; i--) {
> > > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> > 
> > Same here
> 
> Hi Philippe,
> 
> Won't this hurt readability ?. I'm not a gcc guru anyway to have an
> opinion on such stuff :).

Personaly, I find it more readable, but that's a question of habit or a
matter of taste.

Philippe

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 21:18       ` Philippe De Muyter
  2007-02-07 19:41         ` Ahmed S. Darwish
@ 2007-02-08 15:53         ` Bill Davidsen
  2007-02-08 16:02           ` Kai Germaschewski
  1 sibling, 1 reply; 30+ messages in thread
From: Bill Davidsen @ 2007-02-08 15:53 UTC (permalink / raw)
  To: Philippe De Muyter
  Cc: Ahmed S. Darwish, Joe Perches, kkeil, kai.germaschewski,
	linux-kernel, isdn4linux

Philippe De Muyter wrote:
> On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
>> On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:
>>> On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
>>>> A patch to use ARRAY_SIZE macro already defined in kernel.h
>>>> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
>> [...]
>>>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>>> +    int nelem = ARRAY_SIZE(procfsentries);
>>>>      int i;
>>>>  
>>>>      for (i=0; i < nelem; i++) {
>>> For these patches, perhaps you can eliminate the temporary
>>> variable and change the loop to the more common form of
>>>
>>> 	for (i = 0; i < ARRAY_SIZE(array); i++) {
>> Thanks, I think it's better too. 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/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
>> index d22c022..87fe89c 100644
>> --- a/drivers/isdn/capi/capi.c
>> +++ b/drivers/isdn/capi/capi.c
>> @@ -1456,10 +1456,9 @@ static struct procfsentries {
>>  
>>  static void __init proc_init(void)
>>  {
>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>      int i;
>>  
>> -    for (i=0; i < nelem; i++) {
>> +    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
>>          struct procfsentries *p = procfsentries + i;
>>  	p->procent = create_proc_entry(p->name, p->mode, NULL);
>>  	if (p->procent) p->procent->read_proc = p->read_proc;
>> @@ -1468,10 +1467,9 @@ static void __init proc_init(void)
>>  
>>  static void __exit proc_exit(void)
>>  {
>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>      int i;
>>  
>> -    for (i=nelem-1; i >= 0; i--) {
>> +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> 
> I would write such decrementing loops as :
> 
>        for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {
> 
> Long time ago, that produced better code.  I did not check recently though.

Why would you write "--i >= 0" instead of just "i--"? The size of an 
array can't be negative.

-- 
Bill Davidsen <davidsen@tmr.com>
   "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot

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

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-08 15:53         ` Bill Davidsen
@ 2007-02-08 16:02           ` Kai Germaschewski
  0 siblings, 0 replies; 30+ messages in thread
From: Kai Germaschewski @ 2007-02-08 16:02 UTC (permalink / raw)
  To: Bill Davidsen
  Cc: Philippe De Muyter, Ahmed S. Darwish, Joe Perches, kkeil,
	kai.germaschewski, linux-kernel, isdn4linux

Bill Davidsen wrote:
> Philippe De Muyter wrote:
>> On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
>>> On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:
>>>> On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
>>>>> A patch to use ARRAY_SIZE macro already defined in kernel.h
>>>>> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
>>> [...]
>>>>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>>>> +    int nelem = ARRAY_SIZE(procfsentries);
>>>>>      int i;
>>>>>  
>>>>>      for (i=0; i < nelem; i++) {
>>>> For these patches, perhaps you can eliminate the temporary
>>>> variable and change the loop to the more common form of
>>>>
>>>>     for (i = 0; i < ARRAY_SIZE(array); i++) {
>>> Thanks, I think it's better too. 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/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
>>> index d22c022..87fe89c 100644
>>> --- a/drivers/isdn/capi/capi.c
>>> +++ b/drivers/isdn/capi/capi.c
>>> @@ -1456,10 +1456,9 @@ static struct procfsentries {
>>>  
>>>  static void __init proc_init(void)
>>>  {
>>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>>      int i;
>>>  
>>> -    for (i=0; i < nelem; i++) {
>>> +    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
>>>          struct procfsentries *p = procfsentries + i;
>>>      p->procent = create_proc_entry(p->name, p->mode, NULL);
>>>      if (p->procent) p->procent->read_proc = p->read_proc;
>>> @@ -1468,10 +1467,9 @@ static void __init proc_init(void)
>>>  
>>>  static void __exit proc_exit(void)
>>>  {
>>> -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
>>>      int i;
>>>  
>>> -    for (i=nelem-1; i >= 0; i--) {
>>> +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
>>
>> I would write such decrementing loops as :
>>
>>        for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {
>>
>> Long time ago, that produced better code.  I did not check recently
>> though.
>
> Why would you write "--i >= 0" instead of just "i--"? The size of an
> array can't be negative.
>
In my opinion, the first way of writing it is the way to go. I've not
seen it put like the 2nd or 3rd way anywhere in the kernel (of course I
haven't read all of the code), and while it's correct, it's less
readable. I don't think gcc would generate different code between
variant 1 and 2, and anyway, this is called once at module init/exit
time, so whether you save 10 cycles there or not is totally insignificant.

--Kai

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

end of thread, other threads:[~2007-02-08 16:35 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
2007-02-06 16:03 ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-06 16:03 ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
2007-02-06 16:56   ` Dor Laor
2007-02-06 16:56     ` Dor Laor
2007-02-06 16:04 ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
2007-02-06 16:04 ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
2007-02-06 17:52   ` Joe Perches
2007-02-06 20:41     ` Ahmed S. Darwish
2007-02-06 21:18       ` Philippe De Muyter
2007-02-07 19:41         ` Ahmed S. Darwish
2007-02-07 21:02           ` Philippe De Muyter
2007-02-08 15:53         ` Bill Davidsen
2007-02-08 16:02           ` Kai Germaschewski
2007-02-06 16:05 ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
2007-02-06 16:05 ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
2007-02-06 16:06 ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
2007-02-06 16:06 ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
2007-02-06 16:07 ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
2007-02-06 18:57   ` Roland Dreier
2007-02-06 16:07 ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
2007-02-07  6:32   ` Cornelia Huck
2007-02-06 16:08 ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
2007-02-07 18:29   ` Josh Triplett
2007-02-06 16:08 ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
2007-02-06 16:08 ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
2007-02-06 16:09 ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
2007-02-06 16:09 ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
2007-02-06 16:19   ` Evgeniy Polyakov
2007-02-06 16:10 ` [PATCH 2.6.20] drm: " 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.