Commit a3b18c71 authored by Andries E. Brouwer's avatar Andries E. Brouwer Committed by David S. Miller

[NET]: Use ARRAY_SIZE where appropriate.

parent 938a7aea
...@@ -620,13 +620,11 @@ static struct nf_hook_ops br_nf_ops[] = { ...@@ -620,13 +620,11 @@ static struct nf_hook_ops br_nf_ops[] = {
.priority = NF_IP_PRI_FIRST, }, .priority = NF_IP_PRI_FIRST, },
}; };
#define NUMHOOKS (sizeof(br_nf_ops)/sizeof(br_nf_ops[0]))
int br_netfilter_init(void) int br_netfilter_init(void)
{ {
int i; int i;
for (i = 0; i < NUMHOOKS; i++) { for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
int ret; int ret;
if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0) if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
...@@ -647,6 +645,6 @@ void br_netfilter_fini(void) ...@@ -647,6 +645,6 @@ void br_netfilter_fini(void)
{ {
int i; int i;
for (i = NUMHOOKS - 1; i >= 0; i--) for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
nf_unregister_hook(&br_nf_ops[i]); nf_unregister_hook(&br_nf_ops[i]);
} }
...@@ -98,7 +98,7 @@ static int __init init(void) ...@@ -98,7 +98,7 @@ static int __init init(void)
ret = ebt_register_table(&frame_filter); ret = ebt_register_table(&frame_filter);
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++) for (i = 0; i < ARRAY_SIZE(ebt_ops_filter); i++)
if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0) if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
goto cleanup; goto cleanup;
return ret; return ret;
...@@ -113,7 +113,7 @@ static void __exit fini(void) ...@@ -113,7 +113,7 @@ static void __exit fini(void)
{ {
int i; int i;
for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++) for (i = 0; i < ARRAY_SIZE(ebt_ops_filter); i++)
nf_unregister_hook(&ebt_ops_filter[i]); nf_unregister_hook(&ebt_ops_filter[i]);
ebt_unregister_table(&frame_filter); ebt_unregister_table(&frame_filter);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/netfilter_bridge/ebtables.h> #include <linux/netfilter_bridge/ebtables.h>
#include <linux/module.h> #include <linux/module.h>
#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \ #define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
(1 << NF_BR_POST_ROUTING)) (1 << NF_BR_POST_ROUTING))
...@@ -104,7 +105,7 @@ static int __init init(void) ...@@ -104,7 +105,7 @@ static int __init init(void)
ret = ebt_register_table(&frame_nat); ret = ebt_register_table(&frame_nat);
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++) for (i = 0; i < ARRAY_SIZE(ebt_ops_nat); i++)
if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0) if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
goto cleanup; goto cleanup;
return ret; return ret;
...@@ -119,7 +120,7 @@ static void __exit fini(void) ...@@ -119,7 +120,7 @@ static void __exit fini(void)
{ {
int i; int i;
for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++) for (i = 0; i < ARRAY_SIZE(ebt_ops_nat); i++)
nf_unregister_hook(&ebt_ops_nat[i]); nf_unregister_hook(&ebt_ops_nat[i]);
ebt_unregister_table(&frame_nat); ebt_unregister_table(&frame_nat);
} }
......
...@@ -273,7 +273,7 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms * ...@@ -273,7 +273,7 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *
memcpy(t, &dn_dev_sysctl, sizeof(*t)); memcpy(t, &dn_dev_sysctl, sizeof(*t));
for(i = 0; i < (sizeof(t->dn_dev_vars)/sizeof(t->dn_dev_vars[0]) - 1); i++) { for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
long offset = (long)t->dn_dev_vars[i].data; long offset = (long)t->dn_dev_vars[i].data;
t->dn_dev_vars[i].data = ((char *)parms) + offset; t->dn_dev_vars[i].data = ((char *)parms) + offset;
t->dn_dev_vars[i].de = NULL; t->dn_dev_vars[i].de = NULL;
......
...@@ -1302,9 +1302,7 @@ static void devinet_sysctl_register(struct in_device *in_dev, ...@@ -1302,9 +1302,7 @@ static void devinet_sysctl_register(struct in_device *in_dev,
if (!t) if (!t)
return; return;
memcpy(t, &devinet_sysctl, sizeof(*t)); memcpy(t, &devinet_sysctl, sizeof(*t));
for (i = 0; for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
i < sizeof(t->devinet_vars) / sizeof(t->devinet_vars[0]) - 1;
i++) {
t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf; t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
t->devinet_vars[i].de = NULL; t->devinet_vars[i].de = NULL;
} }
......
...@@ -301,7 +301,7 @@ static int help(struct sk_buff *skb, ...@@ -301,7 +301,7 @@ static int help(struct sk_buff *skb,
array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF; array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF;
array[3] = ntohl(ct->tuplehash[dir].tuple.src.ip) & 0xFF; array[3] = ntohl(ct->tuplehash[dir].tuple.src.ip) & 0xFF;
for (i = 0; i < sizeof(search) / sizeof(search[0]); i++) { for (i = 0; i < ARRAY_SIZE(search); i++) {
if (search[i].dir != dir) continue; if (search[i].dir != dir) continue;
found = find_pattern(ftp_buffer, skb->len - dataoff, found = find_pattern(ftp_buffer, skb->len - dataoff,
......
...@@ -1153,7 +1153,7 @@ static __inline__ unsigned short guess_mtu(unsigned short old_mtu) ...@@ -1153,7 +1153,7 @@ static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
{ {
int i; int i;
for (i = 0; i < sizeof(mtu_plateau) / sizeof(mtu_plateau[0]); i++) for (i = 0; i < ARRAY_SIZE(mtu_plateau); i++)
if (old_mtu > mtu_plateau[i]) if (old_mtu > mtu_plateau[i])
return mtu_plateau[i]; return mtu_plateau[i];
return 68; return 68;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/kernel.h>
#include <net/tcp.h> #include <net/tcp.h>
extern int sysctl_tcp_syncookies; extern int sysctl_tcp_syncookies;
...@@ -38,7 +39,7 @@ static __u16 const msstab[] = { ...@@ -38,7 +39,7 @@ static __u16 const msstab[] = {
(__u16)-1 (__u16)-1
}; };
/* The number doesn't include the -1 terminator */ /* The number doesn't include the -1 terminator */
#define NUM_MSS (sizeof(msstab)/sizeof(msstab[0]) - 1) #define NUM_MSS (ARRAY_SIZE(msstab) - 1)
/* /*
* Generate a syncookie. mssp points to the mss, which is returned * Generate a syncookie. mssp points to the mss, which is returned
......
...@@ -53,8 +53,6 @@ static struct irda_entry dir[] = { ...@@ -53,8 +53,6 @@ static struct irda_entry dir[] = {
{"irias", irias_proc_read}, {"irias", irias_proc_read},
}; };
#define IRDA_ENTRIES_NUM (sizeof(dir)/sizeof(dir[0]))
/* /*
* Function irda_proc_register (void) * Function irda_proc_register (void)
* *
...@@ -70,7 +68,7 @@ void __init irda_proc_register(void) ...@@ -70,7 +68,7 @@ void __init irda_proc_register(void)
return; return;
proc_irda->owner = THIS_MODULE; proc_irda->owner = THIS_MODULE;
for (i=0;i<IRDA_ENTRIES_NUM;i++) for (i=0; i<ARRAY_SIZE(dir); i++)
create_proc_info_entry(dir[i].name,0,proc_irda,dir[i].fn); create_proc_info_entry(dir[i].name,0,proc_irda,dir[i].fn);
} }
...@@ -85,7 +83,7 @@ void __exit irda_proc_unregister(void) ...@@ -85,7 +83,7 @@ void __exit irda_proc_unregister(void)
int i; int i;
if (proc_irda) { if (proc_irda) {
for (i=0;i<IRDA_ENTRIES_NUM;i++) for (i=0; i<ARRAY_SIZE(dir); i++)
remove_proc_entry(dir[i].name, proc_irda); remove_proc_entry(dir[i].name, proc_irda);
remove_proc_entry("net/irda", NULL); remove_proc_entry("net/irda", NULL);
......
...@@ -232,7 +232,7 @@ int __init init_netlink(void) ...@@ -232,7 +232,7 @@ int __init init_netlink(void)
devfs_mk_dir("netlink"); devfs_mk_dir("netlink");
/* Someone tell me the official names for the uppercase ones */ /* Someone tell me the official names for the uppercase ones */
for (i = 0; i < sizeof(entries)/sizeof(entries[0]); i++) { for (i = 0; i < ARRAY_SIZE(entries); i++) {
devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor), devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor),
S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name); S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name);
} }
...@@ -259,7 +259,7 @@ void cleanup_module(void) ...@@ -259,7 +259,7 @@ void cleanup_module(void)
{ {
int i; int i;
for (i = 0; i < sizeof(entries)/sizeof(entries[0]); i++) for (i = 0; i < ARRAY_SIZE(entries); i++)
devfs_remove("netlink/%s", entries[i].name); devfs_remove("netlink/%s", entries[i].name);
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
devfs_remove("netlink/tap%d", i); devfs_remove("netlink/tap%d", i);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
* be incorporated into the next SCTP release. * be incorporated into the next SCTP release.
*/ */
#include <linux/kernel.h>
#include <net/sctp/sctp.h> #include <net/sctp/sctp.h>
/* /*
...@@ -88,7 +89,7 @@ static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset, ...@@ -88,7 +89,7 @@ static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset,
char temp[128]; char temp[128];
/* How many entries? */ /* How many entries? */
entries = sizeof(sctp_dbg_objcnt)/sizeof(sctp_dbg_objcnt[0]); entries = ARRAY_SIZE(sctp_dbg_objcnt);
/* Walk the entries and print out the debug information /* Walk the entries and print out the debug information
* for proc fs. * for proc fs.
......
...@@ -288,7 +288,7 @@ static struct rpc_stat pmap_stats; ...@@ -288,7 +288,7 @@ static struct rpc_stat pmap_stats;
struct rpc_program pmap_program = { struct rpc_program pmap_program = {
.name = "portmap", .name = "portmap",
.number = RPC_PMAP_PROGRAM, .number = RPC_PMAP_PROGRAM,
.nrvers = sizeof(pmap_version)/sizeof(pmap_version[0]), .nrvers = ARRAY_SIZE(pmap_version),
.version = pmap_version, .version = pmap_version,
.stats = &pmap_stats, .stats = &pmap_stats,
}; };
...@@ -251,17 +251,17 @@ static struct xfrm_algo_desc calg_list[] = { ...@@ -251,17 +251,17 @@ static struct xfrm_algo_desc calg_list[] = {
static inline int aalg_entries(void) static inline int aalg_entries(void)
{ {
return sizeof(aalg_list) / sizeof(aalg_list[0]); return ARRAY_SIZE(aalg_list);
} }
static inline int ealg_entries(void) static inline int ealg_entries(void)
{ {
return sizeof(ealg_list) / sizeof(ealg_list[0]); return ARRAY_SIZE(ealg_list);
} }
static inline int calg_entries(void) static inline int calg_entries(void)
{ {
return sizeof(calg_list) / sizeof(calg_list[0]); return ARRAY_SIZE(calg_list);
} }
/* Todo: generic iterators */ /* Todo: generic iterators */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment