Commit e8c96f8c29d89af0c13dc2819a9a00575846ca18

Authored by Tobias Klauser
Committed by Linus Torvalds
1 parent b5029622ac

[PATCH] fs: Use ARRAY_SIZE macro

Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove a
duplicate of ARRAY_SIZE.  Some trailing whitespaces are also deleted.

Signed-off-by: Tobias Klauser <tklauser@nuerscht.ch>
Cc: David Howells <dhowells@redhat.com>
Cc: Dave Kleikamp <shaggy@austin.ibm.com>
Acked-by: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: Chris Mason <mason@suse.com>
Cc: Jeff Mahoney <jeffm@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Nathan Scott <nathans@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 23 changed files with 40 additions and 51 deletions Side-by-side Diff

... ... @@ -94,7 +94,7 @@
94 94 .error_func = afscm_error,
95 95 .aemap_func = afscm_aemap,
96 96 .ops_begin = &AFSCM_ops[0],
97   - .ops_end = &AFSCM_ops[sizeof(AFSCM_ops) / sizeof(AFSCM_ops[0])],
  97 + .ops_end = &AFSCM_ops[ARRAY_SIZE(AFSCM_ops)],
98 98 };
99 99  
100 100 static DECLARE_COMPLETION(kafscmd_alive);
... ... @@ -1522,9 +1522,8 @@
1522 1522 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1523 1523 };
1524 1524  
1525   -#define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
  1525 +#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
1526 1526  
1527   -
1528 1527 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1529 1528 {
1530 1529 struct atm_iobuf __user *iobuf;
... ... @@ -1824,7 +1823,7 @@
1824 1823 { FDWERRORGET32, FDWERRORGET }
1825 1824 };
1826 1825  
1827   -#define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
  1826 +#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
1828 1827  
1829 1828 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1830 1829 {
... ... @@ -111,7 +111,7 @@
111 111 { "loglevel", loglevel_read, loglevel_write }
112 112 #endif
113 113 };
114   -#define NPROCENT (sizeof(Entries)/sizeof(Entries[0]))
  114 +#define NPROCENT ARRAY_SIZE(Entries)
115 115  
116 116 void jfs_proc_init(void)
117 117 {
... ... @@ -224,8 +224,8 @@
224 224 };
225 225  
226 226 static struct rpc_version nsm_version1 = {
227   - .number = 1,
228   - .nrprocs = sizeof(nsm_procedures)/sizeof(nsm_procedures[0]),
  227 + .number = 1,
  228 + .nrprocs = ARRAY_SIZE(nsm_procedures),
229 229 .procs = nsm_procedures
230 230 };
231 231  
... ... @@ -238,7 +238,7 @@
238 238 static struct rpc_program nsm_program = {
239 239 .name = "statd",
240 240 .number = SM_PROGRAM,
241   - .nrvers = sizeof(nsm_version)/sizeof(nsm_version[0]),
  241 + .nrvers = ARRAY_SIZE(nsm_version),
242 242 .version = nsm_version,
243 243 .stats = &nsm_stats
244 244 };
... ... @@ -509,7 +509,7 @@
509 509  
510 510 static struct svc_stat nlmsvc_stats;
511 511  
512   -#define NLM_NRVERS (sizeof(nlmsvc_version)/sizeof(nlmsvc_version[0]))
  512 +#define NLM_NRVERS ARRAY_SIZE(nlmsvc_version)
