All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <Julia.Lawall@inria.fr>
To: Veerasenareddy Burru <vburru@marvell.com>
Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org,
	christophe.jaillet@wanadoo.fr, kuba@kernel.org,
	Abhijit Ayarekar <aayarekar@marvell.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 02/24] octeon_ep: use vmalloc_array and vcalloc
Date: Tue, 27 Jun 2023 16:43:17 +0200	[thread overview]
Message-ID: <20230627144339.144478-3-Julia.Lawall@inria.fr> (raw)
In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr>

Use vmalloc_array and vcalloc to protect against
multiplication overflows.

The changes were done using the following Coccinelle
semantic patch:

// <smpl>
@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)
)
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

---
v2: Use vmalloc_array and vcalloc instead of array_size.
This also leaves a multiplication of a constant by a sizeof
as is.  Two patches are thus dropped from the series.

 drivers/net/ethernet/marvell/octeon_ep/octep_rx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c
@@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_d
 		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);


  parent reply	other threads:[~2023-06-27 14:45 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 14:43 [PATCH v2 00/24] use vmalloc_array and vcalloc Julia Lawall
2023-06-27 14:43 ` Julia Lawall
2023-06-27 14:43 ` [Intel-gfx] " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 01/24] lib/test_vmalloc.c: " Julia Lawall
2023-06-27 14:43 ` Julia Lawall [this message]
2023-06-27 14:43 ` [PATCH v2 03/24] drm/gud: " Julia Lawall
2023-06-27 14:43   ` Julia Lawall
2023-07-03 12:23   ` Thomas Zimmermann
2023-07-04 10:41   ` Noralf Trønnes
2023-07-04 10:41     ` Noralf Trønnes
2023-06-27 14:43 ` [PATCH v2 04/24] gve: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 05/24] RDMA/erdma: " Julia Lawall
2023-07-21 18:56   ` Jason Gunthorpe
2023-06-27 14:43 ` [PATCH v2 06/24] dma-buf: system_heap: " Julia Lawall
2023-06-27 14:43   ` Julia Lawall
2023-06-27 18:52   ` John Stultz
2023-06-27 18:52     ` John Stultz
2023-06-27 14:43 ` [PATCH v2 07/24] scsi: fnic: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 08/24] virtio-mem: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 09/24] pds_core: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 10/24] bus: mhi: host: " Julia Lawall
2023-06-27 14:48   ` Jeffrey Hugo
2023-07-12 16:48   ` Manivannan Sadhasivam
2023-06-27 14:43 ` [PATCH v2 11/24] ionic: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 12/24] btrfs: zoned: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 13/24] iommu/tegra: gart: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 14/24] RDMA/siw: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 15/24] habanalabs: " Julia Lawall
2023-06-27 14:43   ` Julia Lawall
2023-07-02  8:01   ` Oded Gabbay
2023-06-27 14:43 ` [Intel-gfx] [PATCH v2 16/24] drm/i915/gvt: " Julia Lawall
2023-06-27 14:43   ` Julia Lawall
2023-06-27 14:43   ` Julia Lawall
2023-06-27 14:43 ` [PATCH v2 17/24] kcov: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 18/24] net: enetc: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 19/24] RDMA/bnxt_re: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 20/24] comedi: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 21/24] x86/sgx: " Julia Lawall
2023-06-27 14:54   ` Dave Hansen
2023-06-27 15:01     ` Julia Lawall
2023-06-27 15:06       ` Dave Hansen
2023-06-27 14:43 ` [PATCH v2 22/24] net: mana: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 23/24] vduse: " Julia Lawall
2023-06-27 14:43 ` [PATCH v2 24/24] scsi: qla2xxx: " Julia Lawall
2023-06-27 16:40 ` [PATCH v2 00/24] " patchwork-bot+netdevbpf
2023-06-27 16:40   ` [Intel-gfx] " patchwork-bot+netdevbpf
2023-06-27 16:40   ` patchwork-bot+netdevbpf
2023-07-06  1:35 ` Martin K. Petersen
2023-07-06  1:35   ` [Intel-gfx] " Martin K. Petersen
2023-07-06  1:35   ` Martin K. Petersen
2023-07-06  1:35   ` Martin K. Petersen
2023-07-11 16:31 ` (subset) " Martin K. Petersen
2023-07-11 16:31   ` [Intel-gfx] " Martin K. Petersen
2023-07-11 16:31   ` Martin K. Petersen
2023-07-11 16:31   ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230627144339.144478-3-Julia.Lawall@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=aayarekar@marvell.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vburru@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.