A series of patches to use ARRAY_SIZE macro
Subsystems (12)
PATCH 1/1 A series of patches to use ARRAY_SIZE macro
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,
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 DVB: Use ARRAY_SIZE macro when appropriate
Hi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
Patch is compile-tested.
drivers/media/dvb/bt8xx/dst.c +1 -1
@@ -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 [email protected] with this type in" ); use_dst_type =DST_TYPE_IS_SAT ;
drivers/media/dvb/bt8xx/dvb-bt8xx.c +2 -1
@@ -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 */
drivers/media/dvb/frontends/cx24110.c +2 -2
@@ -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); };
drivers/media/dvb/frontends/cx24123.c +3 -3
@@ -507,7 +507,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_paint 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 */
drivers/media/dvb/ttpci/av7110_ir.c +2 -1
@@ -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 );
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 KVM: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/kvm/kvm_svm.h +2 -1
@@ -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 4struct vcpu_svm {
drivers/kvm/svm.c +3 -2
@@ -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",
drivers/kvm/vmx.c +3 -3
@@ -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
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Dor Laor
AppliedRE: [PATCH 2.6.20] KVM: Use ARRAY_SIZE macro when appropriate
Quoted 6 lines
Hi all,
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>
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
PATCH 1/1 isdn-eicon: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
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(-)
drivers/isdn/hardware/eicon/debug.c +15 -15
@@ -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 ;
drivers/isdn/hardware/eicon/message.c +11 -12
@@ -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, PLCIPUT_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 )) {
drivers/isdn/hardware/eicon/platform.h +0 -4
@@ -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) \
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 isdn-capi: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
--- capi.c | 4 ++-- capidrv.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/isdn/capi/capi.c +2 -2
@@ -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--) {
drivers/isdn/capi/capidrv.c +2 -2
@@ -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--) {
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 8 lines · Ahmed S. Darwish
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>---
drivers/isdn/capi/capi.c +0
-0
drivers/isdn/capi/capi.c static struct procfsentries { · line 1462
Quoted 8 lines
drivers/isdn/capi/capi.c +1
-1@@ -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++) {Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 3 lines · Joe Perches
Quoted 2 lines · Ahmed S. Darwish
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>
[...]
Quoted 10 lines
Review
Quoted 5 lines
(quoted diff) +1
-1- 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.
---
drivers/isdn/capi/capi.c +2 -4
@@ -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 );
drivers/isdn/capi/capidrv.c +2 -4
@@ -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 );
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 39 lines · Ahmed S. Darwish
Quoted 3 lines · Joe Perches
Quoted 2 lines · Ahmed S. Darwish
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>[...]
Quoted 10 lines
drivers/isdn/capi/capi.c static struct procfsentries {
Quoted 5 lines
drivers/isdn/capi/capi.c +1
-1-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_SIZEmacro when appropriate.Signed-off-by Ahmed S. Darwish <[email protected]>---
drivers/isdn/capi/capi.c +1
-2@@ -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;
drivers/isdn/capi/capi.c static void __init proc_init(void) · line 1472
Quoted 8 lines
drivers/isdn/capi/capi.c +1
-2@@ -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.
Quoted 20 lines
drivers/isdn/capi/capi.c +0
-0struct procfsentries *p = procfsentries + i;if (p->procent) {remove_proc_entry (p->name,NULL );drivers/isdn/capi/capidrv.c +1
-2@@ -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;
drivers/isdn/capi/capidrv.c static void __init proc_init(void) · line 2234
Quoted 8 lines
drivers/isdn/capi/capidrv.c +1
-2@@ -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
drivers/isdn/capi/capidrv.c static void __init proc_init(void) · line 2237
Quoted 5 lines
drivers/isdn/capi/capidrv.c +0
-0struct procfsentries *p = procfsentries + i;if (p->procent) {remove_proc_entry (p->name,NULL );
Philippe
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 10 lines · Philippe De Muyter
Review
Quoted 3 lines · Ahmed S. Darwish
(quoted diff) +1
-1- 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.
[...]
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- 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 :).
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 15 lines · Ahmed S. Darwish
Quoted 10 lines · Philippe De Muyter
Review
Quoted 3 lines · Ahmed S. Darwish
(quoted diff) +1
-1- 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.
[...]
Quoted 3 lines
Quoted 2 lines
(quoted diff) +1
-1- for (i=nelem-1; i >= 0; i--) { + for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
Quoted 6 lines
Quoted 1 line
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
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
In reply to Philippe De MuyterQuoted 44 lines · Philippe De Muyter
Quoted 43 lines · Ahmed S. Darwish
Quoted 3 lines · Joe Perches
Quoted 2 lines · Ahmed S. Darwish
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>[...]
Quoted 9 lines
drivers/isdn/capi/capi.c static struct procfsentries {
Quoted 5 lines
drivers/isdn/capi/capi.c +1
-1-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_SIZEmacro when appropriate.Signed-off-by Ahmed S. Darwish <[email protected]>---
drivers/isdn/capi/capi.c +1
-3@@ -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;
Quoted 8 lines
drivers/isdn/capi/capi.c static void __init proc_init(void) · line 1472
Quoted 2 lines
drivers/isdn/capi/capi.c +1
-1-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.
Signature · 3 lines
Bill Davidsen <[email protected]> "We have more to fear from the bungling of the incompetent than from the machinations of the wicked." - from Slashdot
Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Quoted 50 lines · Bill Davidsen
Quoted 49 lines · Philippe De Muyter
Quoted 37 lines · Ahmed S. Darwish
Quoted 3 lines · Joe Perches
Quoted 2 lines · Ahmed S. Darwish
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>[...]
Quoted 9 lines
drivers/isdn/capi/capi.c static struct procfsentries {
Quoted 5 lines
drivers/isdn/capi/capi.c +1
-1-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_SIZEmacro when appropriate.Signed-off-by Ahmed S. Darwish <[email protected]>---
drivers/isdn/capi/capi.c +1
-2@@ -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;drivers/isdn/capi/capi.c static void __init proc_init(void) · line 1472
Quoted 8 lines
drivers/isdn/capi/capi.c +1
-2@@ -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 :
Quoted 8 lines
Quoted 4 lines
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
PATCH 1/2 OSS: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
[PATCH 1/2] compile-tested
[PATCH 2/2] couldn't be compile-tested (orphaned hardware ?)
sound/oss/es1371.c +2 -1
@@ -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_devicset_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); }
sound/oss/soundcard.c +3 -2
@@ -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 ;
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 2/2 OSS: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
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(-)
sound/oss/au1550_ac97.c +2 -2
@@ -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);
sound/oss/nec_vrc5477.c +2 -2
@@ -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);
sound/oss/swarm_cs4297a.c +2 -1
@@ -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); }
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 atm: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h for ATM drivers.
---
drivers/atm/he.c +1 -1
@@ -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 ); }
drivers/atm/idt77252.c +4 -4
@@ -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 ); }
drivers/atm/nicstarmac.c +3 -1
@@ -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]) );
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 drivers/md.c: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/md/md.c +3 -3
@@ -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
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 infinband: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/infiniband/core/device.c +2 -1
@@ -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);
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] infinband: Use ARRAY_SIZE macro when appropriate
Thanks, queued in my tree for 2.6.21
PATCH 1/1 s390-drivers: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
Not compile tested due to (ofcourse ;)) missing hardware.
drivers/s390/cio/device_id.c +2 -1
@@ -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;
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] s390-drivers: Use ARRAY_SIZE macro when appropriate
Quoted 23 lines · Ahmed S. Darwish
Hi all,
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>---
Not compile tested due to (ofcourse ;)) missing hardware.drivers/s390/cio/device_id.c +1
-0@@ -11,6 +11,7 @@#include <linux/module.h> #include <linux/init.h> +#include <linux/kernel.h> #include <asm/ccwdev.h> #include <asm/delay.h>
drivers/s390/cio/device_id.c VM_virtual_device_info (__u16 devno, struct senseid *ps) · line 145
Quoted 8 lines
drivers/s390/cio/device_id.c +1
-1@@ -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;
PATCH 1/1 rcutorture: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
kernel/rcutorture.c +1 -1
@@ -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);
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] rcutorture: Use ARRAY_SIZE macro when appropriate
Quoted 1 line · Ahmed S. Darwish
Signed-off-by Ahmed S. Darwish <[email protected]>
Thanks. I've applied to my local tree, and I'll push it out shortly along with some other cleanup patches.
- Josh Triplett
PATCH 1/1 intel-agp: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/char/agp/intel-agp.c +2 -1
@@ -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;
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 reiserfs: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
fs/reiserfs/do_balan.c +3 -2
@@ -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]))
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 toshiba-acpi: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/acpi/toshiba_acpi.c +1 -1
@@ -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;
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
PATCH 1/1 w1: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/w1/slaves/w1_therm.c +3 -3
@@ -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); }
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com
Re: [PATCH 2.6.20] w1: Use ARRAY_SIZE macro when appropriate
Quoted 5 lines · Ahmed S. Darwish
Hi all,
A patch to use
ARRAY_SIZEmacro already defined inkernel.hSigned-off-by Ahmed S. Darwish <[email protected]>
Your patch is corrent, thanks Ahmed.
Andrew, Greg will you pick it up, or should I resend it alone?
Signature · 1 line
Evgeniy Polyakov
PATCH 1/1 drm: Use ARRAY_SIZE macro when appropriate
In reply to Ahmed S. DarwishHi all,
A patch to use ARRAY_SIZE macro already defined in kernel.h
---
drivers/char/drm/drm_proc.c +1 -1
@@ -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.
Signature · 2 lines
Ahmed S. Darwish http://darwish-07.blogspot.com