Module Name:    src
Committed By:   rmind
Date:           Mon Apr 30 22:51:28 UTC 2012

Modified Files:
        src/sys/fs/union: union_vfsops.c
        src/sys/kern: kern_malloc.c
        src/sys/miscfs/nullfs: null_vfsops.c
        src/sys/miscfs/overlay: overlay_vfsops.c
        src/sys/miscfs/procfs: procfs_vfsops.c
        src/sys/miscfs/umapfs: umap_vfsops.c
        src/sys/netinet: ip_mroute.c ip_output.c
        src/sys/sys: malloc.h
        src/sys/ufs/chfs: chfs_vfsops.c
        src/sys/ufs/ext2fs: ext2fs_vfsops.c
        src/sys/ufs/lfs: lfs_vfsops.c

Log Message:
- Replace some malloc(9) uses with kmem(9).
- G/C M_IPMOPTS, M_IPMADDR and M_BWMETER.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/fs/union/union_vfsops.c
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/kern_malloc.c
cvs rdiff -u -r1.83 -r1.84 src/sys/miscfs/nullfs/null_vfsops.c
cvs rdiff -u -r1.56 -r1.57 src/sys/miscfs/overlay/overlay_vfsops.c
cvs rdiff -u -r1.86 -r1.87 src/sys/miscfs/procfs/procfs_vfsops.c
cvs rdiff -u -r1.87 -r1.88 src/sys/miscfs/umapfs/umap_vfsops.c
cvs rdiff -u -r1.123 -r1.124 src/sys/netinet/ip_mroute.c
cvs rdiff -u -r1.214 -r1.215 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.113 -r1.114 src/sys/sys/malloc.h
cvs rdiff -u -r1.3 -r1.4 src/sys/ufs/chfs/chfs_vfsops.c
cvs rdiff -u -r1.163 -r1.164 src/sys/ufs/ext2fs/ext2fs_vfsops.c
cvs rdiff -u -r1.295 -r1.296 src/sys/ufs/lfs/lfs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/fs/union/union_vfsops.c
diff -u src/sys/fs/union/union_vfsops.c:1.67 src/sys/fs/union/union_vfsops.c:1.68
--- src/sys/fs/union/union_vfsops.c:1.67	Mon Dec  5 11:12:10 2011
+++ src/sys/fs/union/union_vfsops.c	Mon Apr 30 22:51:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: union_vfsops.c,v 1.67 2011/12/05 11:12:10 hannken Exp $	*/
+/*	$NetBSD: union_vfsops.c,v 1.68 2012/04/30 22:51:27 rmind Exp $	*/
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.67 2011/12/05 11:12:10 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.68 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -164,8 +164,7 @@ union_mount(struct mount *mp, const char
 		goto bad;
 	}
 
-	um = (struct union_mount *) malloc(sizeof(struct union_mount),
-				M_UFSMNT, M_WAITOK);	/* XXX */
+	um = kmem_zalloc(sizeof(struct union_mount), KM_SLEEP);
 
 	/*
 	 * Keep a held reference to the target vnodes.
@@ -291,7 +290,7 @@ union_mount(struct mount *mp, const char
 
 bad:
 	if (um)
-		free(um, M_UFSMNT);
+		kmem_free(um, sizeof(struct union_mount));
 	if (upperrootvp)
 		vrele(upperrootvp);
 	if (lowerrootvp)
@@ -372,9 +371,9 @@ union_unmount(struct mount *mp, int mntf
 	/*
 	 * Finally, throw away the union_mount structure
 	 */
-	free(mp->mnt_data, M_UFSMNT);	/* XXX */
+	kmem_free(um, sizeof(struct union_mount));
 	mp->mnt_data = NULL;
-	return (0);
+	return 0;
 }
 
 int

