Skip to content

Commit

Permalink
Retire the MALLOC and FREE macros. They are an abomination unto style…
Browse files Browse the repository at this point in the history
…(9).

MFC after:	3 months
  • Loading branch information
dag-erling committed Oct 23, 2008
1 parent a779c60 commit 66f807e
Show file tree
Hide file tree
Showing 217 changed files with 1,001 additions and 1,073 deletions.
4 changes: 4 additions & 0 deletions Makefile.inc1
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,14 @@ buildkernel:
@echo "--------------------------------------------------------------"
cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
.endif
.if !defined(NO_KERNELOBJ)
@echo
@echo "--------------------------------------------------------------"
@echo ">>> stage 2.2: rebuilding the object tree"
@echo "--------------------------------------------------------------"
cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
.endif
.if !defined(NO_KERNELTOOLS)
@echo
@echo "--------------------------------------------------------------"
@echo ">>> stage 2.3: build tools"
Expand All @@ -779,6 +782,7 @@ buildkernel:
${MAKE} -DWITHOUT_SSP -DNO_CPU_CFLAGS -DNO_CTF ${target}
.endfor
.endif
.endif
.if !defined(NO_KERNELDEPEND)
@echo
@echo "--------------------------------------------------------------"
Expand Down
4 changes: 1 addition & 3 deletions share/man/man9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,7 @@ MLINKS+=LOCK_PROFILING.9 MUTEX_PROFILING.9
MLINKS+=make_dev.9 destroy_dev.9 \
make_dev.9 dev_depends.9 \
make_dev.9 make_dev_alias.9
MLINKS+=malloc.9 FREE.9 \
malloc.9 free.9 \
malloc.9 MALLOC.9 \
MLINKS+=malloc.9 free.9 \
malloc.9 MALLOC_DECLARE.9 \
malloc.9 MALLOC_DEFINE.9 \
malloc.9 realloc.9 \
Expand Down
22 changes: 2 additions & 20 deletions share/man/man9/malloc.9
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@
.\" $NetBSD: malloc.9,v 1.3 1996/11/11 00:05:11 lukem Exp $
.\" $FreeBSD$
.\"
.Dd June 12, 2003
.Dd October 23, 2008
.Dt MALLOC 9
.Os
.Sh NAME
.Nm malloc ,
.Nm MALLOC ,
.Nm free ,
.Nm FREE ,
.Nm realloc ,
.Nm reallocf ,
.Nm MALLOC_DEFINE ,
Expand All @@ -54,10 +52,8 @@
.In sys/malloc.h
.Ft void *
.Fn malloc "unsigned long size" "struct malloc_type *type" "int flags"
.Fn MALLOC space cast "unsigned long size" "struct malloc_type *type" "int flags"
.Ft void
.Fn free "void *addr" "struct malloc_type *type"
.Fn FREE "void *addr" "struct malloc_type *type"
.Ft void *
.Fn realloc "void *addr" "unsigned long size" "struct malloc_type *type" "int flags"
.Ft void *
Expand Down Expand Up @@ -123,20 +119,6 @@ function is identical to
except that it
will free the passed pointer when the requested memory cannot be allocated.
.Pp
The
.Fn MALLOC
macro variant is functionally equivalent to
.Bd -literal -offset indent
(space) = (cast)malloc((u_long)(size), type, flags)
.Ed
.Pp
and the
.Fn FREE
macro variant is equivalent to
.Bd -literal -offset indent
free((addr), type)
.Ed
.Pp
Unlike its standard C library counterpart
.Pq Xr malloc 3 ,
the kernel version takes two more arguments.
Expand Down Expand Up @@ -219,7 +201,7 @@ MALLOC_DEFINE(M_FOOBUF, "foobuffers", "Buffers to foo data into the ether");
/* sys/something/foo_subr.c */

\&...
MALLOC(buf, struct foo_buf *, sizeof *buf, M_FOOBUF, M_NOWAIT);
buf = malloc(sizeof *buf, M_FOOBUF, M_NOWAIT);

.Ed
.Pp
Expand Down
4 changes: 2 additions & 2 deletions sys/arm/arm/undefined.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ install_coproc_handler(int coproc, undef_handler_t handler)
KASSERT(handler != NULL, ("handler is NULL")); /* Used to be legal. */

/* XXX: M_TEMP??? */
MALLOC(uh, struct undefined_handler *, sizeof(*uh), M_TEMP, M_WAITOK);
uh = malloc(sizeof(*uh), M_TEMP, M_WAITOK);
uh->uh_handler = handler;
install_coproc_handler_static(coproc, uh);
return uh;
Expand All @@ -125,7 +125,7 @@ remove_coproc_handler(void *cookie)
struct undefined_handler *uh = cookie;

