Date: Sat, 13 Jan 2018 16:17:20 -0800 From: Cy Schubert <Cy.Schubert@cschubert.com> To: "Pedro F. Giffuni" <pfg@FreeBSD.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r327949 - in head/sys/dev: aacraid advansys ath beri/virtio bnxt bwn ciss cxgbe/crypto esp fb gpio if_ndis iwi kbd liquidio liquidio/base mpr mps mpt mrsas mxge netmap nvme pst ral rp s... Message-ID: <201801140017.w0E0HKS3049183@slippy.cwsent.com> In-Reply-To: Message from "Pedro F. Giffuni" <pfg@FreeBSD.org> of "Sat, 13 Jan 2018 22:30:31 %2B0000." <201801132230.w0DMUVmF081985@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <201801132230.w0DMUVmF081985@repo.freebsd.org>, "Pedro F. Giffuni" w rites: > Author: pfg > Date: Sat Jan 13 22:30:30 2018 > New Revision: 327949 > URL: https://svnweb.freebsd.org/changeset/base/327949 > > Log: > dev: make some use of mallocarray(9). > > Focus on code where we are doing multiplications within malloc(9). None of > these is likely to overflow, however the change is still useful as some > static checkers can benefit from the allocation attributes we use for > mallocarray. > > This initial sweep only covers malloc(9) calls with M_NOWAIT. No good > reason but I started doing the changes before r327796 and at that time it > was convenient to make sure the sorrounding code could handle NULL values. > > Modified: > head/sys/dev/aacraid/aacraid.c > head/sys/dev/advansys/advansys.c > head/sys/dev/ath/if_ath_rx_edma.c > head/sys/dev/beri/virtio/virtio.c > head/sys/dev/bnxt/if_bnxt.c > head/sys/dev/bwn/if_bwn.c > head/sys/dev/bwn/if_bwn_phy_lp.c > head/sys/dev/ciss/ciss.c > head/sys/dev/cxgbe/crypto/t4_crypto.c > head/sys/dev/esp/ncr53c9x.c > head/sys/dev/fb/splash.c > head/sys/dev/gpio/gpiobus.c > head/sys/dev/if_ndis/if_ndis.c > head/sys/dev/iwi/if_iwi.c > head/sys/dev/kbd/kbd.c > head/sys/dev/liquidio/base/lio_request_manager.c > head/sys/dev/liquidio/lio_main.c > head/sys/dev/mpr/mpr.c > head/sys/dev/mpr/mpr_mapping.c > head/sys/dev/mps/mps.c > head/sys/dev/mps/mps_mapping.c > head/sys/dev/mpt/mpt_cam.c > head/sys/dev/mrsas/mrsas.c > head/sys/dev/mxge/if_mxge.c > head/sys/dev/netmap/if_ptnet.c > head/sys/dev/nvme/nvme_ns.c > head/sys/dev/pst/pst-iop.c > head/sys/dev/ral/rt2560.c > head/sys/dev/ral/rt2661.c > head/sys/dev/rp/rp.c > head/sys/dev/rp/rp_isa.c > head/sys/dev/rp/rp_pci.c > head/sys/dev/sound/midi/midi.c > head/sys/dev/sound/pci/hda/hdaa.c > head/sys/dev/syscons/fire/fire_saver.c > head/sys/dev/virtio/console/virtio_console.c > head/sys/dev/virtio/mmio/virtio_mmio.c > head/sys/dev/virtio/network/if_vtnet.c > head/sys/dev/virtio/pci/virtio_pci.c > head/sys/dev/vmware/vmxnet3/if_vmx.c > head/sys/dev/vnic/nicvf_queues.c > head/sys/dev/xen/blkback/blkback.c > head/sys/dev/xen/blkfront/blkfront.c > > Modified: head/sys/dev/mxge/if_mxge.c > ============================================================================= > = > --- head/sys/dev/mxge/if_mxge.c Sat Jan 13 21:39:46 2018 (r32794 > 8) > +++ head/sys/dev/mxge/if_mxge.c Sat Jan 13 22:30:30 2018 (r32794 > 9) > @@ -688,7 +688,7 @@ z_alloc(void *nil, u_int items, u_int size) > { > void *ptr; > > - ptr = malloc(items * size, M_TEMP, M_NOWAIT); > + ptr = mallocarray(items, size, M_TEMP, M_NOWAIT); > return ptr; > } > > @@ -4390,8 +4390,8 @@ mxge_alloc_slices(mxge_softc_t *sc) > sc->rx_ring_size = cmd.data0; > max_intr_slots = 2 * (sc->rx_ring_size / sizeof (mcp_dma_addr_t)); > > - bytes = sizeof (*sc->ss) * sc->num_slices; Hi Pedro, This broke the build. > - sc->ss = malloc(bytes, M_DEVBUF, M_NOWAIT | M_ZERO); > + sc->ss = mallocarray(sc->num_slices, sizeof(*sc->ss), M_DEVBUF, > + M_NOWAIT | M_ZERO); > if (sc->ss == NULL) > return (ENOMEM); > for (i = 0; i < sc->num_slices; i++) { > @@ -4563,8 +4563,8 @@ mxge_add_msix_irqs(mxge_softc_t *sc) > err = ENOSPC; > goto abort_with_msix; > } > - bytes = sizeof (*sc->msix_irq_res) * sc->num_slices; > - sc->msix_irq_res = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO); > + sc->msix_irq_res = mallocarray(sc->num_slices, > + sizeof(*sc->msix_irq_res), M_DEVBUF, M_NOWAIT|M_ZERO); > if (sc->msix_irq_res == NULL) { > err = ENOMEM; > goto abort_with_msix; > @@ -4583,8 +4583,8 @@ mxge_add_msix_irqs(mxge_softc_t *sc) > } > } > > - bytes = sizeof (*sc->msix_ih) * sc->num_slices; ===> mxge/mxge_rss_ethp_z8e (all) --- all_subdir_mxge/mxge --- /opt/src/svn-current/sys/dev/mxge/if_mxge.c:4538:9: error: unused variable 'bytes' [-Werror,-Wunused-variable] size_t bytes; ^ 1 error generated. *** [if_mxge.o] Error code 1 > - sc->msix_ih = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO); > + sc->msix_ih = mallocarray(sc->num_slices, sizeof(*sc->msix_ih), > + M_DEVBUF, M_NOWAIT|M_ZERO); > > for (i = 0; i < sc->num_slices; i++) { > err = bus_setup_intr(sc->dev, sc->msix_irq_res[i], > -- Cheers, Cy Schubert <Cy.Schubert@cschubert.com> FreeBSD UNIX: <cy@FreeBSD.org> Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801140017.w0E0HKS3049183>