Index: src/sys/kern/kern_malloc.c
diff -u src/sys/kern/kern_malloc.c:1.141 src/sys/kern/kern_malloc.c:1.142
--- src/sys/kern/kern_malloc.c:1.141	Sun Apr 29 20:27:31 2012
+++ src/sys/kern/kern_malloc.c	Mon Apr 30 22:51:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_malloc.c,v 1.141 2012/04/29 20:27:31 dsl Exp $	*/
+/*	$NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $	*/
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.141 2012/04/29 20:27:31 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -90,10 +90,7 @@ MALLOC_DEFINE(M_RTABLE, "routetbl", "rou
 MALLOC_DEFINE(M_FTABLE, "fragtbl", "fragment reassembly header");
 MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure");
 MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure");
-MALLOC_DEFINE(M_IPMOPTS, "ip_moptions", "internet multicast options");
-MALLOC_DEFINE(M_IPMADDR, "in_multi", "internet multicast address");
 MALLOC_DEFINE(M_MRTABLE, "mrt", "multicast routing tables");
-MALLOC_DEFINE(M_BWMETER, "bwmeter", "multicast upcall bw meters");
 
 /*
  * Header contains total size, including the header itself.

Index: src/sys/miscfs/nullfs/null_vfsops.c
diff -u src/sys/miscfs/nullfs/null_vfsops.c:1.83 src/sys/miscfs/nullfs/null_vfsops.c:1.84
--- src/sys/miscfs/nullfs/null_vfsops.c:1.83	Fri Nov 19 06:44:46 2010
+++ src/sys/miscfs/nullfs/null_vfsops.c	Mon Apr 30 22:51:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: null_vfsops.c,v 1.83 2010/11/19 06:44:46 dholland Exp $	*/
+/*	$NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.83 2010/11/19 06:44:46 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -137,7 +137,7 @@ nullfs_mount(struct mount *mp, const cha
 	pathbuf_destroy(pb);
 
 	/* Create the mount point. */
-	nmp = malloc(sizeof(struct null_mount), M_UFSMNT, M_WAITOK | M_ZERO);
+	nmp = kmem_zalloc(sizeof(struct null_mount), KM_SLEEP);
 	mp->mnt_data = nmp;
 	nmp->nullm_vfs = lowerrootvp->v_mount;
 	if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL)
@@ -164,7 +164,7 @@ nullfs_mount(struct mount *mp, const cha
 		vput(lowerrootvp);
 		hashdone(nmp->nullm_node_hashtbl, HASH_LIST,
 		    nmp->nullm_node_hash);
-		free(nmp, M_UFSMNT);
+		kmem_free(nmp, sizeof(struct null_mount));
 		return error;
 	}
 	/*
@@ -203,7 +203,7 @@ nullfs_unmount(struct mount *mp, int mnt
 	/* Finally, destroy the mount point structures. */
 	hashdone(nmp->nullm_node_hashtbl, HASH_LIST, nmp->nullm_node_hash);
 	mutex_destroy(&nmp->nullm_hashlock);
-	free(mp->mnt_data, M_UFSMNT);
+	kmem_free(mp->mnt_data, sizeof(struct null_mount));
 	mp->mnt_data = NULL;
 	return 0;
 }

Index: src/sys/miscfs/overlay/overlay_vfsops.c
diff -u src/sys/miscfs/overlay/overlay_vfsops.c:1.56 src/sys/miscfs/overlay/overlay_vfsops.c:1.57
--- src/sys/miscfs/overlay/overlay_vfsops.c:1.56	Fri Jul  9 08:14:26 2010
+++ src/sys/miscfs/overlay/overlay_vfsops.c	Mon Apr 30 22:51:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: overlay_vfsops.c,v 1.56 2010/07/09 08:14:26 hannken Exp $	*/
+/*	$NetBSD: overlay_vfsops.c,v 1.57 2012/04/30 22:51:27 rmind Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.56 2010/07/09 08:14:26 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.57 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,9 +145,7 @@ ov_mount(struct mount *mp, const char *p
 	/*
 	 * First cut at fixing up upper mount point
 	 */
-	nmp = (struct overlay_mount *) malloc(sizeof(struct overlay_mount),
-				M_UFSMNT, M_WAITOK);	/* XXX */
-	memset(nmp, 0, sizeof(struct overlay_mount));
+	nmp = kmem_zalloc(sizeof(struct overlay_mount), KM_SLEEP);
 
 	mp->mnt_data = nmp;
 	nmp->ovm_vfs = lowerrootvp->v_mount;