LIST_REMOVE(uh, uh_link);
FREE(uh, M_TEMP);
free(uh, M_TEMP);
}


Expand Down
18 changes: 9 additions & 9 deletions sys/cam/scsi/scsi_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ targopen(struct cdev *dev, int flags, int fmt, struct thread *td)
make_dev(&targ_cdevsw, dev2unit(dev), UID_ROOT, GID_WHEEL, 0600,
"targ%d", dev2unit(dev));
}
MALLOC(softc, struct targ_softc *, sizeof(*softc), M_TARG,
softc = malloc(sizeof(*softc), M_TARG,
M_WAITOK | M_ZERO);
dev->si_drv1 = softc;
softc->state = TARG_STATE_OPENED;
Expand Down Expand Up @@ -211,7 +211,7 @@ targclose(struct cdev *dev, int flag, int fmt, struct thread *td)
if ((softc->periph == NULL) ||
(softc->state & TARG_STATE_LUN_ENABLED) == 0) {
destroy_dev(dev);
FREE(softc, M_TARG);
free(softc, M_TARG);
return (0);
}

Expand All @@ -230,7 +230,7 @@ targclose(struct cdev *dev, int flag, int fmt, struct thread *td)
softc->periph = NULL;
}
destroy_dev(dev);
FREE(softc, M_TARG);
free(softc, M_TARG);
}
cam_periph_unlock(periph);
cam_periph_release(periph);
Expand Down Expand Up @@ -531,7 +531,7 @@ targdtor(struct cam_periph *periph)
}
while ((descr = TAILQ_FIRST(&softc->abort_queue)) != NULL) {
TAILQ_REMOVE(&softc->abort_queue, descr, tqe);
FREE(descr, M_TARG);
free(descr, M_TARG);
}

softc->periph = NULL;
Expand Down Expand Up @@ -966,7 +966,7 @@ targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
int ccb_len;

ccb_len = targccblen(type);
MALLOC(ccb, union ccb *, ccb_len, M_TARG, M_WAITOK);
ccb = malloc(ccb_len, M_TARG, M_WAITOK);
CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb));

xpt_setup_ccb(&ccb->ccb_h, softc->path, priority);
Expand All @@ -981,13 +981,13 @@ targfreeccb(struct targ_softc *softc, union ccb *ccb)
{
CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("targfreeccb descr %p and\n",
ccb->ccb_h.targ_descr));
FREE(ccb->ccb_h.targ_descr, M_TARG);
free(ccb->ccb_h.targ_descr, M_TARG);

