Skip to content

Commit 25c8716

Browse files
tklauserLinus Torvalds
authored andcommitted
[PATCH] arch/alpha: Use ARRAY_SIZE macro
Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove a duplicate of the macro. Also remove some trailing whitespaces and needless braces. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent c8e5429 commit 25c8716

5 files changed

Lines changed: 34 additions & 38 deletions

File tree

‎arch/alpha/kernel/err_ev7.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,14 @@ ev7_process_pal_subpacket(struct el_subpacket *header)
274274
struct el_subpacket_handler ev7_pal_subpacket_handler =
275275
SUBPACKET_HANDLER_INIT(EL_CLASS__PAL, ev7_process_pal_subpacket);
276276

277-
void
277+
void
278278
ev7_register_error_handlers(void)
279279
{
280280
int i;
281281

282-
for(i = 0;
283-
i<sizeof(el_ev7_pal_annotations)/sizeof(el_ev7_pal_annotations[1]);
284-
i++) {
282+
for (i = 0; i < ARRAY_SIZE(el_ev7_pal_annotations); i++)
285283
cdl_register_subpacket_annotation(&el_ev7_pal_annotations[i]);
286-
}
284+
287285
cdl_register_subpacket_handler(&ev7_pal_subpacket_handler);
288286
}
289287

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,12 @@ osf_sysinfo(int command, char __user *buf, long count)
623623
long len, err = -EINVAL;
624624

625625
offset = command-1;
626-
if (offset >= sizeof(sysinfo_table)/sizeof(char *)) {
626+
if (offset >= ARRAY_SIZE(sysinfo_table)) {
627627
/* Digital UNIX has a few unpublished interfaces here */
628628
printk("sysinfo(%d)", command);
629629
goto out;
630630
}
631-
631+
632632
down_read(&uts_sem);
633633
res = sysinfo_table[offset];
634634
len = strlen(res)+1;

‎arch/alpha/kernel/setup.c‎

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ struct alpha_machine_vector alpha_mv;
114114
int alpha_using_srm;
115115
#endif
116116

117-
#define N(a) (sizeof(a)/sizeof(a[0]))
118-
119117
static struct alpha_machine_vector *get_sysvec(unsigned long, unsigned long,
120118
unsigned long);
121119
static struct alpha_machine_vector *get_sysvec_byname(const char *);
@@ -240,7 +238,7 @@ reserve_std_resources(void)
240238
standard_io_resources[0].start = RTC_PORT(0);
241239
standard_io_resources[0].end = RTC_PORT(0) + 0x10;
242240

243-
for (i = 0; i < N(standard_io_resources); ++i)
241+
for (i = 0; i < ARRAY_SIZE(standard_io_resources); ++i)
244242
request_resource(io, standard_io_resources+i);
245243
}
246244

@@ -918,13 +916,13 @@ get_sysvec(unsigned long type, unsigned long variation, unsigned long cpu)
918916