@@ -179,8 +177,8 @@ ov_mount(struct mount *mp, const char *p
 	if (error) {
 		vput(lowerrootvp);
 		hashdone(nmp->ovm_node_hashtbl, HASH_LIST, nmp->ovm_node_hash);
-		free(nmp, M_UFSMNT);	/* XXX */
-		return (error);
+		kmem_free(nmp, sizeof(struct overlay_mount));
+		return error;
 	}
 	/*
 	 * Unlock the node
@@ -239,7 +237,7 @@ ov_unmount(struct mount *mp, int mntflag
 	omp = mp->mnt_data;
 	mutex_destroy(&omp->ovm_hashlock);
 	hashdone(omp->ovm_node_hashtbl, HASH_LIST, omp->ovm_node_hash);
-	free(omp, M_UFSMNT);	/* XXX */
+	kmem_free(omp, sizeof(struct overlay_mount));
 	mp->mnt_data = NULL;
 	return 0;
 }

Index: src/sys/miscfs/procfs/procfs_vfsops.c
diff -u src/sys/miscfs/procfs/procfs_vfsops.c:1.86 src/sys/miscfs/procfs/procfs_vfsops.c:1.87
--- src/sys/miscfs/procfs/procfs_vfsops.c:1.86	Tue Sep 27 01:23:59 2011
+++ src/sys/miscfs/procfs/procfs_vfsops.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_vfsops.c,v 1.86 2011/09/27 01:23:59 christos Exp $	*/
+/*	$NetBSD: procfs_vfsops.c,v 1.87 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*
  * Copyright (c) 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.86 2011/09/27 01:23:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.87 2012/04/30 22:51:28 rmind Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -154,8 +154,7 @@ procfs_mount(
 	if (*data_len >= sizeof *args && args->version != PROCFS_ARGSVERSION)
 		return EINVAL;
 
-	pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
-	    M_UFSMNT, M_WAITOK);   /* XXX need new malloc type */
+	pmnt = kmem_zalloc(sizeof(struct procfsmount), KM_SLEEP);
 
 	mp->mnt_stat.f_namemax = PROCFS_MAXNAMLEN;
 	mp->mnt_flag |= MNT_LOCAL;
@@ -191,10 +190,10 @@ procfs_unmount(struct mount *mp, int mnt
 
 	exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
 
-	free(mp->mnt_data, M_UFSMNT);
+	kmem_free(mp->mnt_data, sizeof(struct procfsmount));
 	mp->mnt_data = NULL;
 
-	return (0);
+	return 0;
 }
 
 int

Index: src/sys/miscfs/umapfs/umap_vfsops.c
diff -u src/sys/miscfs/umapfs/umap_vfsops.c:1.87 src/sys/miscfs/umapfs/umap_vfsops.c:1.88
--- src/sys/miscfs/umapfs/umap_vfsops.c:1.87	Tue Mar 13 18:40:58 2012
+++ src/sys/miscfs/umapfs/umap_vfsops.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: umap_vfsops.c,v 1.87 2012/03/13 18:40:58 elad Exp $	*/
+/*	$NetBSD: umap_vfsops.c,v 1.88 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.87 2012/03/13 18:40:58 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.88 2012/04/30 22:51:28 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -142,10 +142,7 @@ umapfs_mount(struct mount *mp, const cha
 	printf("mp = %p\n", mp);
 #endif
 
-	amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
-				M_UFSMNT, M_WAITOK);	/* XXX */
-	memset(amp, 0, sizeof(struct umap_mount));
-
+	amp = kmem_zalloc(sizeof(struct umap_mount), KM_SLEEP);
 	mp->mnt_data = amp;
 	amp->umapm_vfs = lowerrootvp->v_mount;
 	if (amp->umapm_vfs->mnt_flag & MNT_LOCAL)
@@ -216,8 +213,8 @@ umapfs_mount(struct mount *mp, const cha
 		vput(lowerrootvp);
 		hashdone(amp->umapm_node_hashtbl, HASH_LIST,
 		    amp->umapm_node_hash);
-		free(amp, M_UFSMNT);	/* XXX */
-		return (error);
+		kmem_free(amp, sizeof(struct umap_mount));
+		return error;
 	}
 	/*
 	 * Unlock the node (either the lower or the alias)
@@ -275,9 +272,9 @@ umapfs_unmount(struct mount *mp, int mnt
 	 */
 	mutex_destroy(&amp->umapm_hashlock);
 	hashdone(amp->umapm_node_hashtbl, HASH_LIST, amp->umapm_node_hash);
-	free(amp, M_UFSMNT);	/* XXX */
+	kmem_free(amp, sizeof(struct umap_mount));
 	mp->mnt_data = NULL;