switch (ccb->ccb_h.func_code) {
case XPT_ACCEPT_TARGET_IO:
case XPT_IMMED_NOTIFY:
CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("freeing ccb %p\n", ccb));
FREE(ccb, M_TARG);
free(ccb, M_TARG);
break;
default:
/* Send back CCB if we got it from the periph */
Expand All @@ -998,7 +998,7 @@ targfreeccb(struct targ_softc *softc, union ccb *ccb)
} else {
CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH,
("freeing ccb %p\n", ccb));
FREE(ccb, M_TARG);
free(ccb, M_TARG);
}
break;
}
Expand All @@ -1009,7 +1009,7 @@ targgetdescr(struct targ_softc *softc)
{
struct targ_cmd_descr *descr;

MALLOC(descr, struct targ_cmd_descr *, sizeof(*descr), M_TARG,
descr = malloc(sizeof(*descr), M_TARG,
M_WAITOK);
descr->mapinfo.num_bufs_used = 0;
return (descr);
Expand Down
4 changes: 2 additions & 2 deletions sys/compat/linux/linux_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ linux_ioctl_register_handler(struct linux_ioctl_handler *h)
break;
}
if (he == NULL) {
MALLOC(he, struct handler_element *, sizeof(*he),
he = malloc(sizeof(*he),
M_LINUX, M_WAITOK);
he->func = h->func;
} else
Expand Down Expand Up @@ -2711,7 +2711,7 @@ linux_ioctl_unregister_handler(struct linux_ioctl_handler *h)
if (he->func == h->func) {
TAILQ_REMOVE(&handlers, he, list);
sx_xunlock(&linux_ioctl_sx);
FREE(he, M_LINUX);
free(he, M_LINUX);
return (0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions sys/compat/linux/linux_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ do_sa_get(struct sockaddr **sap, const struct osockaddr *osa, int *osalen,
}
#endif

MALLOC(kosa, struct osockaddr *, alloclen, mtype, M_WAITOK);
kosa = malloc(alloclen, mtype, M_WAITOK);

if ((error = copyin(osa, kosa, *osalen)))
goto out;
Expand Down Expand Up @@ -168,7 +168,7 @@ do_sa_get(struct sockaddr **sap, const struct osockaddr *osa, int *osalen,
return (0);

out:
FREE(kosa, mtype);
free(kosa, mtype);
return (error);
}

Expand Down Expand Up @@ -458,7 +458,7 @@ linux_sendit(struct thread *td, int s, struct msghdr *mp, int flags,

bad:
if (to)
FREE(to, M_SONAME);
free(to, M_SONAME);
return (error);
}

Expand Down
12 changes: 6 additions & 6 deletions sys/compat/linux/linux_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ linux_get_char_devices()
char formated[256];
int current_size = 0, string_size = 1024;

MALLOC(string, char *, string_size, M_LINUX, M_WAITOK);
string = malloc(string_size, M_LINUX, M_WAITOK);
string[0] = '\000';
last = "";
TAILQ_FOREACH(de, &devices, list) {
Expand All @@ -181,10 +181,10 @@ linux_get_char_devices()
if (strlen(formated) + current_size
>= string_size) {
string_size *= 2;
MALLOC(string, char *, string_size,
string = malloc(string_size,
M_LINUX, M_WAITOK);
bcopy(temp, string, current_size);
FREE(temp, M_LINUX);
free(temp, M_LINUX);
}
strcat(string, formated);
current_size = strlen(string);
Expand All @@ -197,7 +197,7 @@ linux_get_char_devices()
void
linux_free_get_char_devices(char *string)
{
FREE(string, M_LINUX);
free(string, M_LINUX);
}

static int linux_major_starting = 200;
Expand All @@ -210,7 +210,7 @@ linux_device_register_handler(struct linux_device_handler *d)
if (d == NULL)
return (EINVAL);

MALLOC(de, struct device_element *, sizeof(*de),
de = malloc(sizeof(*de),
M_LINUX, M_WAITOK);
if (d->linux_major < 0) {
d->linux_major = linux_major_starting++;
Expand All @@ -234,7 +234,7 @@ linux_device_unregister_handler(struct linux_device_handler *d)
TAILQ_FOREACH(de, &devices, list) {
if (bcmp(d, &de->entry, sizeof(*d)) == 0) {
TAILQ_REMOVE(&devices, de, list);
FREE(de, M_LINUX);
free(de, M_LINUX);
return (0);
}
}
Expand Down
10 changes: 5 additions & 5 deletions sys/contrib/altq/altq/altq_cbq.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ cbq_add_altq(struct pf_altq *a)
return (ENODEV);

/* allocate and initialize cbq_state_t */
MALLOC(cbqp, cbq_state_t *, sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
if (cbqp == NULL)
return (ENOMEM);
bzero(cbqp, sizeof(cbq_state_t));
Expand Down Expand Up @@ -304,7 +304,7 @@ cbq_remove_altq(struct pf_altq *a)
cbq_class_destroy(cbqp, cbqp->ifnp.root_);

/* deallocate cbq_state_t */
FREE(cbqp, M_DEVBUF);
free(cbqp, M_DEVBUF);

return (0);
}
Expand Down Expand Up @@ -927,7 +927,7 @@ cbq_ifattach(ifacep)
return (ENXIO);

/* allocate and initialize cbq_state_t */
MALLOC(new_cbqp, cbq_state_t *, sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
new_cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
if (new_cbqp == NULL)
return (ENOMEM);
bzero(new_cbqp, sizeof(cbq_state_t));
Expand All @@ -943,7 +943,7 @@ cbq_ifattach(ifacep)
cbq_enqueue, cbq_dequeue, cbq_request,
&new_cbqp->cbq_classifier, acc_classify);
if (error) {
FREE(new_cbqp, M_DEVBUF);
free(new_cbqp, M_DEVBUF);
return (error);
}

Expand Down Expand Up @@ -987,7 +987,7 @@ cbq_ifdetach(ifacep)
}

/* deallocate cbq_state_t */
FREE(cbqp, M_DEVBUF);
free(cbqp, M_DEVBUF);

return (0);
}
Expand Down
4 changes: 2 additions & 2 deletions sys/contrib/altq/altq/altq_cdnr.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ cdnr_cballoc(top, type, input_func)
return (NULL);
}

MALLOC(cb, struct cdnr_block *, size, M_DEVBUF, M_WAITOK);
cb = malloc(size, M_DEVBUF, M_WAITOK);
if (cb == NULL)
return (NULL);
bzero(cb, size);
Expand Down Expand Up @@ -319,7 +319,7 @@ cdnr_cbdestroy(cblock)
if (cb->cb_top != cblock)
LIST_REMOVE(cb, cb_next);

FREE(cb, M_DEVBUF);
free(cb, M_DEVBUF);
}

/*
Expand Down
Loading

0 comments on commit 66f807e

Please sign in to comment.