malloc cleanups:

- malloc+memset -> malloc with M_ZERO
- malloc -> MALLOC for fixed-sized structures
Add RCSIDs while here
This commit is contained in:
gmcgarry 2002-03-15 05:52:53 +00:00
parent 1cb254edf6
commit d4c41b0f8b
10 changed files with 70 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ac.c,v 1.13 2001/12/08 03:34:38 gmcgarry Exp $ */
/* $NetBSD: ac.c,v 1.14 2002/03/15 05:52:53 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -87,6 +87,9 @@
* never uses it.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ac.c,v 1.14 2002/03/15 05:52:53 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
@ -162,12 +165,14 @@ acattach(parent, self, aux)
sc->sc_sq.sq_go = acgo;
sc->sc_sq.sq_intr = acintr;
sc->sc_bp = (struct buf *)malloc(sizeof(struct buf),
MALLOC(sc->sc_bp, struct buf *, sizeof(struct buf), M_DEVBUF, M_NOWAIT);
if (sc->sc_bp == NULL) {
printf("%s: memory allocation failed\n", sc->sc_dev.dv_xname);
return;
}
MALLOC(sc->sc_cmd, struct scsi_fmt_cdb *, sizeof(struct scsi_fmt_cdb),
M_DEVBUF, M_NOWAIT);
sc->sc_cmd = (struct scsi_fmt_cdb *)malloc(sizeof(struct scsi_fmt_cdb),
M_DEVBUF, M_NOWAIT);
if (sc->sc_bp == NULL || sc->sc_cmd == NULL) {
if (sc->sc_cmd == NULL) {
printf("%s: memory allocation failed\n", sc->sc_dev.dv_xname);
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: grf.c,v 1.42 2001/12/26 19:08:11 thorpej Exp $ */
/* $NetBSD: grf.c,v 1.43 2002/03/15 05:52:53 gmcgarry Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -48,6 +48,9 @@
* Hardware access is through the machine dependent grf switch routines.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.43 2002/03/15 05:52:53 gmcgarry Exp $");
#include "opt_compat_hpux.h"
#include <sys/param.h>
@ -711,11 +714,9 @@ grffindpid(gp)
int i, limit;
int ni;
if (gp->g_pid == NULL) {
gp->g_pid = (short *)
malloc(GRFMAXLCK * sizeof(short), M_DEVBUF, M_WAITOK);
memset((caddr_t)gp->g_pid, 0, GRFMAXLCK * sizeof(short));
}
if (gp->g_pid == NULL)
MALLOC(gp->g_pid, short *, GRFMAXLCK*sizeof(short),
M_DEVBUF, M_WAITOK | M_ZERO);
pid = curproc->p_pid;
ni = limit = gp->g_pid[0];
for (i = 1, sp = &gp->g_pid[1]; i <= limit; i++, sp++) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: grf_subr.c,v 1.7 2001/12/14 08:34:28 gmcgarry Exp $ */
/* $NetBSD: grf_subr.c,v 1.8 2002/03/15 05:52:54 gmcgarry Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -40,6 +40,9 @@
* Subroutines common to all framebuffer devices.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grf_subr.c,v 1.8 2002/03/15 05:52:54 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@ -66,15 +69,13 @@ grfdev_attach(sc, init, regs, sw)
if (sc->sc_isconsole)
sc->sc_data = gp = &grf_cn;
else {
sc->sc_data = gp =
(struct grf_data *)malloc(sizeof(struct grf_data),
M_DEVBUF, M_NOWAIT);
MALLOC(sc->sc_data, struct grf_data *, sizeof(struct grf_data),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (sc->sc_data == NULL) {
printf("\n%s: can't allocate grf data\n",
sc->sc_dev.dv_xname);
return;
}
memset(sc->sc_data, 0, sizeof(struct grf_data));
/* Initialize the framebuffer hardware. */
if ((*init)(sc->sc_data, sc->sc_scode, regs) == 0) {
@ -84,6 +85,7 @@ grfdev_attach(sc, init, regs, sw)
return;
}
gp = sc->sc_data;
gp->g_flags = GF_ALIVE;
gp->g_sw = sw;
gp->g_display.gd_id = gp->g_sw->gd_swid;

View File

