diff options
author | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-09-08 04:28:35 +0000 |
---|---|---|
committer | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-09-08 04:28:35 +0000 |
commit | 16414ff834b8904432e33c05c8a65a2fa7c5a44a (patch) | |
tree | 51a4c713152e9967b61812805844cf6a80bbd624 /sys/arch | |
parent | 751a0fce1083a787f8b3a4a3622a921951968a29 (diff) |
convert several malloc(9) to mallocarray(9).
ok deraadt@ guenther@ "re-wrap the long lines" kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/amd64/amd64/est.c | 6 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/mem.c | 7 | ||||
-rw-r--r-- | sys/arch/i386/i386/esm.c | 10 | ||||
-rw-r--r-- | sys/arch/i386/i386/est.c | 6 | ||||
-rw-r--r-- | sys/arch/i386/i386/k6_mem.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/i386/mem.c | 7 | ||||
-rw-r--r-- | sys/arch/i386/pci/pcibios.c | 4 |
7 files changed, 21 insertions, 23 deletions
diff --git a/sys/arch/amd64/amd64/est.c b/sys/arch/amd64/amd64/est.c index 7f9900485a0..2e0b1c16524 100644 --- a/sys/arch/amd64/amd64/est.c +++ b/sys/arch/amd64/amd64/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.37 2015/08/28 00:03:53 deraadt Exp $ */ +/* $OpenBSD: est.c,v 1.38 2015/09/08 04:28:34 semarie Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -379,8 +379,8 @@ est_init(struct cpu_info *ci) } - if ((fake_table = malloc(sizeof(struct est_op) * 3, M_DEVBUF, - M_NOWAIT)) == NULL) { + if ((fake_table = mallocarray(3, sizeof(struct est_op), + M_DEVBUF, M_NOWAIT)) == NULL) { free(fake_fqlist, M_DEVBUF, sizeof(struct fqlist)); printf("%s: EST: cannot allocate memory for fake " "table\n", cpu_device); diff --git a/sys/arch/amd64/amd64/mem.c b/sys/arch/amd64/amd64/mem.c index 66dd603c77f..4f22d1f2760 100644 --- a/sys/arch/amd64/amd64/mem.c +++ b/sys/arch/amd64/amd64/mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mem.c,v 1.27 2015/08/29 12:30:30 sthen Exp $ */ +/* $OpenBSD: mem.c,v 1.28 2015/09/08 04:28:34 semarie Exp $ */ /* * Copyright (c) 1988 University of Utah. * Copyright (c) 1982, 1986, 1990, 1993 @@ -278,9 +278,8 @@ mem_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p) case MEMRANGE_GET: nd = imin(mo->mo_arg[0], mem_range_softc.mr_ndesc); if (nd > 0) { - md = (struct mem_range_desc *) - malloc(nd * sizeof(struct mem_range_desc), - M_MEMDESC, M_WAITOK); + md = mallocarray(nd, sizeof(struct mem_range_desc), + M_MEMDESC, M_WAITOK); error = mem_range_attr_get(md, &nd); if (!error) error = copyout(md, mo->mo_desc, diff --git a/sys/arch/i386/i386/esm.c b/sys/arch/i386/i386/esm.c index 0f3e9f1fc43..a47b821ee39 100644 --- a/sys/arch/i386/i386/esm.c +++ b/sys/arch/i386/i386/esm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: esm.c,v 1.57 2014/12/10 12:27:56 mikeb Exp $ */ +/* $OpenBSD: esm.c,v 1.58 2015/09/08 04:28:34 semarie Exp $ */ /* * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> @@ -885,8 +885,8 @@ esm_make_sensors(struct esm_softc *sc, struct esm_devmap *devmap, * go through these hoops to deal with it. */ nsensors = 4; - s = malloc(sizeof(struct ksensor) * nsensors, M_DEVBUF, - M_NOWAIT|M_ZERO); + s = mallocarray(nsensors, sizeof(struct ksensor), + M_DEVBUF, M_NOWAIT|M_ZERO); if (s == NULL) { free(es, M_DEVBUF, 0); return; @@ -903,8 +903,8 @@ esm_make_sensors(struct esm_softc *sc, struct esm_devmap *devmap, * this expands it out to 6 separate indicators */ nsensors = 6; - s = malloc(sizeof(struct ksensor) * nsensors, M_DEVBUF, - M_NOWAIT|M_ZERO); + s = mallocarray(nsensors, sizeof(struct ksensor), + M_DEVBUF, M_NOWAIT|M_ZERO); if (s == NULL) { free(es, M_DEVBUF, 0); return; diff --git a/sys/arch/i386/i386/est.c b/sys/arch/i386/i386/est.c index b0d79efb15a..d45230efe35 100644 --- a/sys/arch/i386/i386/est.c +++ b/sys/arch/i386/i386/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.45 2014/12/09 06:58:28 doug Exp $ */ +/* $OpenBSD: est.c,v 1.46 2015/09/08 04:28:34 semarie Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -1139,8 +1139,8 @@ est_init(struct cpu_info *ci, int vendor) } - if ((fake_table = malloc(sizeof(struct est_op) * 3, M_DEVBUF, - M_NOWAIT)) == NULL) { + if ((fake_table = mallocarray(3, sizeof(struct est_op), + M_DEVBUF, M_NOWAIT)) == NULL) { free(fake_fqlist, M_DEVBUF, 0); printf("%s: EST: cannot allocate memory for fake " "table\n", cpu_device); diff --git a/sys/arch/i386/i386/k6_mem.c b/sys/arch/i386/i386/k6_mem.c index b0d3b402a06..84a0f34696d 100644 --- a/sys/arch/i386/i386/k6_mem.c +++ b/sys/arch/i386/i386/k6_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: k6_mem.c,v 1.11 2010/02/23 21:54:53 kettenis Exp $ */ +/* $OpenBSD: k6_mem.c,v 1.12 2015/09/08 04:28:34 semarie Exp $ */ /*- * Copyright (c) 1999 Brian Fundakowski Feldman * All rights reserved. @@ -103,7 +103,7 @@ k6_mrinit(struct mem_range_softc *sc) sc->mr_cap = 0; sc->mr_ndesc = 2; /* XXX (BFF) For now, we only have one msr for this */ - sc->mr_desc = malloc(sc->mr_ndesc * sizeof(struct mem_range_desc), + sc->mr_desc = mallocarray(sc->mr_ndesc, sizeof(struct mem_range_desc), M_MEMDESC, M_NOWAIT|M_ZERO); if (sc->mr_desc == NULL) panic("k6_mrinit: malloc returns NULL"); diff --git a/sys/arch/i386/i386/mem.c b/sys/arch/i386/i386/mem.c index d6cb3aa1879..736c8b52d7f 100644 --- a/sys/arch/i386/i386/mem.c +++ b/sys/arch/i386/i386/mem.c @@ -1,5 +1,5 @@ /* $NetBSD: mem.c,v 1.31 1996/05/03 19:42:19 christos Exp $ */ -/* $OpenBSD: mem.c,v 1.45 2015/06/22 18:57:26 kettenis Exp $ */ +/* $OpenBSD: mem.c,v 1.46 2015/09/08 04:28:34 semarie Exp $ */ /* * Copyright (c) 1988 University of Utah. * Copyright (c) 1982, 1986, 1990, 1993 @@ -294,9 +294,8 @@ mem_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p) case MEMRANGE_GET: nd = imin(mo->mo_arg[0], mem_range_softc.mr_ndesc); if (nd > 0) { - md = (struct mem_range_desc *) - malloc(nd * sizeof(struct mem_range_desc), - M_MEMDESC, M_WAITOK); + md = mallocarray(nd, sizeof(struct mem_range_desc), + M_MEMDESC, M_WAITOK); error = mem_range_attr_get(md, &nd); if (!error) error = copyout(md, mo->mo_desc, diff --git a/sys/arch/i386/pci/pcibios.c b/sys/arch/i386/pci/pcibios.c index 39c824d4824..87edc29ebdf 100644 --- a/sys/arch/i386/pci/pcibios.c +++ b/sys/arch/i386/pci/pcibios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcibios.c,v 1.46 2015/07/17 21:36:56 mlarkin Exp $ */ +/* $OpenBSD: pcibios.c,v 1.47 2015/09/08 04:28:34 semarie Exp $ */ /* $NetBSD: pcibios.c,v 1.5 2000/08/01 05:23:59 uch Exp $ */ /* @@ -310,7 +310,7 @@ pcibios_pir_init(struct pcibios_softc *sc) if (pcibios_pir_table == NULL) { pcibios_pir_table_nentries = 32; - pcibios_pir_table = malloc(pcibios_pir_table_nentries * + pcibios_pir_table = mallocarray(pcibios_pir_table_nentries, sizeof(*pcibios_pir_table), M_DEVBUF, M_NOWAIT); if (pcibios_pir_table == NULL) { printf("%s: no memory for $PIR\n", sc->sc_dev.dv_xname); |