aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2018-06-12 16:55:00 -0400
committerKees Cook <keescook@chromium.org>2018-06-12 19:19:22 -0400
commit6da2ec56059c3c7a7e5f729e6349e74ace1e5c57 (patch)
tree2278b513e904a46e930a856da3ed3ac5bc3fe4a4 /net
parent1c542f38ab8d30d9c852a16d49ac5a15267bbf1f (diff)
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This patch replaces cases of: kmalloc(a * b, gfp) with: kmalloc_array(a * b, gfp) as well as handling cases of: kmalloc(a * b * c, gfp) with: kmalloc(array3_size(a, b, c), gfp) as it's slightly less ugly than: kmalloc_array(array_size(a, b), c, gfp) This does, however, attempt to ignore constant size factors like: kmalloc(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 tools/ directory was manually excluded, since it has its own implementation of kmalloc(). The Coccinelle script used for this was: // Fix redundant parens around sizeof(). @@ type TYPE; expression THING, E; @@ ( kmalloc( - (sizeof(TYPE)) * E + sizeof(TYPE) * E , ...) | kmalloc( - (sizeof(THING)) * E + sizeof(THING) * E , ...) ) // Drop single-byte sizes and redundant parens. @@ expression COUNT; typedef u8; typedef __u8; @@ ( kmalloc( - sizeof(u8) * (COUNT) + COUNT , ...) | kmalloc( - sizeof(__u8) * (COUNT) + COUNT , ...) | kmalloc( - sizeof(char) * (COUNT) + COUNT , ...) | kmalloc( - sizeof(unsigned char) * (COUNT) + COUNT , ...) | kmalloc( - sizeof(u8) * COUNT + COUNT , ...) | kmalloc( - sizeof(__u8) * COUNT + COUNT , ...) | kmalloc( - sizeof(char) * COUNT + COUNT , ...) | kmalloc( - 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; @@ ( - kmalloc + kmalloc_array ( - sizeof(TYPE) * (COUNT_ID) + COUNT_ID, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(TYPE) * COUNT_ID + COUNT_ID, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(TYPE) * (COUNT_CONST) + COUNT_CONST, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(TYPE) * COUNT_CONST + COUNT_CONST, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * (COUNT_ID) + COUNT_ID, sizeof(THING) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * COUNT_ID + COUNT_ID, sizeof(THING) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * (COUNT_CONST) + COUNT_CONST, sizeof(THING) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * COUNT_CONST + COUNT_CONST, sizeof(THING) , ...) ) // 2-factor product, only identifiers. @@ identifier SIZE, COUNT; @@ - kmalloc + kmalloc_array ( - 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; @@ ( kmalloc( - sizeof(TYPE) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kmalloc( - sizeof(TYPE) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kmalloc( - sizeof(TYPE) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kmalloc( - sizeof(TYPE) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | kmalloc( - sizeof(THING) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kmalloc( - sizeof(THING) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kmalloc( - sizeof(THING) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | kmalloc( - 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; @@ ( kmalloc( - sizeof(TYPE1) * sizeof(TYPE2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | kmalloc( - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | kmalloc( - sizeof(THING1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | kmalloc( - sizeof(THING1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | kmalloc( - sizeof(TYPE1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) | kmalloc( - 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; @@ ( kmalloc( - (COUNT) * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - COUNT * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - COUNT * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - (COUNT) * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - COUNT * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - (COUNT) * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - (COUNT) * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | kmalloc( - 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; @@ ( kmalloc(C1 * C2 * C3, ...) | kmalloc( - (E1) * E2 * E3 + array3_size(E1, E2, E3) , ...) | kmalloc( - (E1) * (E2) * E3 + array3_size(E1, E2, E3) , ...) | kmalloc( - (E1) * (E2) * (E3) + array3_size(E1, E2, E3) , ...) | kmalloc( - 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; @@ ( kmalloc(sizeof(THING) * C2, ...) | kmalloc(sizeof(TYPE) * C2, ...) | kmalloc(C1 * C2 * C3, ...) | kmalloc(C1 * C2, ...) | - kmalloc + kmalloc_array ( - sizeof(TYPE) * (E2) + E2, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(TYPE) * E2 + E2, sizeof(TYPE) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * (E2) + E2, sizeof(THING) , ...) | - kmalloc + kmalloc_array ( - sizeof(THING) * E2 + E2, sizeof(THING) , ...) | - kmalloc + kmalloc_array ( - (E1) * E2 + E1, E2 , ...) | - kmalloc + kmalloc_array ( - (E1) * (E2) + E1, E2 , ...) | - kmalloc + kmalloc_array ( - E1 * E2 + E1, E2 , ...) ) Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'net')
-rw-r--r--net/9p/protocol.c11
-rw-r--r--net/9p/trans_virtio.c3
-rw-r--r--net/atm/mpc.c2
-rw-r--r--net/bluetooth/hci_core.c2
-rw-r--r--net/bluetooth/l2cap_core.c2
-rw-r--r--net/can/bcm.c10
-rw-r--r--net/ceph/osdmap.c5
-rw-r--r--net/ceph/pagevec.c4
-rw-r--r--net/core/dev.c2
-rw-r--r--net/core/ethtool.c2
-rw-r--r--net/dcb/dcbnl.c3
-rw-r--r--net/dccp/ccids/ccid2.c3
-rw-r--r--net/ipv4/route.c3
-rw-r--r--net/mac80211/main.c2
-rw-r--r--net/mac80211/rc80211_minstrel.c2
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c2
-rw-r--r--net/netfilter/nf_conntrack_proto.c3
-rw-r--r--net/netfilter/nf_nat_core.c5
-rw-r--r--net/netfilter/nf_tables_api.c4
-rw-r--r--net/netfilter/x_tables.c2
-rw-r--r--net/netlink/genetlink.c10
-rw-r--r--net/openvswitch/datapath.c5
-rw-r--r--net/rds/info.c2
-rw-r--r--net/rxrpc/rxkad.c2
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c3
-rw-r--r--net/tipc/netlink_compat.c5
27 files changed, 58 insertions, 43 deletions
diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index 16e10680518c..931ea00c4fed 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -242,8 +242,9 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
242 "w", nwname); 242 "w", nwname);
243 if (!errcode) { 243 if (!errcode) {
244 *wnames = 244 *wnames =
245 kmalloc(sizeof(char *) * *nwname, 245 kmalloc_array(*nwname,
246 GFP_NOFS); 246 sizeof(char *),
247 GFP_NOFS);
247 if (!*wnames) 248 if (!*wnames)
248 errcode = -ENOMEM; 249 errcode = -ENOMEM;
249 } 250 }
@@ -285,9 +286,9 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
285 p9pdu_readf(pdu, proto_version, "w", nwqid); 286 p9pdu_readf(pdu, proto_version, "w", nwqid);
286 if (!errcode) { 287 if (!errcode) {
287 *wqids = 288 *wqids =
288 kmalloc(*nwqid * 289 kmalloc_array(*nwqid,
289 sizeof(struct p9_qid), 290 sizeof(struct p9_qid),
290 GFP_NOFS); 291 GFP_NOFS);
291 if (*wqids == NULL) 292 if (*wqids == NULL)
292 errcode = -ENOMEM; 293 errcode = -ENOMEM;
293 } 294 }
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 4d0372263e5d..05006cbb3361 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -360,7 +360,8 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
360 nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) - 360 nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) -
361 (unsigned long)p / PAGE_SIZE; 361 (unsigned long)p / PAGE_SIZE;
362 362
363 *pages = kmalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); 363 *pages = kmalloc_array(nr_pages, sizeof(struct page *),
364 GFP_NOFS);
364 if (!*pages) 365 if (!*pages)
365 return -ENOMEM; 366 return -ENOMEM;
366 367
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 31e0dcb970f8..75620c2f2617 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -472,7 +472,7 @@ static const uint8_t *copy_macs(struct mpoa_client *mpc,
472 if (mpc->number_of_mps_macs != 0) 472 if (mpc->number_of_mps_macs != 0)
473 kfree(mpc->mps_macs); 473 kfree(mpc->mps_macs);
474 mpc->number_of_mps_macs = 0; 474 mpc->number_of_mps_macs = 0;
475 mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL); 475 mpc->mps_macs = kmalloc_array(ETH_ALEN, num_macs, GFP_KERNEL);
476 if (mpc->mps_macs == NULL) { 476 if (mpc->mps_macs == NULL) {
477 pr_info("(%s) out of mem\n", mpc->dev->name); 477 pr_info("(%s) out of mem\n", mpc->dev->name);
478 return NULL; 478 return NULL;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1dec33790198..ee8ef1228263 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1281,7 +1281,7 @@ int hci_inquiry(void __user *arg)
1281 /* cache_dump can't sleep. Therefore we allocate temp buffer and then 1281 /* cache_dump can't sleep. Therefore we allocate temp buffer and then
1282 * copy it to the user space. 1282 * copy it to the user space.
1283 */ 1283 */
1284 buf = kmalloc(sizeof(struct inquiry_info) * max_rsp, GFP_KERNEL); 1284 buf = kmalloc_array(max_rsp, sizeof(struct inquiry_info), GFP_KERNEL);
1285 if (!buf) { 1285 if (!buf) {
1286 err = -ENOMEM; 1286 err = -ENOMEM;
1287 goto done; 1287 goto done;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9b7907ebfa01..d17a4736e47c 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -331,7 +331,7 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size)
331 */ 331 */
332 alloc_size = roundup_pow_of_two(size); 332 alloc_size = roundup_pow_of_two(size);
333 333
334 seq_list->list = kmalloc(sizeof(u16) * alloc_size, GFP_KERNEL); 334 seq_list->list = kmalloc_array(alloc_size, sizeof(u16), GFP_KERNEL);
335 if (!seq_list->list) 335 if (!seq_list->list)
336 return -ENOMEM; 336 return -ENOMEM;
337 337
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 97fedff3f0c4..394ff1d2791f 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -923,8 +923,9 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
923 923
924 /* create array for CAN frames and copy the data */ 924 /* create array for CAN frames and copy the data */
925 if (msg_head->nframes > 1) { 925 if (msg_head->nframes > 1) {
926 op->frames = kmalloc(msg_head->nframes * op->cfsiz, 926 op->frames = kmalloc_array(msg_head->nframes,
927 GFP_KERNEL); 927 op->cfsiz,
928 GFP_KERNEL);
928 if (!op->frames) { 929 if (!op->frames) {
929 kfree(op); 930 kfree(op);
930 return -ENOMEM; 931 return -ENOMEM;
@@ -1095,8 +1096,9 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
1095 1096
1096 if (msg_head->nframes > 1) { 1097 if (msg_head->nframes > 1) {
1097 /* create array for CAN frames and copy the data */ 1098 /* create array for CAN frames and copy the data */
1098 op->frames = kmalloc(msg_head->nframes * op->cfsiz, 1099 op->frames = kmalloc_array(msg_head->nframes,
1099 GFP_KERNEL); 1100 op->cfsiz,
1101 GFP_KERNEL);
1100 if (!op->frames) { 1102 if (!op->frames) {
1101 kfree(op); 1103 kfree(op);
1102 return -ENOMEM; 1104 return -ENOMEM;
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 9645ffd6acfb..e22820e24f50 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1299,8 +1299,9 @@ static int set_primary_affinity(struct ceph_osdmap *map, int osd, u32 aff)
1299 if (!map->osd_primary_affinity) { 1299 if (!map->osd_primary_affinity) {
1300 int i; 1300 int i;
1301 1301
1302 map->osd_primary_affinity = kmalloc(map->max_osd*sizeof(u32), 1302 map->osd_primary_affinity = kmalloc_array(map->max_osd,
1303 GFP_NOFS); 1303 sizeof(u32),
1304 GFP_NOFS);
1304 if (!map->osd_primary_affinity) 1305 if (!map->osd_primary_affinity)
1305 return -ENOMEM; 1306 return -ENOMEM;
1306 1307
diff --git a/net/ceph/pagevec.c b/net/ceph/pagevec.c
index a3d0adc828e6..e560d3975f41 100644
--- a/net/ceph/pagevec.c
+++ b/net/ceph/pagevec.c
@@ -20,7 +20,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
20 int got = 0; 20 int got = 0;
21 int rc = 0; 21 int rc = 0;
22 22
23 pages = kmalloc(sizeof(*pages) * num_pages, GFP_NOFS); 23 pages = kmalloc_array(num_pages, sizeof(*pages), GFP_NOFS);
24 if (!pages) 24 if (!pages)
25 return ERR_PTR(-ENOMEM); 25 return ERR_PTR(-ENOMEM);
26 26
@@ -74,7 +74,7 @@ struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags)
74 struct page **pages; 74 struct page **pages;
75 int i; 75 int i;
76 76
77 pages = kmalloc(sizeof(*pages) * num_pages, flags); 77 pages = kmalloc_array(num_pages, sizeof(*pages), flags);
78 if (!pages) 78 if (!pages)
79 return ERR_PTR(-ENOMEM); 79 return ERR_PTR(-ENOMEM);
80 for (i = 0; i < num_pages; i++) { 80 for (i = 0; i < num_pages; i++) {
diff --git a/net/core/dev.c b/net/core/dev.c
index 6e18242a1cae..57b7bab5f70b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8823,7 +8823,7 @@ static struct hlist_head * __net_init netdev_create_hash(void)
8823 int i; 8823 int i;
8824 struct hlist_head *hash; 8824 struct hlist_head *hash;
8825 8825
8826 hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL); 8826 hash = kmalloc_array(NETDEV_HASHENTRIES, sizeof(*hash), GFP_KERNEL);
8827 if (hash != NULL) 8827 if (hash != NULL)
8828 for (i = 0; i < NETDEV_HASHENTRIES; i++) 8828 for (i = 0; i < NETDEV_HASHENTRIES; i++)
8829 INIT_HLIST_HEAD(&hash[i]); 8829 INIT_HLIST_HEAD(&hash[i]);
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index c15075dc7572..436e4f9cc7f0 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1816,7 +1816,7 @@ static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1816 return -EFAULT; 1816 return -EFAULT;
1817 1817
1818 test.len = test_len; 1818 test.len = test_len;
1819 data = kmalloc(test_len * sizeof(u64), GFP_USER); 1819 data = kmalloc_array(test_len, sizeof(u64), GFP_USER);
1820 if (!data) 1820 if (!data)
1821 return -ENOMEM; 1821 return -ENOMEM;
1822 1822
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index d2f4e0c1faaf..2589a6b78aa1 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -984,7 +984,8 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
984 */ 984 */
985 err = ops->peer_getappinfo(netdev, &info, &app_count); 985 err = ops->peer_getappinfo(netdev, &info, &app_count);
986 if (!err && app_count) { 986 if (!err && app_count) {
987 table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL); 987 table = kmalloc_array(app_count, sizeof(struct dcb_app),
988 GFP_KERNEL);
988 if (!table) 989 if (!table)
989 return -ENOMEM; 990 return -ENOMEM;
990 991
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index 385f153fe031..2b75df469220 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -46,7 +46,8 @@ static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
46 return -ENOMEM; 46 return -ENOMEM;
47 47
48 /* allocate buffer and initialize linked list */ 48 /* allocate buffer and initialize linked list */
49 seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any()); 49 seqp = kmalloc_array(CCID2_SEQBUF_LEN, sizeof(struct ccid2_seq),
50 gfp_any());
50 if (seqp == NULL) 51 if (seqp == NULL)
51 return -ENOMEM; 52 return -ENOMEM;
52 53
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index bf4e4adc2d00..6bcd1eacc1f0 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -3146,7 +3146,8 @@ int __init ip_rt_init(void)
3146{ 3146{
3147 int cpu; 3147 int cpu;
3148 3148
3149 ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL); 3149 ip_idents = kmalloc_array(IP_IDENTS_SZ, sizeof(*ip_idents),
3150 GFP_KERNEL);
3150 if (!ip_idents) 3151 if (!ip_idents)
3151 panic("IP: failed to allocate ip_idents\n"); 3152 panic("IP: failed to allocate ip_idents\n");
3152 3153
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 4d2e797e3f16..fb1b1f9e7e5e 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -772,7 +772,7 @@ static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
772 if (have_mfp) 772 if (have_mfp)
773 n_suites += 4; 773 n_suites += 4;
774 774
775 suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL); 775 suites = kmalloc_array(n_suites, sizeof(u32), GFP_KERNEL);
776 if (!suites) 776 if (!suites)
777 return -ENOMEM; 777 return -ENOMEM;
778 778
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 8221bc5582ab..7fadfbca9f1b 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -596,7 +596,7 @@ minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
596 if (!mi->r) 596 if (!mi->r)
597 goto error; 597 goto error;
598 598
599 mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp); 599 mi->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
600 if (!mi->sample_table) 600 if (!mi->sample_table)
601 goto error1; 601 goto error1;
602 602
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index fb586b6e5d49..267ab9d5137e 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -1317,7 +1317,7 @@ minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
1317 if (!msp->ratelist) 1317 if (!msp->ratelist)
1318 goto error; 1318 goto error;
1319 1319
1320 msp->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp); 1320 msp->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
1321 if (!msp->sample_table) 1321 if (!msp->sample_table)
1322 goto error1; 1322 goto error1;
1323 1323
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index afdeca53e88b..d88841fbc560 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -402,7 +402,8 @@ int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *l4proto)
402 struct nf_conntrack_l4proto __rcu **proto_array; 402 struct nf_conntrack_l4proto __rcu **proto_array;
403 int i; 403 int i;
404 404
405 proto_array = kmalloc(MAX_NF_CT_PROTO * 405 proto_array =
406 kmalloc_array(MAX_NF_CT_PROTO,
406 sizeof(struct nf_conntrack_l4proto *), 407 sizeof(struct nf_conntrack_l4proto *),
407 GFP_KERNEL); 408 GFP_KERNEL);
408 if (proto_array == NULL) { 409 if (proto_array == NULL) {
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index b7df32a56e7e..46f9df99d276 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -691,8 +691,9 @@ int nf_nat_l4proto_register(u8 l3proto, const struct nf_nat_l4proto *l4proto)
691 691
692 mutex_lock(&nf_nat_proto_mutex); 692 mutex_lock(&nf_nat_proto_mutex);
693 if (nf_nat_l4protos[l3proto] == NULL) { 693 if (nf_nat_l4protos[l3proto] == NULL) {
694 l4protos = kmalloc(IPPROTO_MAX * sizeof(struct nf_nat_l4proto *), 694 l4protos = kmalloc_array(IPPROTO_MAX,
695 GFP_KERNEL); 695 sizeof(struct nf_nat_l4proto *),
696 GFP_KERNEL);
696 if (l4protos == NULL) { 697 if (l4protos == NULL) {
697 ret = -ENOMEM; 698 ret = -ENOMEM;
698 goto out; 699 goto out;
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index ca4c4d994ddb..cae4a026859d 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -7164,8 +7164,8 @@ static int __init nf_tables_module_init(void)
7164 7164
7165 nft_chain_filter_init(); 7165 nft_chain_filter_init();
7166 7166
7167 info = kmalloc(sizeof(struct nft_expr_info) * NFT_RULE_MAXEXPRS, 7167 info = kmalloc_array(NFT_RULE_MAXEXPRS, sizeof(struct nft_expr_info),
7168 GFP_KERNEL); 7168 GFP_KERNEL);
7169 if (info == NULL) { 7169 if (info == NULL) {
7170 err = -ENOMEM; 7170 err = -ENOMEM;
7171 goto err1; 7171 goto err1;
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index df9ab71b0ed9..d0d8397c9588 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1904,7 +1904,7 @@ static int __init xt_init(void)
1904 seqcount_init(&per_cpu(xt_recseq, i)); 1904 seqcount_init(&per_cpu(xt_recseq, i));
1905 } 1905 }
1906 1906
1907 xt = kmalloc(sizeof(struct xt_af) * NFPROTO_NUMPROTO, GFP_KERNEL); 1907 xt = kmalloc_array(NFPROTO_NUMPROTO, sizeof(struct xt_af), GFP_KERNEL);
1908 if (!xt) 1908 if (!xt)
1909 return -ENOMEM; 1909 return -ENOMEM;
1910 1910
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index b9ce82c9440f..25eeb6d2a75a 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -352,8 +352,9 @@ int genl_register_family(struct genl_family *family)
352 } 352 }
353 353
354 if (family->maxattr && !family->parallel_ops) { 354 if (family->maxattr && !family->parallel_ops) {
355 family->attrbuf = kmalloc((family->maxattr+1) * 355 family->attrbuf = kmalloc_array(family->maxattr + 1,
356 sizeof(struct nlattr *), GFP_KERNEL); 356 sizeof(struct nlattr *),
357 GFP_KERNEL);
357 if (family->attrbuf == NULL) { 358 if (family->attrbuf == NULL) {
358 err = -ENOMEM; 359 err = -ENOMEM;
359 goto errout_locked; 360 goto errout_locked;
@@ -566,8 +567,9 @@ static int genl_family_rcv_msg(const struct genl_family *family,
566 return -EOPNOTSUPP; 567 return -EOPNOTSUPP;
567 568
568 if (family->maxattr && family->parallel_ops) { 569 if (family->maxattr && family->parallel_ops) {
569 attrbuf = kmalloc((family->maxattr+1) * 570 attrbuf = kmalloc_array(family->maxattr + 1,
570 sizeof(struct nlattr *), GFP_KERNEL); 571 sizeof(struct nlattr *),
572 GFP_KERNEL);
571 if (attrbuf == NULL) 573 if (attrbuf == NULL)
572 return -ENOMEM; 574 return -ENOMEM;
573 } else 575 } else
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index a61818e94396..0f5ce77460d4 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1578,8 +1578,9 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
1578 goto err_destroy_table; 1578 goto err_destroy_table;
1579 } 1579 }
1580 1580
1581 dp->ports = kmalloc(DP_VPORT_HASH_BUCKETS * sizeof(struct hlist_head), 1581 dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
1582 GFP_KERNEL); 1582 sizeof(struct hlist_head),
1583 GFP_KERNEL);
1583 if (!dp->ports) { 1584 if (!dp->ports) {
1584 err = -ENOMEM; 1585 err = -ENOMEM;
1585 goto err_destroy_percpu; 1586 goto err_destroy_percpu;
diff --git a/net/rds/info.c b/net/rds/info.c
index 140a44a5f7b7..e367a97a18c8 100644
--- a/net/rds/info.c
+++ b/net/rds/info.c
@@ -188,7 +188,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
188 nr_pages = (PAGE_ALIGN(start + len) - (start & PAGE_MASK)) 188 nr_pages = (PAGE_ALIGN(start + len) - (start & PAGE_MASK))
189 >> PAGE_SHIFT; 189 >> PAGE_SHIFT;
190 190
191 pages = kmalloc(nr_pages * sizeof(struct page *), GFP_KERNEL); 191 pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
192 if (!pages) { 192 if (!pages) {
193 ret = -ENOMEM; 193 ret = -ENOMEM;
194 goto out; 194 goto out;
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 6c0ae27fff84..278ac0807a60 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -432,7 +432,7 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb,
432 432
433 sg = _sg; 433 sg = _sg;
434 if (unlikely(nsg > 4)) { 434 if (unlikely(nsg > 4)) {
435 sg = kmalloc(sizeof(*sg) * nsg, GFP_NOIO); 435 sg = kmalloc_array(nsg, sizeof(*sg), GFP_NOIO);
436 if (!sg) 436 if (!sg)
437 goto nomem; 437 goto nomem;
438 } 438 }
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 11d93377ba5e..5dffbc493008 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1438,7 +1438,7 @@ static __init int sctp_init(void)
1438 /* Allocate and initialize the endpoint hash table. */ 1438 /* Allocate and initialize the endpoint hash table. */
1439 sctp_ep_hashsize = 64; 1439 sctp_ep_hashsize = 64;
1440 sctp_ep_hashtable = 1440 sctp_ep_hashtable =
1441 kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL); 1441 kmalloc_array(64, sizeof(struct sctp_hashbucket), GFP_KERNEL);
1442 if (!sctp_ep_hashtable) { 1442 if (!sctp_ep_hashtable) {
1443 pr_err("Failed endpoint_hash alloc\n"); 1443 pr_err("Failed endpoint_hash alloc\n");
1444 status = -ENOMEM; 1444 status = -ENOMEM;
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 9463af4b32e8..be8f103d22fd 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1753,7 +1753,8 @@ alloc_enc_pages(struct rpc_rqst *rqstp)
1753 last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_SHIFT; 1753 last = (snd_buf->page_base + snd_buf->page_len - 1) >> PAGE_SHIFT;
1754 rqstp->rq_enc_pages_num = last - first + 1 + 1; 1754 rqstp->rq_enc_pages_num = last - first + 1 + 1;
1755 rqstp->rq_enc_pages 1755 rqstp->rq_enc_pages
1756 = kmalloc(rqstp->rq_enc_pages_num * sizeof(struct page *), 1756 = kmalloc_array(rqstp->rq_enc_pages_num,
1757 sizeof(struct page *),
1757 GFP_NOFS); 1758 GFP_NOFS);
1758 if (!rqstp->rq_enc_pages) 1759 if (!rqstp->rq_enc_pages)
1759 goto out; 1760 goto out;
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index 4492cda45566..a2f76743c73a 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -285,8 +285,9 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
285 if (!trans_buf) 285 if (!trans_buf)
286 return -ENOMEM; 286 return -ENOMEM;
287 287
288 attrbuf = kmalloc((tipc_genl_family.maxattr + 1) * 288 attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1,
289 sizeof(struct nlattr *), GFP_KERNEL); 289 sizeof(struct nlattr *),
290 GFP_KERNEL);
290 if (!attrbuf) { 291 if (!attrbuf) {
291 err = -ENOMEM; 292 err = -ENOMEM;
292 goto trans_out; 293 goto trans_out;