919917
/* Search the system tables first... */
920918
vec = NULL;
921-
if (type < N(systype_vecs)) {
919+
if (type < ARRAY_SIZE(systype_vecs)) {
922920
vec = systype_vecs[type];
923921
} else if ((type > ST_API_BIAS) &&
924-
(type - ST_API_BIAS) < N(api_vecs)) {
922+
(type - ST_API_BIAS) < ARRAY_SIZE(api_vecs)) {
925923
vec = api_vecs[type - ST_API_BIAS];
926924
} else if ((type > ST_UNOFFICIAL_BIAS) &&
927-
(type - ST_UNOFFICIAL_BIAS) < N(unofficial_vecs)) {
925+
(type - ST_UNOFFICIAL_BIAS) < ARRAY_SIZE(unofficial_vecs)) {
928926
vec = unofficial_vecs[type - ST_UNOFFICIAL_BIAS];
929927
}
930928

@@ -938,36 +936,36 @@ get_sysvec(unsigned long type, unsigned long variation, unsigned long cpu)
938936

939937
switch (type) {
940938
case ST_DEC_ALCOR:
941-
if (member < N(alcor_indices))
939+
if (member < ARRAY_SIZE(alcor_indices))
942940
vec = alcor_vecs[alcor_indices[member]];
943941
break;
944942
case ST_DEC_EB164:
945-
if (member < N(eb164_indices))
943+
if (member < ARRAY_SIZE(eb164_indices))
946944
vec = eb164_vecs[eb164_indices[member]];
947945
/* PC164 may show as EB164 variation with EV56 CPU,
948946
but, since no true EB164 had anything but EV5... */
949947
if (vec == &eb164_mv && cpu == EV56_CPU)
950948
vec = &pc164_mv;
951949
break;
952950
case ST_DEC_EB64P:
953-
if (member < N(eb64p_indices))
951+
if (member < ARRAY_SIZE(eb64p_indices))
954952
vec = eb64p_vecs[eb64p_indices[member]];
955953
break;
956954
case ST_DEC_EB66:
957-
if (member < N(eb66_indices))
955+
if (member < ARRAY_SIZE(eb66_indices))
958956
vec = eb66_vecs[eb66_indices[member]];
959957
break;
960958
case ST_DEC_MARVEL:
961-
if (member < N(marvel_indices))
959+
if (member < ARRAY_SIZE(marvel_indices))
962960
vec = marvel_vecs[marvel_indices[member]];
963961
break;
964962
case ST_DEC_TITAN:
965963
vec = titan_vecs[0]; /* default */
966-
if (member < N(titan_indices))
964+
if (member < ARRAY_SIZE(titan_indices))
967965
vec = titan_vecs[titan_indices[member]];
968966
break;
969967
case ST_DEC_TSUNAMI:
970-
if (member < N(tsunami_indices))
968+
if (member < ARRAY_SIZE(tsunami_indices))
971969
vec = tsunami_vecs[tsunami_indices[member]];
972970
break;
973971
case ST_DEC_1000:
@@ -1039,7 +1037,7 @@ get_sysvec_byname(const char *name)
10391037

10401038
size_t i;
10411039

1042-
for (i = 0; i < N(all_vecs); ++i) {
1040+
for (i = 0; i < ARRAY_SIZE(all_vecs); ++i) {
10431041
struct alpha_machine_vector *mv = all_vecs[i];
10441042
if (strcasecmp(mv->vector_name, name) == 0)
10451043
return mv;
@@ -1055,13 +1053,13 @@ get_sysnames(unsigned long type, unsigned long variation, unsigned long cpu,
10551053

10561054
/* If not in the tables, make it UNKNOWN,
10571055
else set type name to family */
1058-
if (type < N(systype_names)) {
1056+
if (type < ARRAY_SIZE(systype_names)) {
10591057
*type_name = systype_names[type];
10601058
} else if ((type > ST_API_BIAS) &&
1061-
(type - ST_API_BIAS) < N(api_names)) {
1059+
(type - ST_API_BIAS) < ARRAY_SIZE(api_names)) {
10621060
*type_name = api_names[type - ST_API_BIAS];
10631061
} else if ((type > ST_UNOFFICIAL_BIAS) &&
1064-
(type - ST_UNOFFICIAL_BIAS) < N(unofficial_names)) {
1062+
(type - ST_UNOFFICIAL_BIAS) < ARRAY_SIZE(unofficial_names)) {
10651063
*type_name = unofficial_names[type - ST_UNOFFICIAL_BIAS];
10661064
} else {
10671065
*type_name = sys_unknown;
@@ -1083,40 +1081,40 @@ get_sysnames(unsigned long type, unsigned long variation, unsigned long cpu,
10831081
default: /* default to variation "0" for now */
10841082
break;
10851083
case ST_DEC_EB164:
1086-
if (member < N(eb164_indices))
1084+
if (member < ARRAY_SIZE(eb164_indices))
10871085
*variation_name = eb164_names[eb164_indices[member]];
10881086
/* PC164 may show as EB164 variation, but with EV56 CPU,
10891087
so, since no true EB164 had anything but EV5... */
10901088
if (eb164_indices[member] == 0 && cpu == EV56_CPU)
10911089
*variation_name = eb164_names[1]; /* make it PC164 */
10921090
break;
10931091
case ST_DEC_ALCOR:
1094-
if (member < N(alcor_indices))
1092+
if (member < ARRAY_SIZE(alcor_indices))
10951093
*variation_name = alcor_names[alcor_indices[member]];
10961094
break;
10971095
case ST_DEC_EB64P:
1098-
if (member < N(eb64p_indices))
1096+
if (member < ARRAY_SIZE(eb64p_indices))
10991097
*variation_name = eb64p_names[eb64p_indices[member]];
11001098
break;
11011099
case ST_DEC_EB66:
1102-
if (member < N(eb66_indices))
1100+
if (member < ARRAY_SIZE(eb66_indices))
11031101
*variation_name = eb66_names[eb66_indices[member]];
11041102
break;
11051103
case ST_DEC_MARVEL:
1106-
if (member < N(marvel_indices))
1104+
if (member < ARRAY_SIZE(marvel_indices))
11071105
*variation_name = marvel_names[marvel_indices[member]];
11081106
break;
11091107
case ST_DEC_RAWHIDE:
1110-
if (member < N(rawhide_indices))
1108+
if (member < ARRAY_SIZE(rawhide_indices))
11111109
*variation_name = rawhide_names[rawhide_indices[member]];
11121110
break;
11131111
case ST_DEC_TITAN:
11141112
*variation_name = titan_names[0]; /* default */
1115-
if (member < N(titan_indices))
1113+
if (member < ARRAY_SIZE(titan_indices))
11161114
*variation_name = titan_names[titan_indices[member]];
11171115
break;
11181116
case ST_DEC_TSUNAMI:
1119-
if (member < N(tsunami_indices))
1117+
if (member < ARRAY_SIZE(tsunami_indices))
11201118
*variation_name = tsunami_names[tsunami_indices[member]];
11211119
break;
11221120
}
@@ -1211,7 +1209,7 @@ show_cpuinfo(struct seq_file *f, void *slot)
12111209

12121210
cpu_index = (unsigned) (cpu->type - 1);
12131211
cpu_name = "Unknown";
1214-
if (cpu_index < N(cpu_names))
1212+
if (cpu_index < ARRAY_SIZE(cpu_names))
12151213
cpu_name = cpu_names[cpu_index];
12161214

12171215
get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,

‎arch/alpha/kernel/sys_ruffian.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,16 @@ static unsigned long __init
182182
ruffian_get_bank_size(unsigned long offset)
183183
{
184184
unsigned long bank_addr, bank, ret = 0;
185-
185+
186186
/* Valid offsets are: 0x800, 0x840 and 0x880
187187
since Ruffian only uses three banks. */
188188
bank_addr = (unsigned long)PYXIS_MCR + offset;
189189
bank = *(vulp)bank_addr;
190-
190+
191191
/* Check BANK_ENABLE */
192192
if (bank & 0x01) {
193193
static unsigned long size[] __initdata = {
194-
0x40000000UL, /* 0x00, 1G */
194+
0x40000000UL, /* 0x00, 1G */
195195
0x20000000UL, /* 0x02, 512M */
196196
0x10000000UL, /* 0x04, 256M */
197197
0x08000000UL, /* 0x06, 128M */
@@ -203,7 +203,7 @@ ruffian_get_bank_size(unsigned long offset)
203203
};
204204

205205
bank = (bank & 0x1e) >> 1;
206-
if (bank < sizeof(size)/sizeof(*size))
206+
if (bank < ARRAY_SIZE(size))
207207
ret = size[bank];
208208
}
209209

‎arch/alpha/kernel/time.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ validate_cc_value(unsigned long cc)
233233
index = cpu->type & 0xffffffff;
234234

235235
/* If index out of bounds, no way to validate. */
236-
if (index >= sizeof(cpu_hz)/sizeof(cpu_hz[0]))
236+
if (index >= ARRAY_SIZE(cpu_hz))
237237
return cc;
238238

239239
/* If index contains no data, no way to validate. */

0 commit comments

Comments
 (0)