Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jan 2018 15:25:26 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r327828 - in head/sys/dev: e1000 ixl
Message-ID:  <201801111525.w0BFPQDn084190@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Thu Jan 11 15:25:26 2018
New Revision: 327828
URL: https://svnweb.freebsd.org/changeset/base/327828

Log:
  dev/(e1000,ixl): Make some use of mallocarray(9).
  
  Reviewed by:	erj
  Differential Revision: https://reviews.freebsd.org/D13833

Modified:
  head/sys/dev/e1000/if_em.c
  head/sys/dev/ixl/if_ixlv.c
  head/sys/dev/ixl/ixl_pf_iov.c
  head/sys/dev/ixl/ixl_pf_main.c

Modified: head/sys/dev/e1000/if_em.c
==============================================================================
--- head/sys/dev/e1000/if_em.c	Thu Jan 11 15:03:01 2018	(r327827)
+++ head/sys/dev/e1000/if_em.c	Thu Jan 11 15:25:26 2018	(r327828)
@@ -2835,9 +2835,9 @@ em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, u
 
 	/* First allocate the top level queue structs */
 	if (!(adapter->tx_queues =
-	    (struct em_tx_queue *) malloc(sizeof(struct em_tx_queue) *
-	    adapter->tx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
-		device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
+	    (struct em_tx_queue *) mallocarray(adapter->tx_num_queues,
+		sizeof(struct em_tx_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
+		    device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
 		return(ENOMEM);
 	}
 
@@ -2849,7 +2849,8 @@ em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, u
 		que->me = txr->me =  i;
 
 		/* Allocate report status array */
-		if (!(txr->tx_rsq = (qidx_t *) malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_DEVBUF, M_NOWAIT | M_ZERO))) {
+		if (!(txr->tx_rsq = (qidx_t *) mallocarray(scctx->isc_ntxd[0],
+		    sizeof(qidx_t), M_DEVBUF, M_NOWAIT | M_ZERO))) {
 			device_printf(iflib_get_dev(ctx), "failed to allocate rs_idxs memory\n");
 			error = ENOMEM;
 			goto fail;
@@ -2881,8 +2882,8 @@ em_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, u
 
 	/* First allocate the top level queue structs */
 	if (!(adapter->rx_queues =
-	    (struct em_rx_queue *) malloc(sizeof(struct em_rx_queue) *
-	    adapter->rx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+	    (struct em_rx_queue *) mallocarray(adapter->rx_num_queues,
+	        sizeof(struct em_rx_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
 		device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
 		error = ENOMEM;
 		goto fail;

Modified: head/sys/dev/ixl/if_ixlv.c
==============================================================================
--- head/sys/dev/ixl/if_ixlv.c	Thu Jan 11 15:03:01 2018	(r327827)
+++ head/sys/dev/ixl/if_ixlv.c	Thu Jan 11 15:25:26 2018	(r327828)
@@ -1637,8 +1637,8 @@ ixlv_setup_queues(struct ixlv_sc *sc)
 
 	/* Get memory for the station queues */
 	if (!(vsi->queues =
-		(struct ixl_queue *) malloc(sizeof(struct ixl_queue) *
-		vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+		(struct ixl_queue *) mallocarray(vsi->num_queues,
+		    sizeof(struct ixl_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
 			device_printf(dev, "Unable to allocate queue memory\n");
 			error = ENOMEM;
 			goto early;

Modified: head/sys/dev/ixl/ixl_pf_iov.c
==============================================================================
--- head/sys/dev/ixl/ixl_pf_iov.c	Thu Jan 11 15:03:01 2018	(r327827)
+++ head/sys/dev/ixl/ixl_pf_iov.c	Thu Jan 11 15:25:26 2018	(r327828)
@@ -1695,8 +1695,8 @@ ixl_iov_init(device_t dev, uint16_t num_vfs, const nvl
 	pf_vsi = &pf->vsi;
 
 	IXL_PF_LOCK(pf);
-	pf->vfs = malloc(sizeof(struct ixl_vf) * num_vfs, M_IXL, M_NOWAIT |
-	    M_ZERO);
+	pf->vfs = mallocarray(num_vfs, sizeof(struct ixl_vf), M_IXL,
+	    M_NOWAIT | M_ZERO);
 
 	if (pf->vfs == NULL) {
 		error = ENOMEM;

Modified: head/sys/dev/ixl/ixl_pf_main.c
==============================================================================
--- head/sys/dev/ixl/ixl_pf_main.c	Thu Jan 11 15:03:01 2018	(r327827)
+++ head/sys/dev/ixl/ixl_pf_main.c	Thu Jan 11 15:25:26 2018	(r327828)
@@ -2431,8 +2431,8 @@ ixl_setup_stations(struct ixl_pf *pf)
 
 	/* Get memory for the station queues */
         if (!(vsi->queues =
-            (struct ixl_queue *) malloc(sizeof(struct ixl_queue) *
-            vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
+            (struct ixl_queue *) mallocarray(vsi->num_queues,
+	    sizeof(struct ixl_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
                 device_printf(dev, "Unable to allocate queue memory\n");
                 error = ENOMEM;
                 return (error);
@@ -3317,7 +3317,7 @@ ixl_add_hw_filters(struct ixl_vsi *vsi, int flags, int
 	hw = &pf->hw;
 	IXL_PF_LOCK_ASSERT(pf);
 
-	a = malloc(sizeof(struct i40e_aqc_add_macvlan_element_data) * cnt,
+	a = mallocarray(cnt, sizeof(struct i40e_aqc_add_macvlan_element_data),
 	    M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (a == NULL) {
 		device_printf(dev, "add_hw_filters failed to get memory\n");
@@ -3380,7 +3380,8 @@ ixl_del_hw_filters(struct ixl_vsi *vsi, int cnt)
 	hw = &pf->hw;
 	dev = pf->dev;
 
-	d = malloc(sizeof(struct i40e_aqc_remove_macvlan_element_data) * cnt,
+	d = mallocarray(cnt,
+	    sizeof(struct i40e_aqc_remove_macvlan_element_data),
 	    M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (d == NULL) {
 		printf("del hw filter failed to get memory\n");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801111525.w0BFPQDn084190>