Commit d9b1a5a6 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

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 a8749a35 ("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: default avatarJakub Kicinski <kuba@kernel.org>
parents 2553a527 e9c74f8b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
	dma_addr_t q_base_pa;
	int err;

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

	qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info));
	qcq->cq.info = vcalloc(num_descs, sizeof(*qcq->cq.info));
	if (!qcq->cq.info) {
		err = -ENOMEM;
		goto err_out_free_irq;
+2 −2
Original line number Diff line number Diff line
@@ -1789,7 +1789,7 @@ static int enetc_alloc_tx_resource(struct enetc_bdr_resource *res,
	res->bd_count = bd_count;
	res->bd_size = sizeof(union enetc_tx_bd);

	res->tx_swbd = vzalloc(bd_count * sizeof(*res->tx_swbd));
	res->tx_swbd = vcalloc(bd_count, sizeof(*res->tx_swbd));
	if (!res->tx_swbd)
		return -ENOMEM;

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

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

+1 −1
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
	tx->mask = slots - 1;

	/* alloc metadata */
	tx->info = vzalloc(sizeof(*tx->info) * slots);
	tx->info = vcalloc(slots, sizeof(*tx->info));
	if (!tx->info)
		return -ENOMEM;

+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_device *oct, int q_no)
		goto desc_dma_alloc_err;
	}

	oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE);
	oq->buff_info = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE);
	if (unlikely(!oq->buff_info)) {
		dev_err(&oct->pdev->dev,
			"Failed to allocate buffer info for OQ-%d\n", q_no);
+1 −1
Original line number Diff line number Diff line
@@ -627,7 +627,7 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
	if (WARN_ON(cq->id >= gc->max_num_cqs))
		return -EPROTO;

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

Loading