Date: Mon, 15 Jan 2018 21:13:30 +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: r328020 - in head/sys/mips: mips nlm/dev/sec Message-ID: <201801152113.w0FLDUUn065783@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Mon Jan 15 21:13:30 2018 New Revision: 328020 URL: https://svnweb.freebsd.org/changeset/base/328020 Log: mips: make some use of mallocarray(9). Focus on code where we are doing multiplications within malloc(9). None of these ire 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. X-Differential revision: https://reviews.freebsd.org/D13837 Modified: head/sys/mips/mips/busdma_machdep.c head/sys/mips/nlm/dev/sec/nlmrsa.c Modified: head/sys/mips/mips/busdma_machdep.c ============================================================================== --- head/sys/mips/mips/busdma_machdep.c Mon Jan 15 21:11:38 2018 (r328019) +++ head/sys/mips/mips/busdma_machdep.c Mon Jan 15 21:13:30 2018 (r328020) @@ -345,7 +345,8 @@ _busdma_alloc_dmamap(bus_dma_tag_t dmat) struct sync_list *slist; bus_dmamap_t map; - slist = malloc(sizeof(*slist) * dmat->nsegments, M_BUSDMA, M_NOWAIT); + slist = mallocarray(dmat->nsegments, sizeof(*slist), M_BUSDMA, + M_NOWAIT); if (slist == NULL) return (NULL); map = uma_zalloc_arg(dmamap_zone, dmat, M_NOWAIT); @@ -534,9 +535,8 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_d int error = 0; if (dmat->segments == NULL) { - dmat->segments = (bus_dma_segment_t *)malloc( - sizeof(bus_dma_segment_t) * dmat->nsegments, M_BUSDMA, - M_NOWAIT); + dmat->segments = (bus_dma_segment_t *)malloc(dmat->nsegments, + sizeof(bus_dma_segment_t), M_BUSDMA, M_NOWAIT); if (dmat->segments == NULL) { CTR3(KTR_BUSDMA, "%s: tag %p error %d", __func__, dmat, ENOMEM); @@ -647,9 +647,8 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddrp, in else mflags = M_WAITOK; if (dmat->segments == NULL) { - dmat->segments = (bus_dma_segment_t *)malloc( - sizeof(bus_dma_segment_t) * dmat->nsegments, M_BUSDMA, - mflags); + dmat->segments = (bus_dma_segment_t *)malloc(dmat->nsegments, + sizeof(bus_dma_segment_t), M_BUSDMA, mflags); if (dmat->segments == NULL) { CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", __func__, dmat, dmat->flags, ENOMEM); Modified: head/sys/mips/nlm/dev/sec/nlmrsa.c ============================================================================== --- head/sys/mips/nlm/dev/sec/nlmrsa.c Mon Jan 15 21:11:38 2018 (r328019) +++ head/sys/mips/nlm/dev/sec/nlmrsa.c Mon Jan 15 21:13:30 2018 (r328020) @@ -346,7 +346,7 @@ xlp_rsa_newsession(device_t dev, u_int32_t *sidp, stru if (ses == NULL) { sesn = sc->sc_nsessions; - ses = malloc((sesn + 1) * sizeof(*ses), + ses = mallocarray(sesn + 1, sizeof(*ses), M_DEVBUF, M_NOWAIT); if (ses == NULL) return (ENOMEM); @@ -528,8 +528,9 @@ xlp_rsa_kprocess(device_t dev, struct cryptkop *krp, i goto errout; } cmd->rsafn = 0; /* Mod Exp */ - cmd->rsasrc = malloc( - cmd->rsaopsize * (krp->krp_iparams + krp->krp_oparams), + cmd->rsasrc = mallocarray( + krp->krp_iparams + krp->krp_oparams, + cmd->rsaopsize, M_DEVBUF, M_NOWAIT | M_ZERO); if (cmd->rsasrc == NULL) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801152113.w0FLDUUn065783>