@ -1,4 +1,4 @@
/* $NetBSD: hpib.c,v 1.19 1998/01/12 18:31:00 thorpej Exp $ */
/* $NetBSD: hpib.c,v 1.20 2002/03/15 05:52:54 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -75,6 +75,9 @@
* HP-IB bus driver
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: hpib.c,v 1.20 2002/03/15 05:52:54 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
@ -172,7 +175,7 @@ hpibbusattach(parent, self, aux)
/*
* Initialize the DMA queue entry.
*/
sc->sc_dq = (struct dmaqueue *)malloc(sizeof(struct dmaqueue),
MALLOC(sc->sc_dq, struct dmaqueue *, sizeof(struct dmaqueue),
M_DEVBUF, M_NOWAIT);
if (sc->sc_dq == NULL) {
printf("%s: can't allocate DMA queue entry\n", self->dv_xname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtc.c,v 1.2 2001/11/17 23:48:15 gmcgarry Exp $ */
/* $NetBSD: rtc.c,v 1.3 2002/03/15 05:52:54 gmcgarry Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -46,6 +46,9 @@
* attachment for HP300 real-time clock (RTC)
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.3 2002/03/15 05:52:54 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
@ -110,8 +113,8 @@ rtcattach(parent, self, aux)
return;
}
todr_handle = malloc(sizeof(struct todr_chip_handle),
M_DEVBUF, M_NOWAIT);
MALLOC(todr_handle, struct todr_chip_handle *,
sizeof(struct todr_chip_handle), M_DEVBUF, M_NOWAIT);
todr_handle->cookie = sc;
todr_handle->todr_gettime = rtc_gettime;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sd.c,v 1.49 2002/03/05 00:34:14 simonb Exp $ */
/* $NetBSD: sd.c,v 1.50 2002/03/15 05:52:54 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -78,6 +78,9 @@
* SCSI CCS (Command Command Set) disk driver.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.50 2002/03/15 05:52:54 gmcgarry Exp $");
#include "rnd.h"
#include "opt_useleds.h"
@ -631,13 +634,15 @@ sdlblkstrat(bp, bsize)
int bsize;
{
struct sd_softc *sc = sd_cd.cd_devs[sdunit(bp->b_dev)];
struct buf *cbp = (struct buf *)malloc(sizeof(struct buf),
M_DEVBUF, M_WAITOK);
caddr_t cbuf = (caddr_t)malloc(bsize, M_DEVBUF, M_WAITOK);
struct buf *cbp;
caddr_t cbuf;
int bn, resid;
caddr_t addr;
memset((caddr_t)cbp, 0, sizeof(*cbp));
MALLOC(cbp, struct buf *, sizeof(struct buf), M_DEVBUF,
M_WAITOK | M_ZERO);
cbuf = (caddr_t)malloc(bsize, M_DEVBUF, M_WAITOK);
cbp->b_proc = curproc; /* XXX */
cbp->b_dev = bp->b_dev;
bn = bp->b_blkno;

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.55 2002/03/04 02:25:21 simonb Exp $ */
/* $NetBSD: autoconf.c,v 1.56 2002/03/15 05:52:54 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -98,6 +98,9 @@
* and the drivers are initialized.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.56 2002/03/15 05:52:54 gmcgarry Exp $");
#include "hil.h"
#include "dvbox.h"
#include "gbox.h"
@ -401,11 +404,11 @@ device_register(dev, aux)
* Note that we only really care about devices that
* we can mount as root.
*/
dd = (struct dev_data *)malloc(sizeof(struct dev_data),
M_DEVBUF, M_NOWAIT);
MALLOC(dd, struct dev_data *, sizeof(struct dev_data),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (dd == NULL)
panic("device_register: can't allocate dev_data");
memset(dd, 0, sizeof(struct dev_data));
dd->dd_dev = dev;

View File

@ -1,4 +1,4 @@
/* $NetBSD: intr.c,v 1.21 2002/02/10 00:42:15 gmcgarry Exp $ */
/* $NetBSD: intr.c,v 1.22 2002/03/15 05:52:55 gmcgarry Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc.
@ -40,6 +40,9 @@
* Link and dispatch interrupts.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.22 2002/03/15 05:52:55 gmcgarry Exp $");
#define _HP300_INTR_H_PRIVATE
#include <sys/param.h>
@ -198,7 +201,7 @@ intr_establish(func, arg, ipl, priority)
if ((ipl < 0) || (ipl >= NISR))
panic("intr_establish: bad ipl %d", ipl);
newih = (struct hp300_intrhand *)malloc(sizeof(struct hp300_intrhand),
MALLOC(newih, struct hp300_intrhand *, sizeof(struct hp300_intrhand),
M_DEVBUF, M_NOWAIT);
if (newih == NULL)
panic("intr_establish: can't allocate space for handler");

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem.c,v 1.35 2002/02/27 01:20:52 christos Exp $ */
/* $NetBSD: mem.c,v 1.36 2002/03/15 05:52:55 gmcgarry Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -44,6 +44,9 @@
* Memory special file
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.36 2002/03/15 05:52:55 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
@ -177,9 +180,8 @@ mmrw(dev, uio, flags)
* of memory for use with /dev/zero.
*/
if (devzeropage == NULL) {
devzeropage = (caddr_t)
malloc(NBPG, M_TEMP, M_WAITOK);
memset(devzeropage, 0, NBPG);
MALLOC(devzeropage, caddr_t, NBPG, M_TEMP,
M_WAITOK | M_ZERO);
}
c = min(iov->iov_len, NBPG);
error = uiomove(devzeropage, c, uio);

View File

@ -1,4 +1,4 @@
/* $NetBSD: softintr.c,v 1.1 2001/12/08 04:12:37 gmcgarry Exp $ */
/* $NetBSD: softintr.c,v 1.2 2002/03/15 05:52:54 gmcgarry Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -41,6 +41,9 @@
* Based heavily on the alpha implementation by Jason Thorpe.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: softintr.c,v 1.2 2002/03/15 05:52:54 gmcgarry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
@ -142,7 +145,8 @@ softintr_establish(int ipl, void (*func)(void *), void *arg)
hsi = &hp300_soft_intrs[ipl];
sih = malloc(sizeof(*sih), M_DEVBUF, M_NOWAIT);
MALLOC(sih, struct hp300_soft_intrhand *,
sizeof(struct hp300_soft_intrhand), M_DEVBUF, M_NOWAIT);
if (__predict_true(sih != NULL)) {
sih->sih_intrhead = hsi;
sih->sih_fn = func;