513 513 static struct svc_program nlmsvc_program = {
514 514 .pg_prog = NLM_PROGRAM, /* program number */
515 515 .pg_nvers = NLM_NRVERS, /* number of entries in nlmsvc_version */
... ... @@ -599,7 +599,7 @@
599 599 struct rpc_program nlm_program = {
600 600 .name = "lockd",
601 601 .number = NLM_PROGRAM,
602   - .nrvers = sizeof(nlm_versions) / sizeof(nlm_versions[0]),
  602 + .nrvers = ARRAY_SIZE(nlm_versions),
603 603 .version = nlm_versions,
604 604 .stats = &nlm_stats,
605 605 };
... ... @@ -103,7 +103,7 @@
103 103 static struct rpc_program nfs_program = {
104 104 .name = "nfs",
105 105 .number = NFS_PROGRAM,
106   - .nrvers = sizeof(nfs_version) / sizeof(nfs_version[0]),
  106 + .nrvers = ARRAY_SIZE(nfs_version),
107 107 .version = nfs_version,
108 108 .stats = &nfs_rpcstat,
109 109 .pipe_dir_name = "/nfs",
... ... @@ -118,7 +118,7 @@
118 118 struct rpc_program nfsacl_program = {
119 119 .name = "nfsacl",
120 120 .number = NFS_ACL_PROGRAM,
121   - .nrvers = sizeof(nfsacl_version) / sizeof(nfsacl_version[0]),
  121 + .nrvers = ARRAY_SIZE(nfsacl_version),
122 122 .version = nfsacl_version,
123 123 .stats = &nfsacl_rpcstat,
124 124 };
... ... @@ -174,7 +174,7 @@
174 174 static struct rpc_program mnt_program = {
175 175 .name = "mount",
176 176 .number = NFS_MNT_PROGRAM,
177   - .nrvers = sizeof(mnt_version)/sizeof(mnt_version[0]),
  177 + .nrvers = ARRAY_SIZE(mnt_version),
178 178 .version = mnt_version,
179 179 .stats = &mnt_stats,
180 180 };
... ... @@ -704,7 +704,7 @@
704 704  
705 705 struct rpc_version nfs_version2 = {
706 706 .number = 2,
707   - .nrprocs = sizeof(nfs_procedures)/sizeof(nfs_procedures[0]),
  707 + .nrprocs = ARRAY_SIZE(nfs_procedures),
708 708 .procs = nfs_procedures
709 709 };
... ... @@ -1138,7 +1138,7 @@
1138 1138  
1139 1139 struct rpc_version nfs_version3 = {
1140 1140 .number = 3,
1141   - .nrprocs = sizeof(nfs3_procedures)/sizeof(nfs3_procedures[0]),
  1141 + .nrprocs = ARRAY_SIZE(nfs3_procedures),
1142 1142 .procs = nfs3_procedures
1143 1143 };
1144 1144  
... ... @@ -4384,7 +4384,7 @@
4384 4384  
4385 4385 struct rpc_version nfs_version4 = {
4386 4386 .number = 4,
4387   - .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
  4387 + .nrprocs = ARRAY_SIZE(nfs4_procedures),
4388 4388 .procs = nfs4_procedures
4389 4389 };
4390 4390  
... ... @@ -101,7 +101,7 @@
101 101 if (version != NFSCTL_VERSION)
102 102 return -EINVAL;
103 103  
104   - if (cmd < 0 || cmd >= sizeof(map)/sizeof(map[0]) || !map[cmd].name)
  104 + if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
105 105 return -EINVAL;
106 106  
107 107 file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
... ... @@ -907,7 +907,7 @@
907 907 {
908 908 int i;
909 909  
910   - for (i=0; i < sizeof(s2t_map) / sizeof(*s2t_map); i++) {
  910 + for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
911 911 if (s2t_map[i].stringlen == len &&
912 912 0 == memcmp(s2t_map[i].string, p, len))
913 913 return s2t_map[i].type;
... ... @@ -920,7 +920,7 @@
920 920 {
921 921 int i;
922 922  
923   - for (i=0; i < sizeof(s2t_map) / sizeof(*s2t_map); i++) {
  923 + for (i = 0; i < ARRAY_SIZE(s2t_map); i++) {
924 924 if (s2t_map[i].type == who) {
925 925 memcpy(p, s2t_map[i].string, s2t_map[i].stringlen);
926 926 return s2t_map[i].stringlen;
fs/nfsd/nfs4callback.c
... ... @@ -335,7 +335,7 @@
335 335  
336 336 static struct rpc_version nfs_cb_version4 = {
337 337 .number = 1,
338   - .nrprocs = sizeof(nfs4_cb_procedures)/sizeof(nfs4_cb_procedures[0]),
  338 + .nrprocs = ARRAY_SIZE(nfs4_cb_procedures),
339 339 .procs = nfs4_cb_procedures
340 340 };
341 341  
... ... @@ -411,7 +411,7 @@
411 411 /* Initialize rpc_program */
412 412 program->name = "nfs4_cb";
413 413 program->number = cb->cb_prog;
414   - program->nrvers = sizeof(nfs_cb_version)/sizeof(nfs_cb_version[0]);
  414 + program->nrvers = ARRAY_SIZE(nfs_cb_version);
415 415 program->version = nfs_cb_version;
416 416 program->stats = stat;
417 417  
... ... @@ -992,7 +992,7 @@
992 992 if (argp->opcnt > 100)
993 993 goto xdr_error;
994 994  
995   - if (argp->opcnt > sizeof(argp->iops)/sizeof(argp->iops[0])) {
  995 + if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
996 996 argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
997 997 if (!argp->ops) {
998 998 argp->ops = argp->iops;
... ... @@ -105,7 +105,7 @@
105 105 char *data;
106 106 ssize_t rv;
107 107  
108   - if (ino >= sizeof(write_op)/sizeof(write_op[0]) || !write_op[ino])
  108 + if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
109 109 return -EINVAL;
110 110  
111 111 data = simple_transaction_get(file, buf, size);
... ... @@ -72,7 +72,7 @@
72 72 };
73 73  
74 74 #define NFSD_ACL_MINVERS 2
75   -#define NFSD_ACL_NRVERS (sizeof(nfsd_acl_version)/sizeof(nfsd_acl_version[0]))
  75 +#define NFSD_ACL_NRVERS ARRAY_SIZE(nfsd_acl_version)
76 76 static struct svc_version *nfsd_acl_versions[NFSD_ACL_NRVERS];
77 77  
78 78 static struct svc_program nfsd_acl_program = {
... ... @@ -101,7 +101,7 @@
101 101 };
102 102  
103 103 #define NFSD_MINVERS 2
104   -#define NFSD_NRVERS (sizeof(nfsd_version)/sizeof(nfsd_version[0]))
  104 +#define NFSD_NRVERS ARRAY_SIZE(nfsd_version)
105 105 static struct svc_version *nfsd_versions[NFSD_NRVERS];
106 106  
107 107 struct svc_program nfsd_program = {
... ... @@ -268,8 +268,6 @@
268 268 {0xFC, 0x4B},
269 269 };
270 270  
271   -#define MAP_ELEMENT_OF(map) (sizeof(map) / sizeof(map[0]))
272   -
273 271 static inline int sjisibm2euc(unsigned char *euc, const unsigned char sjis_hi,
274 272 const unsigned char sjis_lo);
275 273 static inline int euc2sjisibm_jisx0212(unsigned char *sjis, const unsigned char euc_hi,
... ... @@ -310,7 +308,7 @@
310 308 unsigned short euc;
311 309  
312 310 min_index = 0;
313   - max_index = MAP_ELEMENT_OF(euc2sjisibm_jisx0212_map) - 1;
  311 + max_index = ARRAY_SIZE(euc2sjisibm_jisx0212_map) - 1;
314 312 euc = (euc_hi << 8) | euc_lo;
315 313  
316 314 while (min_index <= max_index) {
... ... @@ -339,7 +337,7 @@
339 337 else
340 338 index = ((euc_hi << 8) | euc_lo) - 0xF4A1 + 12;
341 339  
342   - if ((index < 0) || (index >= MAP_ELEMENT_OF(euc2sjisibm_g3upper_map)))
  340 + if ((index < 0) || (index >= ARRAY_SIZE(euc2sjisibm_g3upper_map)))
343 341 return 0;
344 342  
345 343 sjis[0] = euc2sjisibm_g3upper_map[index][0];
fs/reiserfs/prints.c
... ... @@ -601,8 +601,7 @@
601 601 tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
602 602 tb->tb_path->pos_in_item);
603 603  
604   - for (h = 0; h < sizeof(tb->insert_size) / sizeof(tb->insert_size[0]);
605   - h++) {
  604 + for (h = 0; h < ARRAY_SIZE(tb->insert_size); h++) {
606 605 if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
607 606 tb->tb_path->path_length
608 607 && PATH_H_PATH_OFFSET(tb->tb_path,
609 608  
... ... @@ -658,15 +657,13 @@
658 657  
659 658 /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
660 659 h = 0;
661   - for (i = 0; i < sizeof(tb->FEB) / sizeof(tb->FEB[0]); i++)
  660 + for (i = 0; i < ARRAY_SIZE(tb->FEB); i++)
662 661 sprintf(print_tb_buf + strlen(print_tb_buf),
663 662 "%p (%llu %d)%s", tb->FEB[i],
664 663 tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
665 664 b_blocknr : 0ULL,
666 665 tb->FEB[i] ? atomic_read(&(tb->FEB[i]->b_count)) : 0,
667   - (i ==
668   - sizeof(tb->FEB) / sizeof(tb->FEB[0]) -
669   - 1) ? "\n" : ", ");
  666 + (i == ARRAY_SIZE(tb->FEB) - 1) ? "\n" : ", ");
670 667  
671 668 sprintf(print_tb_buf + strlen(print_tb_buf),
672 669 "======================== the end ====================================\n");
... ... @@ -377,10 +377,10 @@
377 377 sbi->s_sb = sb;
378 378 sbi->s_block_base = 0;
379 379 sb->s_fs_info = sbi;
380   -
  380 +
381 381 sb_set_blocksize(sb, BLOCK_SIZE);
382 382  
383   - for (i = 0; i < sizeof(flavours)/sizeof(flavours[0]) && !size; i++) {
  383 + for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) {
384 384 brelse(bh);
385 385 bh = sb_bread(sb, flavours[i].block);
386 386 if (!bh)
... ... @@ -660,8 +660,7 @@
660 660 * lastblock
661 661 * however, if the disc isn't closed, it could be 512 */
662 662  
663   - for (i=0; (!lastblock && i<sizeof(last)/sizeof(int)); i++)
664   - {
  663 + for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
665 664 if (last[i] < 0 || !(bh = sb_bread(sb, last[i])))
666 665 {
667 666 ident = location = 0;
... ... @@ -672,7 +671,7 @@
672 671 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
673 672 udf_release_data(bh);
674 673 }
675   -
  674 +
676 675 if (ident == TAG_IDENT_AVDP)
677 676 {
678 677 if (location == last[i] - UDF_SB_SESSION(sb))
... ... @@ -753,8 +752,7 @@
753 752 }
754 753 }
755 754  
756   - for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
757   - {
  755 + for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
758 756 if (UDF_SB_ANCHOR(sb)[i])
759 757 {
760 758 if (!(bh = udf_read_tagged(sb,
... ... @@ -1313,8 +1311,7 @@
1313 1311 if (!sb)
1314 1312 return 1;
1315 1313  
1316   - for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
1317   - {
  1314 + for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
1318 1315 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1319 1316 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
1320 1317 {
... ... @@ -1325,7 +1322,7 @@
1325 1322 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength );
1326 1323 main_e = main_e >> sb->s_blocksize_bits;
1327 1324 main_e += main_s;
1328   -
  1325 +
1329 1326 /* Locate the reserve sequence */
1330 1327 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1331 1328 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1332 1329  
... ... @@ -1344,12 +1341,10 @@
1344 1341 }
1345 1342 }
1346 1343  
1347   - if (i == sizeof(UDF_SB_ANCHOR(sb))/sizeof(int))
1348   - {
  1344 + if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
1349 1345 udf_debug("No Anchor block found\n");
1350 1346 return 1;
1351   - }
1352   - else
  1347 + } else
1353 1348 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1354 1349  
1355 1350 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
fs/xfs/linux-2.6/xfs_stats.c
... ... @@ -56,7 +56,7 @@
56 56 };
57 57  
58 58 /* Loop over all stats groups */
59   - for (i=j=len = 0; i < sizeof(xstats)/sizeof(struct xstats_entry); i++) {
  59 + for (i=j=len = 0; i < ARRAY_SIZE(xstats); i++) {
60 60 len += sprintf(buffer + len, xstats[i].desc);
61 61 /* inner loop does each group */
62 62 while (j < xstats[i].endpoint) {
fs/xfs/xfs_vnodeops.c
... ... @@ -1335,7 +1335,7 @@
1335 1335 */
1336 1336 done = 0;
1337 1337 XFS_BMAP_INIT(&free_list, &first_block);
1338   - nmaps = sizeof(mval) / sizeof(mval[0]);
  1338 + nmaps = ARRAY_SIZE(mval);
1339 1339 if ((error = xfs_bmapi(tp, ip, 0, XFS_B_TO_FSB(mp, size),
1340 1340 XFS_BMAPI_METADATA, &first_block, 0, mval, &nmaps,
1341 1341 &free_list)))