diff options
author | Kees Cook <keescook@chromium.org> | 2018-06-12 17:03:40 -0400 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2018-06-12 19:19:22 -0400 |
commit | 6396bb221514d2876fd6dc0aa2a1f240d99b37bb (patch) | |
tree | c5c501e859b93de096b1f01160135612ed765059 /net | |
parent | 6da2ec56059c3c7a7e5f729e6349e74ace1e5c57 (diff) |
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/bridge/br_multicast.c | 2 | ||||
-rw-r--r-- | net/can/bcm.c | 3 | ||||
-rw-r--r-- | net/core/ethtool.c | 4 | ||||
-rw-r--r-- | net/ieee802154/nl-phy.c | 2 | ||||
-rw-r--r-- | net/ipv4/fib_frontend.c | 2 | ||||
-rw-r--r-- | net/ipv4/route.c | 2 | ||||
-rw-r--r-- | net/ipv6/icmp.c | 2 | ||||
-rw-r--r-- | net/mac80211/chan.c | 2 | ||||
-rw-r--r-- | net/mac80211/rc80211_minstrel.c | 2 | ||||
-rw-r--r-- | net/mac80211/rc80211_minstrel_ht.c | 2 | ||||
-rw-r--r-- | net/mac80211/scan.c | 2 | ||||
-rw-r--r-- | net/mac80211/util.c | 5 | ||||
-rw-r--r-- | net/netfilter/nf_tables_api.c | 2 | ||||
-rw-r--r-- | net/netfilter/nfnetlink_cthelper.c | 5 | ||||
-rw-r--r-- | net/netrom/af_netrom.c | 2 | ||||
-rw-r--r-- | net/openvswitch/vport.c | 2 | ||||
-rw-r--r-- | net/rds/ib.c | 3 | ||||
-rw-r--r-- | net/rose/af_rose.c | 3 | ||||
-rw-r--r-- | net/sctp/auth.c | 5 | ||||
-rw-r--r-- | net/smc/smc_wr.c | 6 | ||||
-rw-r--r-- | net/sunrpc/auth_gss/gss_rpc_upcall.c | 2 | ||||
-rw-r--r-- | net/sunrpc/cache.c | 2 | ||||
-rw-r--r-- | net/wireless/nl80211.c | 4 |
23 files changed, 36 insertions, 30 deletions
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index cb4729539b82..920665dd92db 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c | |||
@@ -333,7 +333,7 @@ static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu **mdbp, int max, | |||
333 | mdb->max = max; | 333 | mdb->max = max; |
334 | mdb->old = old; | 334 | mdb->old = old; |
335 | 335 | ||
336 | mdb->mhash = kzalloc(max * sizeof(*mdb->mhash), GFP_ATOMIC); | 336 | mdb->mhash = kcalloc(max, sizeof(*mdb->mhash), GFP_ATOMIC); |
337 | if (!mdb->mhash) { | 337 | if (!mdb->mhash) { |
338 | kfree(mdb); | 338 | kfree(mdb); |
339 | return -ENOMEM; | 339 | return -ENOMEM; |
diff --git a/net/can/bcm.c b/net/can/bcm.c index 394ff1d2791f..9393f25df08d 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -1105,7 +1105,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | /* create and init array for received CAN frames */ | 1107 | /* create and init array for received CAN frames */ |
1108 | op->last_frames = kzalloc(msg_head->nframes * op->cfsiz, | 1108 | op->last_frames = kcalloc(msg_head->nframes, |
1109 | op->cfsiz, | ||
1109 | GFP_KERNEL); | 1110 | GFP_KERNEL); |
1110 | if (!op->last_frames) { | 1111 | if (!op->last_frames) { |
1111 | kfree(op->frames); | 1112 | kfree(op->frames); |
diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 436e4f9cc7f0..8be6be2d9c7b 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c | |||
@@ -911,7 +911,7 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, | |||
911 | memset(&info, 0, sizeof(info)); | 911 | memset(&info, 0, sizeof(info)); |
912 | info.cmd = ETHTOOL_GSSET_INFO; | 912 | info.cmd = ETHTOOL_GSSET_INFO; |
913 | 913 | ||
914 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); | 914 | info_buf = kcalloc(n_bits, sizeof(u32), GFP_USER); |
915 | if (!info_buf) | 915 | if (!info_buf) |
916 | return -ENOMEM; | 916 | return -ENOMEM; |
917 | 917 | ||
@@ -1017,7 +1017,7 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, | |||
1017 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { | 1017 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
1018 | if (info.rule_cnt > 0) { | 1018 | if (info.rule_cnt > 0) { |
1019 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) | 1019 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
1020 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), | 1020 | rule_buf = kcalloc(info.rule_cnt, sizeof(u32), |
1021 | GFP_USER); | 1021 | GFP_USER); |
1022 | if (!rule_buf) | 1022 | if (!rule_buf) |
1023 | return -ENOMEM; | 1023 | return -ENOMEM; |
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c index dc2960be51e0..b231e40f006a 100644 --- a/net/ieee802154/nl-phy.c +++ b/net/ieee802154/nl-phy.c | |||
@@ -38,7 +38,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 portid, | |||
38 | { | 38 | { |
39 | void *hdr; | 39 | void *hdr; |
40 | int i, pages = 0; | 40 | int i, pages = 0; |
41 | uint32_t *buf = kzalloc(32 * sizeof(uint32_t), GFP_KERNEL); | 41 | uint32_t *buf = kcalloc(32, sizeof(uint32_t), GFP_KERNEL); |
42 | 42 | ||
43 | pr_debug("%s\n", __func__); | 43 | pr_debug("%s\n", __func__); |
44 | 44 | ||
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 63aa39b3af03..b21833651394 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c | |||
@@ -567,7 +567,7 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt, | |||
567 | struct nlattr *mx; | 567 | struct nlattr *mx; |
568 | int len = 0; | 568 | int len = 0; |
569 | 569 | ||
570 | mx = kzalloc(3 * nla_total_size(4), GFP_KERNEL); | 570 | mx = kcalloc(3, nla_total_size(4), GFP_KERNEL); |
571 | if (!mx) | 571 | if (!mx) |
572 | return -ENOMEM; | 572 | return -ENOMEM; |
573 | 573 | ||
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 6bcd1eacc1f0..1df6e97106d7 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -649,7 +649,7 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw, | |||
649 | 649 | ||
650 | hash = rcu_dereference(nh->nh_exceptions); | 650 | hash = rcu_dereference(nh->nh_exceptions); |
651 | if (!hash) { | 651 | if (!hash) { |
652 | hash = kzalloc(FNHE_HASH_SIZE * sizeof(*hash), GFP_ATOMIC); | 652 | hash = kcalloc(FNHE_HASH_SIZE, sizeof(*hash), GFP_ATOMIC); |
653 | if (!hash) | 653 | if (!hash) |
654 | goto out_unlock; | 654 | goto out_unlock; |
655 | rcu_assign_pointer(nh->nh_exceptions, hash); | 655 | rcu_assign_pointer(nh->nh_exceptions, hash); |
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index d8c4b6374377..be491bf6ab6e 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c | |||
@@ -956,7 +956,7 @@ static int __net_init icmpv6_sk_init(struct net *net) | |||
956 | int err, i, j; | 956 | int err, i, j; |
957 | 957 | ||
958 | net->ipv6.icmp_sk = | 958 | net->ipv6.icmp_sk = |
959 | kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL); | 959 | kcalloc(nr_cpu_ids, sizeof(struct sock *), GFP_KERNEL); |
960 | if (!net->ipv6.icmp_sk) | 960 | if (!net->ipv6.icmp_sk) |
961 | return -ENOMEM; | 961 | return -ENOMEM; |
962 | 962 | ||
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index 89178b46b32f..d9558ffb8acf 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c | |||
@@ -1186,7 +1186,7 @@ static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local, | |||
1186 | lockdep_assert_held(&local->mtx); | 1186 | lockdep_assert_held(&local->mtx); |
1187 | lockdep_assert_held(&local->chanctx_mtx); | 1187 | lockdep_assert_held(&local->chanctx_mtx); |
1188 | 1188 | ||
1189 | vif_chsw = kzalloc(sizeof(vif_chsw[0]) * n_vifs, GFP_KERNEL); | 1189 | vif_chsw = kcalloc(n_vifs, sizeof(vif_chsw[0]), GFP_KERNEL); |
1190 | if (!vif_chsw) | 1190 | if (!vif_chsw) |
1191 | return -ENOMEM; | 1191 | return -ENOMEM; |
1192 | 1192 | ||
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c index 7fadfbca9f1b..76048b53c5b2 100644 --- a/net/mac80211/rc80211_minstrel.c +++ b/net/mac80211/rc80211_minstrel.c | |||
@@ -592,7 +592,7 @@ minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp) | |||
592 | max_rates = sband->n_bitrates; | 592 | max_rates = sband->n_bitrates; |
593 | } | 593 | } |
594 | 594 | ||
595 | mi->r = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp); | 595 | mi->r = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp); |
596 | if (!mi->r) | 596 | if (!mi->r) |
597 | goto error; | 597 | goto error; |
598 | 598 | ||
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c index 267ab9d5137e..67ebdeaffbbc 100644 --- a/net/mac80211/rc80211_minstrel_ht.c +++ b/net/mac80211/rc80211_minstrel_ht.c | |||
@@ -1313,7 +1313,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp) | |||
1313 | if (!msp) | 1313 | if (!msp) |
1314 | return NULL; | 1314 | return NULL; |
1315 | 1315 | ||
1316 | msp->ratelist = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp); | 1316 | msp->ratelist = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp); |
1317 | if (!msp->ratelist) | 1317 | if (!msp->ratelist) |
1318 | goto error; | 1318 | goto error; |
1319 | 1319 | ||
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index a3b1bcc2b461..2e917a6d239d 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c | |||
@@ -1157,7 +1157,7 @@ int __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata, | |||
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | ie = kzalloc(num_bands * iebufsz, GFP_KERNEL); | 1160 | ie = kcalloc(iebufsz, num_bands, GFP_KERNEL); |
1161 | if (!ie) { | 1161 | if (!ie) { |
1162 | ret = -ENOMEM; | 1162 | ret = -ENOMEM; |
1163 | goto out; | 1163 | goto out; |
diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 2d82c88efd0b..5e2e511c4a6f 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c | |||
@@ -1803,8 +1803,9 @@ static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata) | |||
1803 | if (WARN_ON(res)) | 1803 | if (WARN_ON(res)) |
1804 | return res; | 1804 | return res; |
1805 | 1805 | ||
1806 | funcs = kzalloc((sdata->local->hw.max_nan_de_entries + 1) * | 1806 | funcs = kcalloc(sdata->local->hw.max_nan_de_entries + 1, |
1807 | sizeof(*funcs), GFP_KERNEL); | 1807 | sizeof(*funcs), |
1808 | GFP_KERNEL); | ||
1808 | if (!funcs) | 1809 | if (!funcs) |
1809 | return -ENOMEM; | 1810 | return -ENOMEM; |
1810 | 1811 | ||
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index cae4a026859d..f0411fbffe77 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c | |||
@@ -5303,7 +5303,7 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx, | |||
5303 | if (err < 0) | 5303 | if (err < 0) |
5304 | return err; | 5304 | return err; |
5305 | 5305 | ||
5306 | ops = kzalloc(sizeof(struct nf_hook_ops) * n, GFP_KERNEL); | 5306 | ops = kcalloc(n, sizeof(struct nf_hook_ops), GFP_KERNEL); |
5307 | if (!ops) | 5307 | if (!ops) |
5308 | return -ENOMEM; | 5308 | return -ENOMEM; |
5309 | 5309 | ||
diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c index cb5b5f207777..e5d27b2e4eba 100644 --- a/net/netfilter/nfnetlink_cthelper.c +++ b/net/netfilter/nfnetlink_cthelper.c | |||
@@ -190,8 +190,9 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper, | |||
190 | if (class_max > NF_CT_MAX_EXPECT_CLASSES) | 190 | if (class_max > NF_CT_MAX_EXPECT_CLASSES) |
191 | return -EOVERFLOW; | 191 | return -EOVERFLOW; |
192 | 192 | ||
193 | expect_policy = kzalloc(sizeof(struct nf_conntrack_expect_policy) * | 193 | expect_policy = kcalloc(class_max, |
194 | class_max, GFP_KERNEL); | 194 | sizeof(struct nf_conntrack_expect_policy), |
195 | GFP_KERNEL); | ||
195 | if (expect_policy == NULL) | 196 | if (expect_policy == NULL) |
196 | return -ENOMEM; | 197 | return -ENOMEM; |
197 | 198 | ||
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index b97eb766a1d5..93fbcafbf388 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c | |||
@@ -1395,7 +1395,7 @@ static int __init nr_proto_init(void) | |||
1395 | return -1; | 1395 | return -1; |
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | dev_nr = kzalloc(nr_ndevs * sizeof(struct net_device *), GFP_KERNEL); | 1398 | dev_nr = kcalloc(nr_ndevs, sizeof(struct net_device *), GFP_KERNEL); |
1399 | if (dev_nr == NULL) { | 1399 | if (dev_nr == NULL) { |
1400 | printk(KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device array\n"); | 1400 | printk(KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device array\n"); |
1401 | return -1; | 1401 | return -1; |
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index f81c1d0ddff4..19f6765566e7 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c | |||
@@ -47,7 +47,7 @@ static struct hlist_head *dev_table; | |||
47 | */ | 47 | */ |
48 | int ovs_vport_init(void) | 48 | int ovs_vport_init(void) |
49 | { | 49 | { |
50 | dev_table = kzalloc(VPORT_HASH_BUCKETS * sizeof(struct hlist_head), | 50 | dev_table = kcalloc(VPORT_HASH_BUCKETS, sizeof(struct hlist_head), |
51 | GFP_KERNEL); | 51 | GFP_KERNEL); |
52 | if (!dev_table) | 52 | if (!dev_table) |
53 | return -ENOMEM; | 53 | return -ENOMEM; |
diff --git a/net/rds/ib.c b/net/rds/ib.c index 02deee29e7f1..b6ad38e48f62 100644 --- a/net/rds/ib.c +++ b/net/rds/ib.c | |||
@@ -163,7 +163,8 @@ static void rds_ib_add_one(struct ib_device *device) | |||
163 | rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom; | 163 | rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom; |
164 | rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom; | 164 | rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom; |
165 | 165 | ||
166 | rds_ibdev->vector_load = kzalloc(sizeof(int) * device->num_comp_vectors, | 166 | rds_ibdev->vector_load = kcalloc(device->num_comp_vectors, |
167 | sizeof(int), | ||
167 | GFP_KERNEL); | 168 | GFP_KERNEL); |
168 | if (!rds_ibdev->vector_load) { | 169 | if (!rds_ibdev->vector_load) { |
169 | pr_err("RDS/IB: %s failed to allocate vector memory\n", | 170 | pr_err("RDS/IB: %s failed to allocate vector memory\n", |
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c index 5b73fea849df..ebe42e7eb456 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c | |||
@@ -1514,7 +1514,8 @@ static int __init rose_proto_init(void) | |||
1514 | 1514 | ||
1515 | rose_callsign = null_ax25_address; | 1515 | rose_callsign = null_ax25_address; |
1516 | 1516 | ||
1517 | dev_rose = kzalloc(rose_ndevs * sizeof(struct net_device *), GFP_KERNEL); | 1517 | dev_rose = kcalloc(rose_ndevs, sizeof(struct net_device *), |
1518 | GFP_KERNEL); | ||
1518 | if (dev_rose == NULL) { | 1519 | if (dev_rose == NULL) { |
1519 | printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n"); | 1520 | printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n"); |
1520 | rc = -ENOMEM; | 1521 | rc = -ENOMEM; |
diff --git a/net/sctp/auth.c b/net/sctp/auth.c index e64630cd3331..5b537613946f 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c | |||
@@ -482,8 +482,9 @@ int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp) | |||
482 | return 0; | 482 | return 0; |
483 | 483 | ||
484 | /* Allocated the array of pointers to transorms */ | 484 | /* Allocated the array of pointers to transorms */ |
485 | ep->auth_hmacs = kzalloc(sizeof(struct crypto_shash *) * | 485 | ep->auth_hmacs = kcalloc(SCTP_AUTH_NUM_HMACS, |
486 | SCTP_AUTH_NUM_HMACS, gfp); | 486 | sizeof(struct crypto_shash *), |
487 | gfp); | ||
487 | if (!ep->auth_hmacs) | 488 | if (!ep->auth_hmacs) |
488 | return -ENOMEM; | 489 | return -ENOMEM; |
489 | 490 | ||
diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c index cc7c1bb60fe8..dbd2605d1962 100644 --- a/net/smc/smc_wr.c +++ b/net/smc/smc_wr.c | |||
@@ -584,9 +584,9 @@ int smc_wr_alloc_link_mem(struct smc_link *link) | |||
584 | GFP_KERNEL); | 584 | GFP_KERNEL); |
585 | if (!link->wr_rx_sges) | 585 | if (!link->wr_rx_sges) |
586 | goto no_mem_wr_tx_sges; | 586 | goto no_mem_wr_tx_sges; |
587 | link->wr_tx_mask = kzalloc( | 587 | link->wr_tx_mask = kcalloc(BITS_TO_LONGS(SMC_WR_BUF_CNT), |
588 | BITS_TO_LONGS(SMC_WR_BUF_CNT) * sizeof(*link->wr_tx_mask), | 588 | sizeof(*link->wr_tx_mask), |
589 | GFP_KERNEL); | 589 | GFP_KERNEL); |
590 | if (!link->wr_tx_mask) | 590 | if (!link->wr_tx_mask) |
591 | goto no_mem_wr_rx_sges; | 591 | goto no_mem_wr_rx_sges; |
592 | link->wr_tx_pends = kcalloc(SMC_WR_BUF_CNT, | 592 | link->wr_tx_pends = kcalloc(SMC_WR_BUF_CNT, |
diff --git a/net/sunrpc/auth_gss/gss_rpc_upcall.c b/net/sunrpc/auth_gss/gss_rpc_upcall.c index 46b295e4f2b8..d58bd058b09b 100644 --- a/net/sunrpc/auth_gss/gss_rpc_upcall.c +++ b/net/sunrpc/auth_gss/gss_rpc_upcall.c | |||
@@ -224,7 +224,7 @@ static void gssp_free_receive_pages(struct gssx_arg_accept_sec_context *arg) | |||
224 | static int gssp_alloc_receive_pages(struct gssx_arg_accept_sec_context *arg) | 224 | static int gssp_alloc_receive_pages(struct gssx_arg_accept_sec_context *arg) |
225 | { | 225 | { |
226 | arg->npages = DIV_ROUND_UP(NGROUPS_MAX * 4, PAGE_SIZE); | 226 | arg->npages = DIV_ROUND_UP(NGROUPS_MAX * 4, PAGE_SIZE); |
227 | arg->pages = kzalloc(arg->npages * sizeof(struct page *), GFP_KERNEL); | 227 | arg->pages = kcalloc(arg->npages, sizeof(struct page *), GFP_KERNEL); |
228 | /* | 228 | /* |
229 | * XXX: actual pages are allocated by xdr layer in | 229 | * XXX: actual pages are allocated by xdr layer in |
230 | * xdr_partial_copy_from_skb. | 230 | * xdr_partial_copy_from_skb. |
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index cdda4744c9b1..109fbe591e7b 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c | |||
@@ -1683,7 +1683,7 @@ struct cache_detail *cache_create_net(const struct cache_detail *tmpl, struct ne | |||
1683 | if (cd == NULL) | 1683 | if (cd == NULL) |
1684 | return ERR_PTR(-ENOMEM); | 1684 | return ERR_PTR(-ENOMEM); |
1685 | 1685 | ||
1686 | cd->hash_table = kzalloc(cd->hash_size * sizeof(struct hlist_head), | 1686 | cd->hash_table = kcalloc(cd->hash_size, sizeof(struct hlist_head), |
1687 | GFP_KERNEL); | 1687 | GFP_KERNEL); |
1688 | if (cd->hash_table == NULL) { | 1688 | if (cd->hash_table == NULL) { |
1689 | kfree(cd); | 1689 | kfree(cd); |
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 07514ca011b2..c7bbe5f0aae8 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -10833,7 +10833,7 @@ static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, | |||
10833 | struct nlattr **tb; | 10833 | struct nlattr **tb; |
10834 | int err; | 10834 | int err; |
10835 | 10835 | ||
10836 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | 10836 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
10837 | if (!tb) | 10837 | if (!tb) |
10838 | return -ENOMEM; | 10838 | return -ENOMEM; |
10839 | 10839 | ||
@@ -11793,7 +11793,7 @@ static int nl80211_nan_add_func(struct sk_buff *skb, | |||
11793 | 11793 | ||
11794 | func->srf_num_macs = n_entries; | 11794 | func->srf_num_macs = n_entries; |
11795 | func->srf_macs = | 11795 | func->srf_macs = |
11796 | kzalloc(sizeof(*func->srf_macs) * n_entries, | 11796 | kcalloc(n_entries, sizeof(*func->srf_macs), |
11797 | GFP_KERNEL); | 11797 | GFP_KERNEL); |
11798 | if (!func->srf_macs) { | 11798 | if (!func->srf_macs) { |
11799 | err = -ENOMEM; | 11799 | err = -ENOMEM; |