-	return (0);
+	return 0;
 }
 
 extern const struct vnodeopv_desc umapfs_vnodeop_opv_desc;

Index: src/sys/netinet/ip_mroute.c
diff -u src/sys/netinet/ip_mroute.c:1.123 src/sys/netinet/ip_mroute.c:1.124
--- src/sys/netinet/ip_mroute.c:1.123	Thu Mar 22 20:34:39 2012
+++ src/sys/netinet/ip_mroute.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.123 2012/03/22 20:34:39 drochner Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.124 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.123 2012/03/22 20:34:39 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.124 2012/04/30 22:51:28 rmind Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1571,7 +1571,7 @@ expire_upcalls(void *v)
 				struct bw_meter *x = rt->mfc_bw_meter;
 
 				rt->mfc_bw_meter = x->bm_mfc_next;
-				free(x, M_BWMETER);
+				kmem_free(x, sizeof(*x));
 			}
 
 			++mrtstat.mrts_cache_cleanups;
@@ -2511,7 +2511,7 @@ add_bw_upcall(struct bw_upcall *req)
     }
 
     /* Allocate the new bw_meter entry */
-    x = (struct bw_meter *)malloc(sizeof(*x), M_BWMETER, M_NOWAIT);
+    x = kmem_intr_alloc(sizeof(*x), KM_NOSLEEP);
     if (x == NULL) {
 	splx(s);
 	return ENOBUFS;
@@ -2547,7 +2547,7 @@ free_bw_list(struct bw_meter *list)
 
 	list = list->bm_mfc_next;
 	unschedule_bw_meter(x);
-	free(x, M_BWMETER);
+	kmem_free(x, sizeof(*x));
     }
 }
 
@@ -2606,7 +2606,7 @@ del_bw_upcall(struct bw_upcall *req)
 	    unschedule_bw_meter(x);
 	    splx(s);
 	    /* Free the bw_meter entry */
