From: dhill Date: Tue, 11 Apr 2017 14:43:49 +0000 (+0000) Subject: Partially revert previous mallocarray conversions that contain X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=265a1ec57e702d97bc8bccd7cabf77bdfdd08787;p=openbsd Partially revert previous mallocarray conversions that contain constants. The consensus is that if both operands are constant, we don't need mallocarray. Reminded by tedu@ ok deraadt@ --- diff --git a/sys/dev/ic/aac.c b/sys/dev/ic/aac.c index b6188b64e65..996b32bc901 100644 --- a/sys/dev/ic/aac.c +++ b/sys/dev/ic/aac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aac.c,v 1.69 2017/04/09 18:07:19 dhill Exp $ */ +/* $OpenBSD: aac.c,v 1.70 2017/04/11 14:43:49 dhill Exp $ */ /*- * Copyright (c) 2000 Michael Smith @@ -1277,7 +1277,7 @@ aac_init(struct aac_softc *sc) /* Allocate some FIBs and associated command structs */ TAILQ_INIT(&sc->aac_fibmap_tqh); - sc->aac_commands = mallocarray(AAC_MAX_FIBS, sizeof(struct aac_command), + sc->aac_commands = malloc(AAC_MAX_FIBS * sizeof(struct aac_command), M_DEVBUF, M_WAITOK | M_ZERO); while (sc->total_fibs < AAC_MAX_FIBS) { if (aac_alloc_commands(sc) != 0) diff --git a/sys/dev/ic/adw.c b/sys/dev/ic/adw.c index baebe59b76a..c1efc7f0c13 100644 --- a/sys/dev/ic/adw.c +++ b/sys/dev/ic/adw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adw.c,v 1.53 2017/04/09 18:07:19 dhill Exp $ */ +/* $OpenBSD: adw.c,v 1.54 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: adw.c,v 1.23 2000/05/27 18:24:50 dante Exp $ */ /* @@ -144,7 +144,7 @@ adw_alloc_carriers(ADW_SOFTC *sc) * Allocate the control structure. */ sc->sc_control->carriers = - mallocarray(ADW_MAX_CARRIER, sizeof(ADW_CARRIER), M_DEVBUF, + malloc(ADW_MAX_CARRIER * sizeof(ADW_CARRIER), M_DEVBUF, M_NOWAIT); if (sc->sc_control->carriers == NULL) return (ENOMEM); diff --git a/sys/dev/ic/ath.c b/sys/dev/ic/ath.c index 3a0520da9f4..90f70a1a45d 100644 --- a/sys/dev/ic/ath.c +++ b/sys/dev/ic/ath.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ath.c,v 1.113 2017/04/09 18:07:19 dhill Exp $ */ +/* $OpenBSD: ath.c,v 1.114 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: ath.c,v 1.37 2004/08/18 21:59:39 dyoung Exp $ */ /*- @@ -2973,7 +2973,7 @@ ath_getchannels(struct ath_softc *sc, HAL_BOOL outdoor, HAL_BOOL xchanmode) int i, ix, nchan; sc->sc_nchan = 0; - chans = mallocarray(IEEE80211_CHAN_MAX, sizeof(HAL_CHANNEL), + chans = malloc(IEEE80211_CHAN_MAX * sizeof(HAL_CHANNEL), M_TEMP, M_NOWAIT); if (chans == NULL) { printf("%s: unable to allocate channel table\n", ifp->if_xname); diff --git a/sys/dev/pci/azalia.c b/sys/dev/pci/azalia.c index bea16a3005f..308e0adf462 100644 --- a/sys/dev/pci/azalia.c +++ b/sys/dev/pci/azalia.c @@ -1,4 +1,4 @@ -/* $OpenBSD: azalia.c,v 1.234 2017/04/09 18:16:00 dhill Exp $ */ +/* $OpenBSD: azalia.c,v 1.235 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: azalia.c,v 1.20 2006/05/07 08:31:44 kent Exp $ */ /*- @@ -1097,7 +1097,7 @@ azalia_init_rirb(azalia_t *az, int resuming) DPRINTF(("%s: RIRB allocation succeeded.\n", __func__)); /* setup the unsolicited response queue */ - az->unsolq = mallocarray(UNSOLQ_SIZE, sizeof(rirb_entry_t), + az->unsolq = malloc(sizeof(rirb_entry_t) * UNSOLQ_SIZE, M_DEVBUF, M_NOWAIT | M_ZERO); if (az->unsolq == NULL) { DPRINTF(("%s: can't allocate unsolicited response queue.\n", diff --git a/sys/dev/pci/if_dc_pci.c b/sys/dev/pci/if_dc_pci.c index ea5bcefdbe6..95a820313ce 100644 --- a/sys/dev/pci/if_dc_pci.c +++ b/sys/dev/pci/if_dc_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_dc_pci.c,v 1.75 2017/04/09 18:16:00 dhill Exp $ */ +/* $OpenBSD: if_dc_pci.c,v 1.76 2017/04/11 14:43:49 dhill Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -360,7 +360,7 @@ dc_pci_attach(struct device *parent, struct device *self, void *aux) sc->dc_type = DC_TYPE_PNIC; sc->dc_flags |= DC_TX_STORENFWD|DC_TX_INTR_ALWAYS; sc->dc_flags |= DC_PNIC_RX_BUG_WAR; - sc->dc_pnic_rx_buf = mallocarray(5, ETHER_MAX_DIX_LEN, + sc->dc_pnic_rx_buf = malloc(ETHER_MAX_DIX_LEN * 5, M_DEVBUF, M_NOWAIT); if (sc->dc_pnic_rx_buf == NULL) panic("dc_pci_attach"); diff --git a/sys/dev/pci/if_nep.c b/sys/dev/pci/if_nep.c index f22efe0d718..3104b8c63af 100644 --- a/sys/dev/pci/if_nep.c +++ b/sys/dev/pci/if_nep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_nep.c,v 1.29 2017/04/09 19:59:43 deraadt Exp $ */ +/* $OpenBSD: if_nep.c,v 1.30 2017/04/11 14:43:49 dhill Exp $ */ /* * Copyright (c) 2014, 2015 Mark Kettenis * @@ -1561,7 +1561,7 @@ nep_up(struct nep_softc *sc) return; sc->sc_rbdesc = NEP_DMA_KVA(sc->sc_rbring); - sc->sc_rb = mallocarray(NEP_NRBDESC, sizeof(struct nep_block), + sc->sc_rb = malloc(sizeof(struct nep_block) * NEP_NRBDESC, M_DEVBUF, M_WAITOK); for (i = 0; i < NEP_NRBDESC; i++) { rb = &sc->sc_rb[i]; @@ -1592,7 +1592,7 @@ nep_up(struct nep_softc *sc) goto free_rxmbox; sc->sc_txdesc = NEP_DMA_KVA(sc->sc_txring); - sc->sc_txbuf = mallocarray(NEP_NTXDESC, sizeof(struct nep_buf), + sc->sc_txbuf = malloc(sizeof(struct nep_buf) * NEP_NTXDESC, M_DEVBUF, M_WAITOK); for (i = 0; i < NEP_NTXDESC; i++) { txb = &sc->sc_txbuf[i]; diff --git a/sys/dev/usb/dwc2/dwc2_hcd.c b/sys/dev/usb/dwc2/dwc2_hcd.c index dee59662862..e42e6d427c4 100644 --- a/sys/dev/usb/dwc2/dwc2_hcd.c +++ b/sys/dev/usb/dwc2/dwc2_hcd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwc2_hcd.c,v 1.17 2017/04/09 18:09:41 dhill Exp $ */ +/* $OpenBSD: dwc2_hcd.c,v 1.18 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: dwc2_hcd.c,v 1.15 2014/11/24 10:14:14 skrll Exp $ */ /* @@ -2184,14 +2184,14 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, dev_dbg(hsotg->dev, "hcfg=%08x\n", DWC2_READ_4(hsotg, HCFG)); #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS - hsotg->frame_num_array = mallocarray(FRAME_NUM_ARRAY_SIZE, - sizeof(*hsotg->frame_num_array), - M_DEVBUF, M_ZERO | M_WAITOK); + hsotg->frame_num_array = malloc(sizeof(*hsotg->frame_num_array) * + FRAME_NUM_ARRAY_SIZE, M_DEVBUF, + M_ZERO | M_WAITOK); if (!hsotg->frame_num_array) goto error1; - hsotg->last_frame_num_array = mallocarray(FRAME_NUM_ARRAY_SIZE, - sizeof(*hsotg->last_frame_num_array), - M_DEVBUF, M_ZERO | M_WAITOK); + hsotg->last_frame_num_array = malloc( + sizeof(*hsotg->last_frame_num_array) * + FRAME_NUM_ARRAY_SIZE, M_DEVBUF, M_ZERO | M_WAITOK); if (!hsotg->last_frame_num_array) goto error1; hsotg->last_frame_num = HFNUM_MAX_FRNUM; diff --git a/sys/dev/wscons/wsemul_vt100.c b/sys/dev/wscons/wsemul_vt100.c index 6d90d906583..0e4ee7a93f9 100644 --- a/sys/dev/wscons/wsemul_vt100.c +++ b/sys/dev/wscons/wsemul_vt100.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100.c,v 1.34 2017/04/09 18:05:17 dhill Exp $ */ +/* $OpenBSD: wsemul_vt100.c,v 1.35 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: wsemul_vt100.c,v 1.13 2000/04/28 21:56:16 mycroft Exp $ */ /* @@ -222,10 +222,10 @@ wsemul_vt100_attach(int console, const struct wsscreen_descr *type, edp->dblwid = malloc(edp->nrows, M_DEVBUF, M_NOWAIT | M_ZERO); edp->dw = 0; edp->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT); - edp->isolatin1tab = mallocarray(128, sizeof(u_int), M_DEVBUF, M_NOWAIT); - edp->decgraphtab = mallocarray(128, sizeof(u_int), M_DEVBUF, M_NOWAIT); - edp->dectechtab = mallocarray(128, sizeof(u_int), M_DEVBUF, M_NOWAIT); - edp->nrctab = mallocarray(128, sizeof(u_int), M_DEVBUF, M_NOWAIT); + edp->isolatin1tab = malloc(128 * sizeof(u_int), M_DEVBUF, M_NOWAIT); + edp->decgraphtab = malloc(128 * sizeof(u_int), M_DEVBUF, M_NOWAIT); + edp->dectechtab = malloc(128 * sizeof(u_int), M_DEVBUF, M_NOWAIT); + edp->nrctab = malloc(128 * sizeof(u_int), M_DEVBUF, M_NOWAIT); vt100_initchartables(edp); wsemul_vt100_reset(edp); return (edp); diff --git a/sys/dev/wscons/wsevent.c b/sys/dev/wscons/wsevent.c index 37bbeb66172..52e0096440b 100644 --- a/sys/dev/wscons/wsevent.c +++ b/sys/dev/wscons/wsevent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsevent.c,v 1.16 2017/04/09 18:05:17 dhill Exp $ */ +/* $OpenBSD: wsevent.c,v 1.17 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: wsevent.c,v 1.16 2003/08/07 16:31:29 agc Exp $ */ /* @@ -109,7 +109,7 @@ wsevent_init(struct wseventvar *ev) return; } ev->get = ev->put = 0; - ev->q = mallocarray(WSEVENT_QSIZE, sizeof(struct wscons_event), + ev->q = malloc(WSEVENT_QSIZE * sizeof(struct wscons_event), M_DEVBUF, M_WAITOK | M_ZERO); } diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c index f8029836177..437dff36bde 100644 --- a/sys/net/if_pfsync.c +++ b/sys/net/if_pfsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pfsync.c,v 1.248 2017/04/09 17:57:58 dhill Exp $ */ +/* $OpenBSD: if_pfsync.c,v 1.249 2017/04/11 14:43:49 dhill Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff @@ -316,8 +316,8 @@ pfsync_clone_create(struct if_clone *ifc, int unit) sc->sc_len = PFSYNC_MINPKT; sc->sc_maxupdates = 128; - sc->sc_imo.imo_membership = (struct in_multi **)mallocarray( - IP_MIN_MEMBERSHIPS, sizeof(struct in_multi *), M_IPMOPTS, + sc->sc_imo.imo_membership = (struct in_multi **)malloc( + (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, M_WAITOK | M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c index a159df99d59..1f6928cd292 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vxlan.c,v 1.58 2017/04/09 17:57:58 dhill Exp $ */ +/* $OpenBSD: if_vxlan.c,v 1.59 2017/04/11 14:43:49 dhill Exp $ */ /* * Copyright (c) 2013 Reyk Floeter @@ -129,8 +129,8 @@ vxlan_clone_create(struct if_clone *ifc, int unit) M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) return (ENOMEM); - sc->sc_imo.imo_membership = mallocarray( - IP_MIN_MEMBERSHIPS, sizeof(struct in_multi *), M_IPMOPTS, + sc->sc_imo.imo_membership = malloc( + (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; sc->sc_dstport = htons(VXLAN_PORT); diff --git a/sys/net80211/ieee80211_input.c b/sys/net80211/ieee80211_input.c index 9645357ea19..8fd5a9cfa66 100644 --- a/sys/net80211/ieee80211_input.c +++ b/sys/net80211/ieee80211_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_input.c,v 1.190 2017/04/09 18:15:32 dhill Exp $ */ +/* $OpenBSD: ieee80211_input.c,v 1.191 2017/04/11 14:43:49 dhill Exp $ */ /*- * Copyright (c) 2001 Atsushi Onoe @@ -2566,7 +2566,7 @@ ieee80211_recv_addba_req(struct ieee80211com *ic, struct mbuf *m, ba->ba_winstart = ssn; ba->ba_winend = (ba->ba_winstart + ba->ba_winsize - 1) & 0xfff; /* allocate and setup our reordering buffer */ - ba->ba_buf = mallocarray(IEEE80211_BA_MAX_WINSZ, sizeof(*ba->ba_buf), + ba->ba_buf = malloc(IEEE80211_BA_MAX_WINSZ * sizeof(*ba->ba_buf), M_DEVBUF, M_NOWAIT | M_ZERO); if (ba->ba_buf == NULL) goto refuse; diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 59ad35dc44b..ee7846d2013 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.306 2017/04/09 17:57:58 dhill Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.307 2017/04/11 14:43:49 dhill Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -795,8 +795,8 @@ carp_clone_create(struct if_clone *ifc, int unit) #ifdef INET6 sc->sc_im6o.im6o_hlim = CARP_DFLTTL; #endif /* INET6 */ - sc->sc_imo.imo_membership = (struct in_multi **)mallocarray( - IP_MIN_MEMBERSHIPS, sizeof(struct in_multi *), M_IPMOPTS, + sc->sc_imo.imo_membership = (struct in_multi **)malloc( + (sizeof(struct in_multi *) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 3802b834142..da223746a4e 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.337 2017/04/09 17:57:58 dhill Exp $ */ +/* $OpenBSD: ip_output.c,v 1.338 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -1344,8 +1344,8 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m, * allocate one and initialize to default values. */ imo = malloc(sizeof(*imo), M_IPMOPTS, M_WAITOK|M_ZERO); - immp = (struct in_multi **)mallocarray( - IP_MIN_MEMBERSHIPS, sizeof(*immp), M_IPMOPTS, + immp = (struct in_multi **)malloc( + (sizeof(*immp) * IP_MIN_MEMBERSHIPS), M_IPMOPTS, M_WAITOK|M_ZERO); *imop = imo; imo->imo_ifidx = 0; diff --git a/sys/ntfs/ntfs_subr.c b/sys/ntfs/ntfs_subr.c index 641ff218209..4e9a071b158 100644 --- a/sys/ntfs/ntfs_subr.c +++ b/sys/ntfs/ntfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntfs_subr.c,v 1.49 2017/04/09 18:15:09 dhill Exp $ */ +/* $OpenBSD: ntfs_subr.c,v 1.50 2017/04/11 14:43:49 dhill Exp $ */ /* $NetBSD: ntfs_subr.c,v 1.4 2003/04/10 21:37:32 jdolecek Exp $ */ /*- @@ -1754,7 +1754,7 @@ ntfs_toupper_use(struct mount *mp, struct ntfsmount *ntmp, struct proc *p) * XXX for now, just the first 256 entries are used anyway, * so don't bother reading more */ - ntfs_toupper_tab = mallocarray(256 * 256, sizeof(wchar), M_NTFSRDATA, + ntfs_toupper_tab = malloc(256 * 256 * sizeof(wchar), M_NTFSRDATA, M_WAITOK); if ((error = VFS_VGET(mp, NTFS_UPCASEINO, &vp)))