Skip to content

Commit d9b1a5a

Browse files
committed
Merge branch 'use-vmalloc_array-and-vcalloc'
Julia Lawall says: ==================== use vmalloc_array and vcalloc The functions vmalloc_array and vcalloc were introduced in commit a8749a3 ("mm: vmalloc: introduce array allocation functions") but are not used much yet. This series introduces uses of these functions, to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch. @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) v2: This series uses vmalloc_array and vcalloc instead of array_size. It also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. ==================== Link: https://lore.kernel.org/r/20230627144339.144478-1-Julia.Lawall@inria.fr Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 2553a52 + e9c74f8 commit d9b1a5a

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

drivers/net/ethernet/amd/pds_core/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
196196
dma_addr_t q_base_pa;
197197
int err;
198198

199-
qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info));
199+
qcq->q.info = vcalloc(num_descs, sizeof(*qcq->q.info));
200200
if (!qcq->q.info) {
201201
err = -ENOMEM;
202202
goto err_out;
@@ -219,7 +219,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
219219
if (err)
220220
goto err_out_free_q_info;
221221

222-
qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info));
222+
qcq->cq.info = vcalloc(num_descs, sizeof(*qcq->cq.info));
223223
if (!qcq->cq.info) {
224224
err = -ENOMEM;
225225
goto err_out_free_irq;

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ static int enetc_alloc_tx_resource(struct enetc_bdr_resource *res,
17891789
res->bd_count = bd_count;
17901790
res->bd_size = sizeof(union enetc_tx_bd);
17911791

1792-
res->tx_swbd = vzalloc(bd_count * sizeof(*res->tx_swbd));
1792+
res->tx_swbd = vcalloc(bd_count, sizeof(*res->tx_swbd));
17931793
if (!res->tx_swbd)
17941794
return -ENOMEM;
17951795

@@ -1877,7 +1877,7 @@ static int enetc_alloc_rx_resource(struct enetc_bdr_resource *res,
18771877
if (extended)
18781878
res->bd_size *= 2;
18791879

1880-
res->rx_swbd = vzalloc(bd_count * sizeof(struct enetc_rx_swbd));
1880+
res->rx_swbd = vcalloc(bd_count, sizeof(struct enetc_rx_swbd));
18811881
if (!res->rx_swbd)
18821882
return -ENOMEM;
18831883

drivers/net/ethernet/google/gve/gve_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
248248
tx->mask = slots - 1;
249249

250250
/* alloc metadata */
251-
tx->info = vzalloc(sizeof(*tx->info) * slots);
251+
tx->info = vcalloc(slots, sizeof(*tx->info));
252252
if (!tx->info)
253253
return -ENOMEM;
254254

drivers/net/ethernet/marvell/octeon_ep/octep_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no)
158158
goto desc_dma_alloc_err;
159159
}
160160

161-
oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
161+
oq->buff_info = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE);
162162
if (unlikely(!oq->buff_info)) {
163163
dev_err(&oct->pdev->dev,
164164
"Failed to allocate buffer info for OQ-%d\n", q_no);

drivers/net/ethernet/microsoft/mana/hw_channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
627627
if (WARN_ON(cq->id >= gc->max_num_cqs))
628628
return -EPROTO;
629629

630-
gc->cq_table = vzalloc(gc->max_num_cqs * sizeof(struct gdma_queue *));
630+
gc->cq_table = vcalloc(gc->max_num_cqs, sizeof(struct gdma_queue *));
631631
if (!gc->cq_table)
632632
return -ENOMEM;
633633

drivers/net/ethernet/pensando/ionic/ionic_lif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
561561
new->q.dev = dev;
562562
new->flags = flags;
563563

564-
new->q.info = vzalloc(num_descs * sizeof(*new->q.info));
564+
new->q.info = vcalloc(num_descs, sizeof(*new->q.info));
565565
if (!new->q.info) {
566566
netdev_err(lif->netdev, "Cannot allocate queue info\n");
567567
err = -ENOMEM;
@@ -582,7 +582,7 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
582582
if (err)
583583
goto err_out;
584584

585-
new->cq.info = vzalloc(num_descs * sizeof(*new->cq.info));
585+
new->cq.info = vcalloc(num_descs, sizeof(*new->cq.info));
586586
if (!new->cq.info) {
587587
netdev_err(lif->netdev, "Cannot allocate completion queue info\n");
588588
err = -ENOMEM;

0 commit comments

Comments
 (0)