-	    free(x, M_BWMETER);
+	    kmem_free(x, sizeof(*x));
 	    return 0;
 	} else {
 	    splx(s);

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.214 src/sys/netinet/ip_output.c:1.215
--- src/sys/netinet/ip_output.c:1.214	Thu Mar 22 20:34:39 2012
+++ src/sys/netinet/ip_output.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.214 2012/03/22 20:34:39 drochner Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.215 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.214 2012/03/22 20:34:39 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.215 2012/04/30 22:51:28 rmind Exp $");
 
 #include "opt_pfil_hooks.h"
 #include "opt_inet.h"
@@ -100,6 +100,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip_output.c,
 
 #include <sys/param.h>
 #include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/mbuf.h>
 #include <sys/errno.h>
 #include <sys/protosw.h>
@@ -1455,29 +1456,27 @@ ip_getoptval(const struct sockopt *sopt,
 int
 ip_setmoptions(struct ip_moptions **imop, const struct sockopt *sopt)
 {
-	int error = 0;
-	int i;
 	struct in_addr addr;
 	struct ip_mreq lmreq, *mreq;
 	struct ifnet *ifp;
 	struct ip_moptions *imo = *imop;
-	int ifindex;
+	int i, ifindex, error = 0;
 
 	if (imo == NULL) {
 		/*
 		 * No multicast option buffer attached to the pcb;
 		 * allocate one and initialize to default values.
 		 */
-		imo = malloc(sizeof(*imo), M_IPMOPTS, M_NOWAIT);
+		imo = kmem_intr_alloc(sizeof(*imo), KM_NOSLEEP);
 		if (imo == NULL)
-			return (ENOBUFS);
+			return ENOBUFS;
 
-		*imop = imo;
 		imo->imo_multicast_ifp = NULL;
 		imo->imo_multicast_addr.s_addr = INADDR_ANY;
 		imo->imo_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
 		imo->imo_multicast_loop = IP_DEFAULT_MULTICAST_LOOP;
 		imo->imo_num_memberships = 0;
+		*imop = imo;
 	}
 
 	switch (sopt->sopt_name) {
@@ -1672,11 +1671,11 @@ ip_setmoptions(struct ip_moptions **imop
 	    imo->imo_multicast_ttl == IP_DEFAULT_MULTICAST_TTL &&
 	    imo->imo_multicast_loop == IP_DEFAULT_MULTICAST_LOOP &&
 	    imo->imo_num_memberships == 0) {
-		free(*imop, M_IPMOPTS);
+		kmem_free(imo, sizeof(*imo));
 		*imop = NULL;
 	}
 
-	return (error);
+	return error;
 }
 
 /*
@@ -1738,7 +1737,7 @@ ip_freemoptions(struct ip_moptions *imo)
 	if (imo != NULL) {
 		for (i = 0; i < imo->imo_num_memberships; ++i)
 			in_delmulti(imo->imo_membership[i]);
-		free(imo, M_IPMOPTS);
+		kmem_free(imo, sizeof(*imo));
 	}
 }
 

Index: src/sys/sys/malloc.h
diff -u src/sys/sys/malloc.h:1.113 src/sys/sys/malloc.h:1.114
--- src/sys/sys/malloc.h:1.113	Sun Apr 29 20:27:32 2012
+++ src/sys/sys/malloc.h	Mon Apr 30 22:51:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: malloc.h,v 1.113 2012/04/29 20:27:32 dsl Exp $	*/
+/*	$NetBSD: malloc.h,v 1.114 2012/04/30 22:51:27 rmind Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -62,10 +62,7 @@ MALLOC_DECLARE(M_RTABLE);
 MALLOC_DECLARE(M_FTABLE);
 MALLOC_DECLARE(M_UFSMNT);
 MALLOC_DECLARE(M_NETADDR);
-MALLOC_DECLARE(M_IPMOPTS);
-MALLOC_DECLARE(M_IPMADDR);
 MALLOC_DECLARE(M_MRTABLE);
-MALLOC_DECLARE(M_BWMETER);
 #endif
 
 void	*kern_malloc(unsigned long, int);

Index: src/sys/ufs/chfs/chfs_vfsops.c
diff -u src/sys/ufs/chfs/chfs_vfsops.c:1.3 src/sys/ufs/chfs/chfs_vfsops.c:1.4
--- src/sys/ufs/chfs/chfs_vfsops.c:1.3	Thu Apr 12 15:31:01 2012
+++ src/sys/ufs/chfs/chfs_vfsops.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: chfs_vfsops.c,v 1.3 2012/04/12 15:31:01 ttoth Exp $	*/
+/*	$NetBSD: chfs_vfsops.c,v 1.4 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -255,20 +255,15 @@ chfs_mountfs(struct vnode *devvp, struct
 		return (err);
 	}
 
-	ump = malloc(sizeof(*ump), M_UFSMNT, M_WAITOK);
-	memset(ump, 0, sizeof(*ump));
+	ump = kmem_zalloc(sizeof(struct ufsmount), KM_SLEEP);
+
 	ump->um_fstype = UFS1;
 	//ump->um_ops = &chfs_ufsops;
-	ump->um_chfs = malloc(sizeof(struct chfs_mount),
-	    M_UFSMNT, M_WAITOK);
-	memset(ump->um_chfs, 0, sizeof(struct chfs_mount));
-
+	ump->um_chfs = kmem_zalloc(sizeof(struct chfs_mount), KM_SLEEP);
 	mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE);
 
 	/* Get superblock and set flash device number */
 	chmp = ump->um_chfs;
-	if (!chmp)
-		return ENOMEM;
 
 	chmp->chm_ebh = kmem_alloc(sizeof(struct chfs_ebh), KM_SLEEP);
 
@@ -276,9 +271,7 @@ chfs_mountfs(struct vnode *devvp, struct
 	err = ebh_open(chmp->chm_ebh, devvp->v_rdev);
 	if (err) {
 		dbg("error while opening flash\n");
-		kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh));
-		free(chmp, M_UFSMNT);
-		return err;
+		goto fail;
 	}
 
 	//TODO check flash sizes
@@ -289,14 +282,6 @@ chfs_mountfs(struct vnode *devvp, struct
 	chmp->chm_blocks = kmem_zalloc(chmp->chm_ebh->peb_nr *
 	    sizeof(struct chfs_eraseblock), KM_SLEEP);
 
-	if (!chmp->chm_blocks) {
-		kmem_free(chmp->chm_ebh, chmp->chm_ebh->peb_nr *
-		    sizeof(struct chfs_eraseblock));
-		ebh_close(chmp->chm_ebh);
-		free(chmp, M_UFSMNT);
-		return ENOMEM;
-	}
-
 	mutex_init(&chmp->chm_lock_mountfields, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(&chmp->chm_lock_sizes, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(&chmp->chm_lock_vnocache, MUTEX_DEFAULT, IPL_NONE);
@@ -337,11 +322,9 @@ chfs_mountfs(struct vnode *devvp, struct
 
 	if (err) {
 		chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
-		kmem_free(chmp->chm_ebh, chmp->chm_ebh->peb_nr *
-		    sizeof(struct chfs_eraseblock));
 		ebh_close(chmp->chm_ebh);
-		free(chmp, M_UFSMNT);
-		return EIO;
+		err = EIO;
+		goto fail;
 	}
 
 	mp->mnt_data = ump;
@@ -385,6 +368,11 @@ chfs_mountfs(struct vnode *devvp, struct
 
 	devvp->v_specmountpoint = mp;
 	return 0;
+fail:
+	kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh));
+	kmem_free(chmp, sizeof(struct chfs_mount));
+	kmem_free(ump, sizeof(struct ufsmount));
+	return err;
 }
 
 /* --------------------------------------------------------------------- */
@@ -438,8 +426,8 @@ chfs_unmount(struct mount *mp, int mntfl
 
 	mutex_destroy(&ump->um_lock);
 
-	//free(ump->um_chfs, M_UFSMNT);
-	free(ump, M_UFSMNT);
+	//kmem_free(ump->um_chfs, sizeof(struct chfs_mount));
+	kmem_free(ump, sizeof(struct ufsmount));
 	mp->mnt_data = NULL;
 	mp->mnt_flag &= ~MNT_LOCAL;
 	dbg("[END]\n");

Index: src/sys/ufs/ext2fs/ext2fs_vfsops.c
diff -u src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.163 src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.164
--- src/sys/ufs/ext2fs/ext2fs_vfsops.c:1.163	Tue Mar 13 18:41:04 2012
+++ src/sys/ufs/ext2fs/ext2fs_vfsops.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs_vfsops.c,v 1.163 2012/03/13 18:41:04 elad Exp $	*/
+/*	$NetBSD: ext2fs_vfsops.c,v 1.164 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.163 2012/03/13 18:41:04 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.164 2012/04/30 22:51:28 rmind Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -694,12 +694,10 @@ ext2fs_mountfs(struct vnode *devvp, stru
 	error = ext2fs_checksb(fs, ronly);
 	if (error)
 		goto out;
-	ump = malloc(sizeof(*ump), M_UFSMNT, M_WAITOK);
-	memset(ump, 0, sizeof(*ump));
+	ump = kmem_zalloc(sizeof(*ump), KM_SLEEP);
 	ump->um_fstype = UFS1;
 	ump->um_ops = &ext2fs_ufsops;
-	ump->um_e2fs = malloc(sizeof(struct m_ext2fs), M_UFSMNT, M_WAITOK);
-	memset(ump->um_e2fs, 0, sizeof(struct m_ext2fs));
+	ump->um_e2fs = kmem_zalloc(sizeof(struct m_ext2fs), KM_SLEEP);
 	e2fs_sbload((struct ext2fs *)bp->b_data, &ump->um_e2fs->e2fs);
 	brelse(bp, 0);
 	bp = NULL;
@@ -731,15 +729,15 @@ ext2fs_mountfs(struct vnode *devvp, stru
 	m_fs->e2fs_ipb = m_fs->e2fs_bsize / EXT2_DINODE_SIZE(m_fs);
 	m_fs->e2fs_itpg = m_fs->e2fs.e2fs_ipg / m_fs->e2fs_ipb;
 
-	m_fs->e2fs_gd = malloc(m_fs->e2fs_ngdb * m_fs->e2fs_bsize,
-	    M_UFSMNT, M_WAITOK);
+	m_fs->e2fs_gd = kmem_alloc(m_fs->e2fs_ngdb * m_fs->e2fs_bsize, KM_SLEEP);
 	for (i = 0; i < m_fs->e2fs_ngdb; i++) {
 		error = bread(devvp ,
 		    fsbtodb(m_fs, m_fs->e2fs.e2fs_first_dblock +
 		    1 /* superblock */ + i),
 		    m_fs->e2fs_bsize, NOCRED, 0, &bp);
 		if (error) {
-			free(m_fs->e2fs_gd, M_UFSMNT);
+			kmem_free(m_fs->e2fs_gd,
+			    m_fs->e2fs_ngdb * m_fs->e2fs_bsize);
 			goto out;
 		}
 		e2fs_cgload((struct ext2_gd *)bp->b_data,
@@ -777,8 +775,8 @@ out:
 	KASSERT(bp != NULL);
 	brelse(bp, 0);
 	if (ump) {
-		free(ump->um_e2fs, M_UFSMNT);
-		free(ump, M_UFSMNT);
+		kmem_free(ump->um_e2fs, sizeof(struct m_ext2fs));
+		kmem_free(ump, sizeof(*ump));
 		mp->mnt_data = NULL;
 	}
 	return (error);
@@ -813,9 +811,9 @@ ext2fs_unmount(struct mount *mp, int mnt
 	error = VOP_CLOSE(ump->um_devvp, fs->e2fs_ronly ? FREAD : FREAD|FWRITE,
 	    NOCRED);
 	vput(ump->um_devvp);
-	free(fs->e2fs_gd, M_UFSMNT);
-	free(fs, M_UFSMNT);
-	free(ump, M_UFSMNT);
+	kmem_free(fs->e2fs_gd, fs->e2fs_ngdb * fs->e2fs_bsize);
+	kmem_free(fs, sizeof(*fs));
+	kmem_free(ump, sizeof(*ump));
 	mp->mnt_data = NULL;
 	mp->mnt_flag &= ~MNT_LOCAL;
 	return (error);

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.295 src/sys/ufs/lfs/lfs_vfsops.c:1.296
--- src/sys/ufs/lfs/lfs_vfsops.c:1.295	Tue Mar 13 18:41:13 2012
+++ src/sys/ufs/lfs/lfs_vfsops.c	Mon Apr 30 22:51:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.295 2012/03/13 18:41:13 elad Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.296 2012/04/30 22:51:28 rmind Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.295 2012/03/13 18:41:13 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.296 2012/04/30 22:51:28 rmind Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -927,7 +927,7 @@ lfs_mountfs(struct vnode *devvp, struct 
 	}
 
 	/* Allocate the mount structure, copy the superblock into it. */
-	fs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK | M_ZERO);
+	fs = kmem_zalloc(sizeof(struct lfs), KM_SLEEP);
 	memcpy(&fs->lfs_dlfs, tdfs, sizeof(struct dlfs));
 
 	/* Compatibility */
@@ -952,7 +952,7 @@ lfs_mountfs(struct vnode *devvp, struct 
 		      (long long)((bufmem_hiwater / bufmem_lowater) *
 				  LFS_INVERSE_MAX_BYTES(
 					  fsbtob(fs, LFS_NRESERVE(fs))) >> PAGE_SHIFT)));
-		free(fs, M_UFSMNT);
+		kmem_free(fs, sizeof(struct lfs));
 		error = EFBIG; /* XXX needs translation */
 		goto out;
 	}
@@ -963,7 +963,7 @@ lfs_mountfs(struct vnode *devvp, struct 
 		fs->lfs_rfpid = l->l_proc->p_pid;
 	}
 
-	ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK | M_ZERO);
+	ump = kmem_zalloc(sizeof(*ump), KM_SLEEP);
 	ump->um_lfs = fs;
 	ump->um_ops = &lfs_ufsops;
 	ump->um_fstype = UFS1;
@@ -1151,8 +1151,8 @@ out:
 	if (abp)
 		brelse(abp, 0);
 	if (ump) {
-		free(ump->um_lfs, M_UFSMNT);
-		free(ump, M_UFSMNT);
+		kmem_free(ump->um_lfs, sizeof(struct lfs));
+		kmem_free(ump, sizeof(*ump));
 		mp->mnt_data = NULL;
 	}
 
@@ -1239,8 +1239,9 @@ lfs_unmount(struct mount *mp, int mntfla
 	cv_destroy(&fs->lfs_stopcv);
 	rw_destroy(&fs->lfs_fraglock);
 	rw_destroy(&fs->lfs_iflock);
-	free(fs, M_UFSMNT);
-	free(ump, M_UFSMNT);
+
+	kmem_free(fs, sizeof(struct lfs));
+	kmem_free(ump, sizeof(*ump));
 
 	mp->mnt_data = NULL;
 	mp->mnt_flag &= ~MNT_LOCAL;

Reply via email to