linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] unionfs: kmalloc cleanups
@ 2006-01-10 12:36 Pekka J Enberg
  0 siblings, 0 replies; 2+ messages in thread
From: Pekka J Enberg @ 2006-01-10 12:36 UTC (permalink / raw)
  To: unionfs; +Cc: linux-fsdevel

Hi,

This patch removes the KMALLOC and KFREE wrappers from unionfs and converts
callers to use proper kmalloc, kzalloc, kcalloc, and kfree where appropriate.
This patch also replaces the use of GFP_UNIONFS macro with GFP_KERNEL.

The use of debugging memory allocator wrappers is discouraged in the Linux
kernel and there are plenty of memory leak tracking patches floating around
(in -mm in particular). While unionfs is an out-of-tree filesystem, this
patch is one small step in bringing unionfs ready for inclusion so please
consider applying this patch.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 branchman.c        |   68 +++++++----------
 commonfops.c       |   29 +++----
 copyup.c           |   19 ++--
 dirhelper.c        |    6 -
 fist.h             |    7 -
 inode.c            |   16 ++--
 main.c             |  207 ++++++-----------------------------------------------
 persistent_inode.c |   28 +++----
 rdstate.c          |    8 +-
 rename.c           |    8 +-
 super.c            |   19 ++--
 unionfs.h          |    5 -
 12 files changed, 120 insertions(+), 300 deletions(-)

Index: unionfs-20060109-2055/branchman.c
===================================================================
--- unionfs-20060109-2055.orig/branchman.c
+++ unionfs-20060109-2055/branchman.c
@@ -57,7 +57,7 @@ static int newputmap(struct super_block 
 	spd = stopd(sb);
 
 	i = sizeof(int) * (sbend(sb) + 1);
-	newmap = KMALLOC(sizeof(struct putmap) + i, GFP_UNIONFS);
+	newmap = kmalloc(sizeof(struct putmap) + i, GFP_KERNEL);
 	if (!newmap) {
 		print_exit_status(-ENOMEM);
 		return -ENOMEM;
@@ -68,9 +68,9 @@ static int newputmap(struct super_block 
 		spd->usi_lastputmap = 1;
 
 		spd->usi_putmaps =
-		    KMALLOC(sizeof(struct putmap *), GFP_UNIONFS);
+		    kmalloc(sizeof(struct putmap *), GFP_KERNEL);
 		if (!spd->usi_putmaps) {
-			KFREE(newmap);
+			kfree(newmap);
 			print_exit_status(-ENOMEM);
 			return -ENOMEM;
 		}
@@ -83,11 +83,10 @@ static int newputmap(struct super_block 
 			newfirst++;
 		}
 
-		newlist =
-		    KMALLOC(sizeof(struct putmap *) *
-			    (1 + spd->usi_lastputmap - newfirst), GFP_UNIONFS);
+		newlist = kcalloc(1 + spd->usi_lastputmap - newfirst,
+				  sizeof(struct putmap *), GFP_KERNEL);
 		if (!newlist) {
-			KFREE(newmap);
+			kfree(newmap);
 			print_exit_status(-ENOMEM);
 			return -ENOMEM;
 		}
@@ -97,7 +96,7 @@ static int newputmap(struct super_block 
 			    spd->usi_putmaps[i - spd->usi_firstputmap];
 		}
 
-		KFREE(spd->usi_putmaps);
+		kfree(spd->usi_putmaps);
 		spd->usi_putmaps = newlist;
 		spd->usi_firstputmap = newfirst;
 		spd->usi_lastputmap++;
@@ -202,7 +201,7 @@ int unionfs_ioctl_addbranch(struct inode
 	print_entry_location();
 
 	err = -ENOMEM;
-	addargs = KMALLOC(sizeof(struct unionfs_addbranch_args), GFP_UNIONFS);
+	addargs = kmalloc(sizeof(struct unionfs_addbranch_args), GFP_KERNEL);
 	if (!addargs)
 		goto out;
 
@@ -270,26 +269,21 @@ int unionfs_ioctl_addbranch(struct inode
 	if (pobjects > 0) {
 		/* Reallocate the dynamic structures. */
 		new_hidden_mnt =
-		    KMALLOC(sizeof(struct vfsmount *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct vfsmount *), GFP_KERNEL);
 		new_udi_dentry =
-		    KMALLOC(sizeof(struct dentry *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct dentry *), GFP_KERNEL);
 		new_uii_inode =
-		    KMALLOC(sizeof(struct inode *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct inode *), GFP_KERNEL);
 		new_usi_sb =
-		    KMALLOC(sizeof(struct super_block *) * pobjects,
-			    GFP_UNIONFS);
-		new_counts = KMALLOC(sizeof(atomic_t) * pobjects, GFP_UNIONFS);
-		new_branchperms = KMALLOC(sizeof(int) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct super_block *),
+			    GFP_KERNEL);
+		new_counts = kmalloc(sizeof(atomic_t) * pobjects, GFP_KERNEL);
+		new_branchperms = kcalloc(pobjects, sizeof(int), GFP_KERNEL);
 		if (!new_hidden_mnt || !new_udi_dentry || !new_uii_inode
 		    || !new_counts || !new_usi_sb || !new_branchperms) {
 			err = -ENOMEM;
 			goto out;
 		}
-		memset(new_hidden_mnt, 0, sizeof(struct vfsmount *) * pobjects);
-		memset(new_udi_dentry, 0, sizeof(struct dentry *) * pobjects);
-		memset(new_uii_inode, 0, sizeof(struct inode *) * pobjects);
-		memset(new_usi_sb, 0, sizeof(struct super_block *) * pobjects);
-		memset(new_branchperms, 0, sizeof(int) * pobjects);
 	}
 
 	/* Copy the in-place values to our new structure. */
@@ -348,12 +342,12 @@ int unionfs_ioctl_addbranch(struct inode
 	}
 
 	/* Now we can free the old ones. */
-	KFREE(dtopd(inode->i_sb->s_root)->udi_dentry_p);
-	KFREE(itopd(inode->i_sb->s_root->d_inode)->uii_inode_p);
-	KFREE(stopd(inode->i_sb)->usi_hidden_mnt_p);
-	KFREE(stopd(inode->i_sb)->usi_sb_p);
-	KFREE(stopd(inode->i_sb)->usi_sbcount_p);
-	KFREE(stopd(inode->i_sb)->usi_branchperms_p);
+	kfree(dtopd(inode->i_sb->s_root)->udi_dentry_p);
+	kfree(itopd(inode->i_sb->s_root->d_inode)->uii_inode_p);
+	kfree(stopd(inode->i_sb)->usi_hidden_mnt_p);
+	kfree(stopd(inode->i_sb)->usi_sb_p);
+	kfree(stopd(inode->i_sb)->usi_sbcount_p);
+	kfree(stopd(inode->i_sb)->usi_branchperms_p);
 
 	/* Update the real pointers. */
 	dtohd_ptr(inode->i_sb->s_root) = new_udi_dentry;
@@ -389,13 +383,13 @@ int unionfs_ioctl_addbranch(struct inode
 	unlock_dentry(inode->i_sb->s_root);
 	unionfs_write_unlock(inode->i_sb);
 
-	KFREE(new_hidden_mnt);
-	KFREE(new_udi_dentry);
-	KFREE(new_uii_inode);
-	KFREE(new_usi_sb);
-	KFREE(new_counts);
-	KFREE(new_branchperms);
-	KFREE(addargs);
+	kfree(new_hidden_mnt);
+	kfree(new_udi_dentry);
+	kfree(new_uii_inode);
+	kfree(new_usi_sb);
+	kfree(new_counts);
+	kfree(new_branchperms);
+	kfree(addargs);
 	if (path)
 		putname(path);
 
@@ -476,7 +470,7 @@ int unionfs_ioctl_delbranch(struct super
 
 	/* This doesn't open a file, so we might have to free the map here. */
 	if (atomic_read(&stopd(sb)->usi_putmaps[pmindex]->count) == 0) {
-		KFREE(stopd(sb)->usi_putmaps[pmindex]);
+		kfree(stopd(sb)->usi_putmaps[pmindex]);
 		stopd(sb)->usi_putmaps[pmindex] = NULL;
 	}
 
@@ -503,7 +497,7 @@ int unionfs_ioctl_rdwrbranch(struct inod
 		goto out;
 
 	err = -ENOMEM;
-	rdwrargs = KMALLOC(sizeof(struct unionfs_rdwrbranch_args), GFP_UNIONFS);
+	rdwrargs = kmalloc(sizeof(struct unionfs_rdwrbranch_args), GFP_KERNEL);
 	if (!rdwrargs)
 		goto out;
 
@@ -534,7 +528,7 @@ int unionfs_ioctl_rdwrbranch(struct inod
       out:
 	unlock_dentry(inode->i_sb->s_root);
 	unionfs_write_unlock(inode->i_sb);
-	KFREE(rdwrargs);
+	kfree(rdwrargs);
 
 	print_exit_status(err);
 
Index: unionfs-20060109-2055/commonfops.c
===================================================================
--- unionfs-20060109-2055.orig/commonfops.c
+++ unionfs-20060109-2055/commonfops.c
@@ -47,7 +47,7 @@ static inline void branchput_gen(int gen
 		stopd(sb)->usi_putmaps[generation - stopd(sb)->usi_firstputmap]
 		    = NULL;
 		fist_dprint(8, "Freeing putmap %d.\n", generation);
-		KFREE(putmap);
+		kfree(putmap);
 	}
 }
 
@@ -61,16 +61,16 @@ static char *get_random_name(int size, u
 		return NULL;
 
 	if (!name)
-		name = KMALLOC(size + 1, GFP_UNIONFS);
+		name = kmalloc(size + 1, GFP_KERNEL);
 	if (!name) {
 		name = ERR_PTR(-ENOMEM);
 		goto out;
 	}
 	strncpy(name, WHPFX, WHLEN);
 
-	tmpbuf = KMALLOC(size, GFP_UNIONFS);
+	tmpbuf = kmalloc(size, GFP_KERNEL);
 	if (!tmpbuf) {
-		KFREE(name);
+		kfree(name);
 		name = ERR_PTR(-ENOMEM);
 		goto out;
 	}
@@ -99,7 +99,7 @@ static char *get_random_name(int size, u
 	name[size] = '\0';
 
       out:
-	KFREE(tmpbuf);
+	kfree(tmpbuf);
 	return (name);
 
 }
@@ -153,7 +153,7 @@ static int copyup_deleted_file(struct fi
 	unlock_dir(hidden_dir_dentry);
 
       out:
-	KFREE(name);
+	kfree(name);
 	print_exit_status(err);
 	return err;
 }
@@ -203,7 +203,7 @@ int unionfs_file_revalidate(struct file 
 			}
 		}
 		if (ftohf_ptr(file)) {
-			KFREE(ftohf_ptr(file));
+			kfree(ftohf_ptr(file));
 			ftohf_ptr(file) = NULL;
 		}
 
@@ -215,7 +215,7 @@ int unionfs_file_revalidate(struct file 
 			int size =
 			    sizeof(struct file *) * (sbmax(sb) -
 						     UNIONFS_INLINE_OBJECTS);
-			ftohf_ptr(file) = KMALLOC(size, GFP_UNIONFS);
+			ftohf_ptr(file) = kmalloc(size, GFP_KERNEL);
 			if (!ftohf_ptr(file)) {
 				err = -ENOMEM;
 				goto out;
@@ -364,12 +364,11 @@ int unionfs_open(struct inode *inode, st
 	print_entry_location();
 
 	ftopd_lhs(file) =
-	    KMALLOC(sizeof(struct unionfs_file_info), GFP_UNIONFS);
+	    kzalloc(sizeof(struct unionfs_file_info), GFP_KERNEL);
 	if (!ftopd(file)) {
 		err = -ENOMEM;
 		goto out;
 	}
-	memset(ftopd(file), 0, sizeof(struct unionfs_file_info));
 	fbstart(file) = -1;
 	fbend(file) = -1;
 	atomic_set(&ftopd(file)->ufi_generation,
@@ -378,7 +377,7 @@ int unionfs_open(struct inode *inode, st
 		int size =
 		    sizeof(struct file *) * (sbmax(inode->i_sb) -
 					     UNIONFS_INLINE_OBJECTS);
-		ftohf_ptr(file) = KMALLOC(size, GFP_UNIONFS);
+		ftohf_ptr(file) = kmalloc(size, GFP_KERNEL);
 		if (!ftohf_ptr(file)) {
 			err = -ENOMEM;
 			goto out;
@@ -490,8 +489,8 @@ int unionfs_open(struct inode *inode, st
 		}
 		if (!locked)
 			unionfs_read_unlock(file->f_dentry->d_sb);
-		KFREE(ftohf_ptr(file));
-		KFREE(ftopd(file));
+		kfree(ftohf_ptr(file));
+		kfree(ftopd(file));
 	}
 
 	fist_print_file("OUT: unionfs_open", file);
@@ -530,7 +529,7 @@ int unionfs_file_release(struct inode *i
 			unionfs_read_unlock(inode->i_sb);
 		}
 	}
-	KFREE(ftohf_ptr(file));
+	kfree(ftohf_ptr(file));
 
 	if (ftopd(file)->rdstate) {
 		ftopd(file)->rdstate->uds_access = jiffies;
@@ -546,7 +545,7 @@ int unionfs_file_release(struct inode *i
 		spin_unlock(&itopd(inode)->uii_rdlock);
 		ftopd(file)->rdstate = NULL;
 	}
-	KFREE(ftopd(file));
+	kfree(ftopd(file));
 
 	fist_checkinode(inode, "post unionfs_release");
 
Index: unionfs-20060109-2055/copyup.c
===================================================================
--- unionfs-20060109-2055.orig/copyup.c
+++ unionfs-20060109-2055/copyup.c
@@ -241,7 +241,7 @@ int copyup_named_dentry(struct inode *di
 	/* For symlinks, we must read the link before we lock the directory. */
 	if (S_ISLNK(old_hidden_dentry->d_inode->i_mode)) {
 
-		symbuf = KMALLOC(PATH_MAX, GFP_UNIONFS);
+		symbuf = kmalloc(PATH_MAX, GFP_KERNEL);
 		if (!symbuf) {
 			err = -ENOMEM;
 			goto copyup_readlink_err;
@@ -291,7 +291,7 @@ int copyup_named_dentry(struct inode *di
 	current->fsgid = saved_gid;
 	unlock_dir(new_hidden_parent_dentry);
       copyup_readlink_err:
-	KFREE(symbuf);
+	kfree(symbuf);
 	if (err) {
 		/* get rid of the hidden dentry and all its traces */
 		DPUT(new_hidden_dentry);
@@ -336,7 +336,7 @@ int copyup_named_dentry(struct inode *di
 		}
 
 		/* allocating a buffer */
-		buf = (char *)KMALLOC(PAGE_SIZE, GFP_UNIONFS);
+		buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
 		if (!buf) {
 			err = -ENOMEM;
 			goto out;
@@ -377,7 +377,7 @@ int copyup_named_dentry(struct inode *di
 			}
 		} while ((read_bytes > 0) && (len > 0));
 		set_fs(old_fs);
-		KFREE(buf);
+		kfree(buf);
 	}
 
 	/* Set permissions. */
@@ -530,8 +530,7 @@ struct dentry *create_parents_named(stru
 	old_bstart = dbstart(dentry);
 	old_bend = dbend(dentry);
 
-	path = (struct dentry **)KMALLOC(kmalloc_size, GFP_KERNEL);
-	memset(path, 0, kmalloc_size);
+	path = kzalloc(kmalloc_size, GFP_KERNEL);
 
 	/* assume the negative dentry of unionfs as the parent dentry */
 	parent_dentry = dentry;
@@ -562,15 +561,13 @@ struct dentry *create_parents_named(stru
 			kmalloc_size *= 2;
 			num_dentry = kmalloc_size / sizeof(struct dentry *);
 
-			tmp_path =
-			    (struct dentry **)KMALLOC(kmalloc_size, GFP_KERNEL);
+			tmp_path = kzalloc(kmalloc_size, GFP_KERNEL);
 			if (!tmp_path) {
 				hidden_dentry = ERR_PTR(-ENOMEM);
 				goto out;
 			}
-			memset(tmp_path, 0, kmalloc_size);
 			memcpy(tmp_path, path, old_kmalloc_size);
-			KFREE(path);
+			kfree(path);
 			path = tmp_path;
 			tmp_path = NULL;
 		}
@@ -702,7 +699,7 @@ struct dentry *create_parents_named(stru
 		child_dentry = path[--count];
 	}
       out:
-	KFREE(path);
+	kfree(path);
 	fist_print_dentry("OUT: create_parents_named", dentry);
 	print_exit_pointer(hidden_dentry);
 	return hidden_dentry;
Index: unionfs-20060109-2055/dirhelper.c
===================================================================
--- unionfs-20060109-2055.orig/dirhelper.c
+++ unionfs-20060109-2055/dirhelper.c
@@ -48,7 +48,7 @@ int delete_whiteouts(struct dentry *dent
 	hidden_dir_dentry = dtohd_index(dentry, bindex);
 	BUG_ON(!S_ISDIR(hidden_dir_dentry->d_inode->i_mode));
 
-	name = (char *)__get_free_page(GFP_UNIONFS);
+	name = (char *)__get_free_page(GFP_KERNEL);
 	if (!name) {
 		err = -ENOMEM;
 		goto out;
@@ -182,7 +182,7 @@ int check_empty(struct dentry *dentry, s
 	if (0 <= bopaque && bopaque < bend)
 		bend = bopaque;
 
-	buf = KMALLOC(sizeof(struct unionfs_rdutil_callback), GFP_UNIONFS);
+	buf = kmalloc(sizeof(struct unionfs_rdutil_callback), GFP_KERNEL);
 	if (!buf) {
 		err = -ENOMEM;
 		goto out;
@@ -241,7 +241,7 @@ int check_empty(struct dentry *dentry, s
 			*namelist = buf->rdstate;
 		else if (buf->rdstate)
 			free_rdstate(buf->rdstate);
-		KFREE(buf);
+		kfree(buf);
 	}
 
 	unionfs_read_unlock(sb);
Index: unionfs-20060109-2055/inode.c
===================================================================
--- unionfs-20060109-2055.orig/inode.c
+++ unionfs-20060109-2055/inode.c
@@ -191,7 +191,7 @@ static int unionfs_create(struct inode *
 
       out:
 	DPUT(whiteout_dentry);
-	KFREE(name);
+	kfree(name);
 
 	fist_print_dentry("OUT unionfs_create :", dentry);
 	unlock_dentry(dentry);
@@ -323,7 +323,7 @@ static int unionfs_link(struct dentry *o
 	if (!new_dentry->d_inode)
 		d_drop(new_dentry);
 
-	KFREE(name);
+	kfree(name);
 
 	unlock_dentry(new_dentry);
 	unlock_dentry(old_dentry);
@@ -451,7 +451,7 @@ static int unionfs_symlink(struct inode 
 	if (!dentry->d_inode)
 		d_drop(dentry);
 
-	KFREE(name);
+	kfree(name);
 	fist_print_dentry("OUT unionfs_symlink :", dentry);
 	unlock_dentry(dentry);
 	print_exit_status(err);
@@ -602,7 +602,7 @@ static int unionfs_mkdir(struct inode *p
 	if (!dentry->d_inode)
 		d_drop(dentry);
 
-	KFREE(name);
+	kfree(name);
 
 	fist_print_dentry("OUT unionfs_mkdir :", dentry);
 	unlock_dentry(dentry);
@@ -714,7 +714,7 @@ static int unionfs_mknod(struct inode *d
 		d_drop(dentry);
 
 	if (name) {
-		KFREE(name);
+		kfree(name);
 	}
 
 	fist_print_dentry("OUT unionfs_mknod :", dentry);
@@ -764,7 +764,7 @@ static void *unionfs_follow_link(struct 
 	print_entry_location();
 
 	/* This is freed by the put_link method assuming a successful call. */
-	buf = (char *)KMALLOC(len, GFP_UNIONFS);
+	buf = kmalloc(len, GFP_KERNEL);
 	if (!buf) {
 		err = -ENOMEM;
 		goto out;
@@ -776,7 +776,7 @@ static void *unionfs_follow_link(struct 
 	err = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
 	set_fs(old_fs);
 	if (err < 0) {
-		KFREE(buf);
+		kfree(buf);
 		buf = NULL;
 		goto out;
 	}
@@ -802,7 +802,7 @@ void unionfs_put_link(struct dentry *den
 	char *link;
 	print_entry_location();
 	link = nd_get_link(nd);
-	KFREE(link);
+	kfree(link);
 	print_exit_location();
 }
 
Index: unionfs-20060109-2055/main.c
===================================================================
--- unionfs-20060109-2055.orig/main.c
+++ unionfs-20060109-2055/main.c
@@ -74,12 +74,11 @@ int unionfs_interpose(struct dentry *den
 			int size =
 			    (sbmax(sb) -
 			     UNIONFS_INLINE_OBJECTS) * sizeof(struct inode *);
-			itohi_ptr(inode) = KMALLOC(size, GFP_UNIONFS);
+			itohi_ptr(inode) = kzalloc(size, GFP_KERNEL);
 			if (!itohi_ptr(inode)) {
 				err = -ENOMEM;
 				goto out;
 			}
-			memset(itohi_ptr(inode), 0, size);
 		}
 		memset(itohi_inline(inode), 0,
 		       UNIONFS_INLINE_OBJECTS * sizeof(struct inode *));
@@ -277,16 +276,13 @@ static int parse_dirs_option(struct supe
 		err = -ENOMEM;
 
 		hidden_root_info->udi_dentry_p =
-		    KMALLOC(sizeof(struct dentry *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct dentry *), GFP_KERNEL);
 		if (!hidden_root_info->udi_dentry_p)
 			goto out;
 
-		memset(hidden_root_info->udi_dentry_p, 0,
-		       sizeof(struct dentry *) * pobjects);
-
 		stohs_ptr(sb) =
-		    KMALLOC(sizeof(struct super_block *) *
-			    pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(struct super_block *) *
+			    pobjects, GFP_KERNEL);
 		if (!stohs_ptr(sb))
 			goto out;
 
@@ -294,17 +290,17 @@ static int parse_dirs_option(struct supe
 		       pobjects * sizeof(struct super_block *));
 
 		stopd(sb)->usi_sbcount_p =
-		    KMALLOC(sizeof(atomic_t) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(atomic_t) * pobjects, GFP_KERNEL);
 		if (!stopd(sb)->usi_sbcount_p)
 			goto out;
 
 		stopd(sb)->usi_branchperms_p =
-		    KMALLOC(sizeof(int) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(int) * pobjects, GFP_KERNEL);
 		if (!stopd(sb)->usi_branchperms_p)
 			goto out;
 
 		stohiddenmnt_ptr(sb) =
-		    KMALLOC(sizeof(struct vfsmount *) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(struct vfsmount *) * pobjects, GFP_KERNEL);
 		if (!stohiddenmnt_ptr(sb))
 			goto out;
 
@@ -439,10 +435,9 @@ static struct unionfs_dentry_info *union
 	/* allocate private data area */
 	err = -ENOMEM;
 	hidden_root_info =
-	    KMALLOC(sizeof(struct unionfs_dentry_info), GFP_UNIONFS);
+	    kzalloc(sizeof(struct unionfs_dentry_info), GFP_KERNEL);
 	if (!hidden_root_info)
 		goto out_error;
-	memset(hidden_root_info, 0, sizeof(struct unionfs_dentry_info));
 	hidden_root_info->udi_bstart = -1;
 	hidden_root_info->udi_bend = -1;
 	hidden_root_info->udi_bopaque = -1;
@@ -602,16 +597,16 @@ static struct unionfs_dentry_info *union
 		if (stohiddenmnt_index(sb, bindex))
 			mntput(stohiddenmnt_index(sb, bindex));
 	}
-	KFREE(hidden_root_info->udi_dentry_p);
-	KFREE(hidden_root_info);
+	kfree(hidden_root_info->udi_dentry_p);
+	kfree(hidden_root_info);
 
-	KFREE(stohiddenmnt_ptr(sb));
+	kfree(stohiddenmnt_ptr(sb));
 	stohiddenmnt_ptr(sb) = NULL;
-	KFREE(stopd(sb)->usi_sbcount_p);
+	kfree(stopd(sb)->usi_sbcount_p);
 	stopd(sb)->usi_sbcount_p = NULL;
-	KFREE(stopd(sb)->usi_branchperms_p);
+	kfree(stopd(sb)->usi_branchperms_p);
 	stopd(sb)->usi_branchperms_p = NULL;
-	KFREE(stohs_ptr(sb));
+	kfree(stohs_ptr(sb));
 	stohs_ptr(sb) = NULL;
 
 	hidden_root_info = ERR_PTR(err);
@@ -620,153 +615,6 @@ static struct unionfs_dentry_info *union
 	return hidden_root_info;
 }
 
-#ifdef FIST_MALLOC_DEBUG
-/* for malloc debugging */
-atomic_t unionfs_malloc_counter;
-atomic_t unionfs_mallocs_outstanding;
-atomic_t unionfs_dget_counter;
-atomic_t unionfs_dgets_outstanding;
-
-void *unionfs_kmalloc(size_t len, int flag, int line, const char *file)
-{
-	void *ptr = (void *)kmalloc(len, flag);
-	if (ptr) {
-		atomic_inc(&unionfs_malloc_counter);
-		atomic_inc(&unionfs_mallocs_outstanding);
-		printk("KM:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_malloc_counter),
-		       atomic_read(&unionfs_mallocs_outstanding), ptr, line,
-		       file);
-	}
-	return ptr;
-}
-
-void unionfs_kfree(void *ptr, int line, const char *file)
-{
-	atomic_inc(&unionfs_malloc_counter);
-	if (ptr) {
-		BUG_ON(IS_ERR(ptr));
-		atomic_dec(&unionfs_mallocs_outstanding);
-	}
-	printk("KF:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_malloc_counter),
-	       atomic_read(&unionfs_mallocs_outstanding), ptr, line, file);
-	kfree(ptr);
-}
-
-void record_set(struct dentry *upper, int index, struct dentry *ptr,
-		struct dentry *old, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	printk("DD:%d:%d:%d:%p:%d:%s %p, %d\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       old ? atomic_read(&old->d_count) : 0, old, line, file, upper,
-	       index);
-	atomic_inc(&unionfs_dget_counter);
-	printk("DS:%d:%d:%d:%p:%d:%s %p, %d\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file, upper,
-	       index);
-}
-
-void record_path_lookup(struct nameidata *nd, int line, const char *file)
-{
-	struct dentry *ptr = nd->dentry;
-	if (ptr) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DL:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-}
-
-void record_path_release(struct nameidata *nd, int line, const char *file)
-{
-	struct dentry *ptr = nd->dentry;
-
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr)
-		atomic_dec(&unionfs_dgets_outstanding);
-	printk("DP:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-}
-
-struct file *unionfs_dentry_open(struct dentry *ptr, struct vfsmount *mnt,
-				 int flags, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr)
-		atomic_dec(&unionfs_dgets_outstanding);
-	printk("DO:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-	return dentry_open(ptr, mnt, flags);
-}
-
-struct dentry *unionfs_dget(struct dentry *ptr, int line, const char *file)
-{
-	ptr = dget(ptr);
-	if (ptr) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DG:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-	return ptr;
-}
-
-struct dentry *unionfs_dget_parent(struct dentry *child, int line,
-				   const char *file)
-{
-	struct dentry *ptr;
-
-	ptr = dget_parent(child);
-	atomic_inc(&unionfs_dget_counter);
-	atomic_inc(&unionfs_dgets_outstanding);
-	printk("DG:%d:%d:%d:%p:%d:%s\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       atomic_read(&ptr->d_count), ptr, line, file);
-
-	return ptr;
-}
-
-struct dentry *unionfs_lookup_one_len(const char *name, struct dentry *parent,
-				      int len, int line, const char *file)
-{
-	struct dentry *ptr = lookup_one_len(name, parent, len);
-	if (ptr && !IS_ERR(ptr)) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DL:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-	return ptr;
-}
-
-void unionfs_dput(struct dentry *ptr, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr) {
-		BUG_ON(IS_ERR(ptr));
-		atomic_dec(&unionfs_dgets_outstanding);
-	}
-	printk("DP:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-	dput(ptr);
-}
-
-#endif				/* FIST_MALLOC_DEBUG */
-
 static int
 unionfs_read_super(struct super_block *sb, void *raw_data, int silent)
 {
@@ -788,7 +636,7 @@ unionfs_read_super(struct super_block *s
 	/*
 	 * Allocate superblock private data
 	 */
-	stopd_lhs(sb) = KMALLOC(sizeof(struct unionfs_sb_info), GFP_UNIONFS);
+	stopd_lhs(sb) = kmalloc(sizeof(struct unionfs_sb_info), GFP_KERNEL);
 	if (!stopd(sb)) {
 		printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
 		err = -ENOMEM;
@@ -887,7 +735,7 @@ unionfs_read_super(struct super_block *s
 
       out_freedpd:
 	if (dtopd(sb->s_root)) {
-		KFREE(dtohd_ptr(sb->s_root));
+		kfree(dtohd_ptr(sb->s_root));
 		free_dentry_private_data(dtopd(sb->s_root));
 	}
 	DPUT(sb->s_root);
@@ -911,21 +759,21 @@ unionfs_read_super(struct super_block *s
 			if (stopd(sb) && stohiddenmnt_index(sb, bindex))
 				mntput(stohiddenmnt_index(sb, bindex));
 		}
-		KFREE(hidden_root_info->udi_dentry_p);
-		KFREE(hidden_root_info);
+		kfree(hidden_root_info->udi_dentry_p);
+		kfree(hidden_root_info);
 		hidden_root_info = NULL;
 	}
       out_free:
-	KFREE(stohiddenmnt_ptr(sb));
-	KFREE(stopd(sb)->usi_sbcount_p);
-	KFREE(stopd(sb)->usi_branchperms_p);
-	KFREE(stohs_ptr(sb));
-	KFREE(stopd(sb));
+	kfree(stohiddenmnt_ptr(sb));
+	kfree(stopd(sb)->usi_sbcount_p);
+	kfree(stopd(sb)->usi_branchperms_p);
+	kfree(stohs_ptr(sb));
+	kfree(stopd(sb));
 	stopd_lhs(sb) = NULL;
       out:
 	if (hidden_root_info && !IS_ERR(hidden_root_info)) {
-		KFREE(hidden_root_info->udi_dentry_p);
-		KFREE(hidden_root_info);
+		kfree(hidden_root_info->udi_dentry_p);
+		kfree(hidden_root_info);
 	}
 	print_exit_status(err);
 	return err;
@@ -962,11 +810,6 @@ static int __init init_unionfs_fs(void)
 
 	fist_set_debug_value(init_debug);
 
-#ifdef FIST_MALLOC_DEBUG
-	atomic_set(&unionfs_malloc_counter, 0);
-	atomic_set(&unionfs_mallocs_outstanding, 0);
-#endif				/* FIST_MALLOC_DEBUG */
-
 	if ((err = init_filldir_cache()))
 		goto out;
 	if ((err = init_inode_cache()))
Index: unionfs-20060109-2055/persistent_inode.c
===================================================================
--- unionfs-20060109-2055.orig/persistent_inode.c
+++ unionfs-20060109-2055/persistent_inode.c
@@ -61,7 +61,7 @@ static int verify_forwardmap(struct supe
 		goto out;
 	}
 	spd->usi_bmap =
-	    KMALLOC(sizeof(struct bmapent) * header.usedbranches, GFP_UNIONFS);
+	    kmalloc(sizeof(struct bmapent) * header.usedbranches, GFP_KERNEL);
 	spd->usi_num_bmapents = header.usedbranches;
 	if (!spd->usi_bmap) {
 		err = -ENOMEM;
@@ -84,7 +84,7 @@ static int verify_forwardmap(struct supe
 	}
 	set_fs(oldfs);
 	mallocsize = sizeof(int) * header.usedbranches;
-	spd->usi_fsnum_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_fsnum_table = kmalloc(mallocsize, GFP_KERNEL);
 	if (!spd->usi_fsnum_table) {
 		err = -ENOMEM;
 		goto out_err;
@@ -95,9 +95,9 @@ static int verify_forwardmap(struct supe
 	goto out;
       out_err:
 	if (spd->usi_bmap)
-		KFREE(spd->usi_bmap);
+		kfree(spd->usi_bmap);
 	if (spd->usi_fsnum_table)
-		KFREE(spd->usi_fsnum_table);
+		kfree(spd->usi_fsnum_table);
       out:
 	print_exit_status(err);
 	return err;
@@ -253,22 +253,20 @@ int init_imap_data(struct super_block *s
 	spd->usi_bnum_table = NULL;
 
 	mallocsize = sizeof(struct file *) * (hidden_root_info->udi_bend + 1);
-	spd->usi_reversemaps = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_reversemaps = kzalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_reversemaps)) {
 		err = -ENOMEM;
 		goto out_error;
 	}
-	memset(spd->usi_reversemaps, 0, mallocsize);
 
-	spd->usi_map_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_map_table = kzalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_map_table)) {
 		err = -ENOMEM;
 		goto out_error;
 	}
-	memset(spd->usi_map_table, 0, mallocsize);
 
 	mallocsize = sizeof(int) * (hidden_root_info->udi_bend + 1);
-	spd->usi_bnum_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_bnum_table = kmalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_bnum_table)) {
 		err = -ENOMEM;
 		goto out_error;
@@ -283,17 +281,17 @@ int init_imap_data(struct super_block *s
       out_error:
 
 	if (spd->usi_reversemaps) {
-		KFREE(spd->usi_reversemaps);
+		kfree(spd->usi_reversemaps);
 		spd->usi_reversemaps = NULL;
 	}
 
 	if (spd->usi_map_table) {
-		KFREE(spd->usi_map_table);
+		kfree(spd->usi_map_table);
 		spd->usi_map_table = NULL;
 	}
 
 	if (spd->usi_bnum_table) {
-		KFREE(spd->usi_bnum_table);
+		kfree(spd->usi_bnum_table);
 		spd->usi_bnum_table = NULL;
 
 	}
@@ -323,17 +321,17 @@ void cleanup_imap_data(struct super_bloc
 		count--;
 	}
 	if (spd->usi_reversemaps) {
-		KFREE(spd->usi_reversemaps);
+		kfree(spd->usi_reversemaps);
 		spd->usi_reversemaps = NULL;
 	}
 
 	if (spd->usi_map_table) {
-		KFREE(spd->usi_map_table);
+		kfree(spd->usi_map_table);
 		spd->usi_map_table = NULL;
 	}
 
 	if (spd->usi_bnum_table) {
-		KFREE(spd->usi_bnum_table);
+		kfree(spd->usi_bnum_table);
 		spd->usi_bnum_table = NULL;
 	}
 	if (spd->usi_forwardmap) {
Index: unionfs-20060109-2055/rdstate.c
===================================================================
--- unionfs-20060109-2055.orig/rdstate.c
+++ unionfs-20060109-2055/rdstate.c
@@ -150,7 +150,7 @@ struct unionfs_dir_state *alloc_rdstate(
 	    (mallocsize -
 	     sizeof(struct unionfs_dir_state)) / sizeof(struct list_head);
 
-	rdstate = KMALLOC(mallocsize, GFP_UNIONFS);
+	rdstate = kmalloc(mallocsize, GFP_KERNEL);
 	if (!rdstate)
 		return NULL;
 
@@ -177,7 +177,7 @@ struct unionfs_dir_state *alloc_rdstate(
 static void free_filldir_node(struct filldir_node *node)
 {
 	if (node->namelen >= DNAME_INLINE_LEN_MIN)
-		KFREE(node->name);
+		kfree(node->name);
 	kmem_cache_free(unionfs_filldir_cachep, node);
 }
 
@@ -198,7 +198,7 @@ void free_rdstate(struct unionfs_dir_sta
 		}
 	}
 
-	KFREE(state);
+	kfree(state);
 }
 
 struct filldir_node *find_filldir_node(struct unionfs_dir_state *rdstate,
@@ -295,7 +295,7 @@ int add_filldir_node(struct unionfs_dir_
 	if (namelen < DNAME_INLINE_LEN_MIN) {
 		new->name = new->iname;
 	} else {
-		new->name = (char *)KMALLOC(namelen + 1, GFP_UNIONFS);
+		new->name = kmalloc(namelen + 1, GFP_KERNEL);
 		if (!new->name) {
 			kmem_cache_free(unionfs_filldir_cachep, new);
 			new = NULL;
Index: unionfs-20060109-2055/rename.c
===================================================================
--- unionfs-20060109-2055.orig/rename.c
+++ unionfs-20060109-2055/rename.c
@@ -128,7 +128,7 @@ static int do_rename(struct inode *old_d
 			set_dbend(new_dentry, bindex);
 	}
 
-	KFREE(wh_name);
+	kfree(wh_name);
 
 	fist_print_dentry("OUT: do_rename, old_dentry", old_dentry);
 	fist_print_dentry("OUT: do_rename, new_dentry", new_dentry);
@@ -605,7 +605,7 @@ static int unionfs_rename_all(struct ino
 	print_entry_location();
 
 	parent_dentry = old_dentry->d_parent;
-	name = KMALLOC(old_dentry->d_name.len + 1, GFP_UNIONFS);
+	name = kmalloc(old_dentry->d_name.len + 1, GFP_KERNEL);
 	if (!name) {
 		err = -ENOMEM;
 		goto out;
@@ -710,7 +710,7 @@ static int unionfs_rename_all(struct ino
 		err = eio;
 
       out:
-	KFREE(name);
+	kfree(name);
 	print_exit_status(err);
 	return err;
 }
@@ -746,7 +746,7 @@ static struct dentry *lookup_whiteout(st
 	}
 	unlock_dentry(parent);
 	DPUT(parent);
-	KFREE(whname);
+	kfree(whname);
 	return wh_dentry;
 }
 
Index: unionfs-20060109-2055/super.c
===================================================================
--- unionfs-20060109-2055.orig/super.c
+++ unionfs-20060109-2055/super.c
@@ -53,13 +53,12 @@ static void unionfs_read_inode(struct in
 		int size =
 		    (sbmax(inode->i_sb) -
 		     UNIONFS_INLINE_OBJECTS) * sizeof(struct inode *);
-		itohi_ptr(inode) = KMALLOC(size, GFP_UNIONFS);
+		itohi_ptr(inode) = kzalloc(size, GFP_KERNEL);
 		if (!itohi_ptr(inode)) {
 			printk(KERN_ERR
 			       "No kernel memory when allocating lower-pointer array!\n");
 			BUG();
 		}
-		memset(itohi_ptr(inode), 0, size);
 	}
 	memset(itohi_inline(inode), 0,
 	       UNIONFS_INLINE_OBJECTS * sizeof(struct inode *));
@@ -133,12 +132,12 @@ static void unionfs_put_super(struct sup
 		for (bindex = bstart; bindex <= bend; bindex++)
 			BUG_ON(branch_count(sb, bindex) != 0);
 
-		KFREE(stohs_ptr(sb));
-		KFREE(stohiddenmnt_ptr(sb));
-		KFREE(spd->usi_sbcount_p);
-		KFREE(spd->usi_branchperms_p);
-		KFREE(spd->usi_putmaps);
-		KFREE(spd);
+		kfree(stohs_ptr(sb));
+		kfree(stohiddenmnt_ptr(sb));
+		kfree(spd->usi_sbcount_p);
+		kfree(spd->usi_branchperms_p);
+		kfree(spd->usi_putmaps);
+		kfree(spd);
 		stopd_lhs(sb) = NULL;
 	}
 	fist_dprint(6, "unionfs: released super\n");
@@ -297,7 +296,7 @@ static void unionfs_clear_inode(struct i
 	// XXX: why this assertion fails?
 	// because it doesn't like us
 	// BUG_ON((inode->i_state & I_DIRTY) != 0);
-	KFREE(itohi_ptr(inode));
+	kfree(itohi_ptr(inode));
 	itohi_ptr(inode) = NULL;
 
 	print_exit_location();
@@ -437,7 +436,7 @@ static int unionfs_show_options(struct s
 
 	lock_dentry(sb->s_root);
 
-	tmp = __get_free_page(GFP_UNIONFS);
+	tmp = __get_free_page(GFP_KERNEL);
 	if (!tmp) {
 		ret = -ENOMEM;
 		goto out;
Index: unionfs-20060109-2055/unionfs.h
===================================================================
--- unionfs-20060109-2055.orig/unionfs.h
+++ unionfs-20060109-2055/unionfs.h
@@ -48,9 +48,6 @@
 /* Mount time flags */
 #define MOUNT_FLAG(sb)     (stopd(sb)->usi_mount_flag)
 
-/* What type of flags to use for kmalloc, etc. */
-#define GFP_UNIONFS GFP_KERNEL
-
 /*UUID typedef needed later*/
 typedef uint8_t uuid_t[16];
 
@@ -620,7 +617,7 @@ static inline char *alloc_whname(const c
 {
 	char *buf;
 
-	buf = KMALLOC(len + WHLEN + 1, GFP_UNIONFS);
+	buf = kmalloc(len + WHLEN + 1, GFP_KERNEL);
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
Index: unionfs-20060109-2055/fist.h
===================================================================
--- unionfs-20060109-2055.orig/fist.h
+++ unionfs-20060109-2055/fist.h
@@ -92,9 +92,6 @@
  */
 
 #ifdef FIST_MALLOC_DEBUG
-extern void *unionfs_kmalloc(size_t len, int flag, int line, const char *file);
-extern void unionfs_kfree(void *ptr, int line, const char *file);
-
 extern struct dentry *unionfs_dget_parent(struct dentry *child, int line,
 					  const char *file);
 extern struct dentry *unionfs_dget(struct dentry *ptr, int line,
@@ -110,8 +107,6 @@ struct file *unionfs_dentry_open(struct 
 void record_set(struct dentry *upper, int index, struct dentry *ptr,
 		struct dentry *old, int line, const char *file);
 
-#define KMALLOC(size,flag) unionfs_kmalloc((size),(flag),__LINE__,__FILE__)
-#define KFREE(ptr) unionfs_kfree((ptr),__LINE__,__FILE__)
 #define DGET(d) unionfs_dget((d),__LINE__,__FILE__)
 #define DPUT(d) unionfs_dput((d),__LINE__,__FILE__)
 #define LOOKUP_ONE_LEN(name,parent,len) unionfs_lookup_one_len((name),(parent),(len),__LINE__,__FILE__)
@@ -124,8 +119,6 @@ void record_set(struct dentry *upper, in
 # define DENTRY_OPEN(d,m,f) unionfs_dentry_open((d),(m),(f),__LINE__,__FILE__)
 # define GET_PARENT(dentry) unionfs_dget_parent((dentry),__LINE__,__FILE__)
 #else				/* not FIST_MALLOC_DEBUG */
-# define KMALLOC(a,b)		kmalloc((a),(b))
-# define KFREE(a)		kfree((a))
 # define DPUT(a)		dput((a))
 # define DGET(a)		dget((a))
 # define LOOKUP_ONE_LEN(a,b,c)	lookup_one_len((a),(b),(c))

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] unionfs: kmalloc cleanups
@ 2006-01-10 12:40 Pekka J Enberg
  0 siblings, 0 replies; 2+ messages in thread
From: Pekka J Enberg @ 2006-01-10 12:40 UTC (permalink / raw)
  To: unionfs; +Cc: linux-fsdevel

Hi,

[Please consider allowing posts from non-subscribers to unionfs list.]

This patch removes the KMALLOC and KFREE wrappers from unionfs and converts
callers to use proper kmalloc, kzalloc, kcalloc, and kfree where appropriate.
This patch also replaces the use of GFP_UNIONFS macro with GFP_KERNEL.

The use of debugging memory allocator wrappers is discouraged in the Linux
kernel and there are plenty of memory leak tracking patches floating around
(in -mm in particular). While unionfs is an out-of-tree filesystem, this
patch is one small step in bringing unionfs ready for inclusion so please
consider applying this patch.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 branchman.c        |   68 +++++++----------
 commonfops.c       |   29 +++----
 copyup.c           |   19 ++--
 dirhelper.c        |    6 -
 fist.h             |    7 -
 inode.c            |   16 ++--
 main.c             |  207 ++++++-----------------------------------------------
 persistent_inode.c |   28 +++----
 rdstate.c          |    8 +-
 rename.c           |    8 +-
 super.c            |   19 ++--
 unionfs.h          |    5 -
 12 files changed, 120 insertions(+), 300 deletions(-)

Index: unionfs-20060109-2055/branchman.c
===================================================================
--- unionfs-20060109-2055.orig/branchman.c
+++ unionfs-20060109-2055/branchman.c
@@ -57,7 +57,7 @@ static int newputmap(struct super_block 
 	spd = stopd(sb);
 
 	i = sizeof(int) * (sbend(sb) + 1);
-	newmap = KMALLOC(sizeof(struct putmap) + i, GFP_UNIONFS);
+	newmap = kmalloc(sizeof(struct putmap) + i, GFP_KERNEL);
 	if (!newmap) {
 		print_exit_status(-ENOMEM);
 		return -ENOMEM;
@@ -68,9 +68,9 @@ static int newputmap(struct super_block 
 		spd->usi_lastputmap = 1;
 
 		spd->usi_putmaps =
-		    KMALLOC(sizeof(struct putmap *), GFP_UNIONFS);
+		    kmalloc(sizeof(struct putmap *), GFP_KERNEL);
 		if (!spd->usi_putmaps) {
-			KFREE(newmap);
+			kfree(newmap);
 			print_exit_status(-ENOMEM);
 			return -ENOMEM;
 		}
@@ -83,11 +83,10 @@ static int newputmap(struct super_block 
 			newfirst++;
 		}
 
-		newlist =
-		    KMALLOC(sizeof(struct putmap *) *
-			    (1 + spd->usi_lastputmap - newfirst), GFP_UNIONFS);
+		newlist = kcalloc(1 + spd->usi_lastputmap - newfirst,
+				  sizeof(struct putmap *), GFP_KERNEL);
 		if (!newlist) {
-			KFREE(newmap);
+			kfree(newmap);
 			print_exit_status(-ENOMEM);
 			return -ENOMEM;
 		}
@@ -97,7 +96,7 @@ static int newputmap(struct super_block 
 			    spd->usi_putmaps[i - spd->usi_firstputmap];
 		}
 
-		KFREE(spd->usi_putmaps);
+		kfree(spd->usi_putmaps);
 		spd->usi_putmaps = newlist;
 		spd->usi_firstputmap = newfirst;
 		spd->usi_lastputmap++;
@@ -202,7 +201,7 @@ int unionfs_ioctl_addbranch(struct inode
 	print_entry_location();
 
 	err = -ENOMEM;
-	addargs = KMALLOC(sizeof(struct unionfs_addbranch_args), GFP_UNIONFS);
+	addargs = kmalloc(sizeof(struct unionfs_addbranch_args), GFP_KERNEL);
 	if (!addargs)
 		goto out;
 
@@ -270,26 +269,21 @@ int unionfs_ioctl_addbranch(struct inode
 	if (pobjects > 0) {
 		/* Reallocate the dynamic structures. */
 		new_hidden_mnt =
-		    KMALLOC(sizeof(struct vfsmount *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct vfsmount *), GFP_KERNEL);
 		new_udi_dentry =
-		    KMALLOC(sizeof(struct dentry *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct dentry *), GFP_KERNEL);
 		new_uii_inode =
-		    KMALLOC(sizeof(struct inode *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct inode *), GFP_KERNEL);
 		new_usi_sb =
-		    KMALLOC(sizeof(struct super_block *) * pobjects,
-			    GFP_UNIONFS);
-		new_counts = KMALLOC(sizeof(atomic_t) * pobjects, GFP_UNIONFS);
-		new_branchperms = KMALLOC(sizeof(int) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct super_block *),
+			    GFP_KERNEL);
+		new_counts = kmalloc(sizeof(atomic_t) * pobjects, GFP_KERNEL);
+		new_branchperms = kcalloc(pobjects, sizeof(int), GFP_KERNEL);
 		if (!new_hidden_mnt || !new_udi_dentry || !new_uii_inode
 		    || !new_counts || !new_usi_sb || !new_branchperms) {
 			err = -ENOMEM;
 			goto out;
 		}
-		memset(new_hidden_mnt, 0, sizeof(struct vfsmount *) * pobjects);
-		memset(new_udi_dentry, 0, sizeof(struct dentry *) * pobjects);
-		memset(new_uii_inode, 0, sizeof(struct inode *) * pobjects);
-		memset(new_usi_sb, 0, sizeof(struct super_block *) * pobjects);
-		memset(new_branchperms, 0, sizeof(int) * pobjects);
 	}
 
 	/* Copy the in-place values to our new structure. */
@@ -348,12 +342,12 @@ int unionfs_ioctl_addbranch(struct inode
 	}
 
 	/* Now we can free the old ones. */
-	KFREE(dtopd(inode->i_sb->s_root)->udi_dentry_p);
-	KFREE(itopd(inode->i_sb->s_root->d_inode)->uii_inode_p);
-	KFREE(stopd(inode->i_sb)->usi_hidden_mnt_p);
-	KFREE(stopd(inode->i_sb)->usi_sb_p);
-	KFREE(stopd(inode->i_sb)->usi_sbcount_p);
-	KFREE(stopd(inode->i_sb)->usi_branchperms_p);
+	kfree(dtopd(inode->i_sb->s_root)->udi_dentry_p);
+	kfree(itopd(inode->i_sb->s_root->d_inode)->uii_inode_p);
+	kfree(stopd(inode->i_sb)->usi_hidden_mnt_p);
+	kfree(stopd(inode->i_sb)->usi_sb_p);
+	kfree(stopd(inode->i_sb)->usi_sbcount_p);
+	kfree(stopd(inode->i_sb)->usi_branchperms_p);
 
 	/* Update the real pointers. */
 	dtohd_ptr(inode->i_sb->s_root) = new_udi_dentry;
@@ -389,13 +383,13 @@ int unionfs_ioctl_addbranch(struct inode
 	unlock_dentry(inode->i_sb->s_root);
 	unionfs_write_unlock(inode->i_sb);
 
-	KFREE(new_hidden_mnt);
-	KFREE(new_udi_dentry);
-	KFREE(new_uii_inode);
-	KFREE(new_usi_sb);
-	KFREE(new_counts);
-	KFREE(new_branchperms);
-	KFREE(addargs);
+	kfree(new_hidden_mnt);
+	kfree(new_udi_dentry);
+	kfree(new_uii_inode);
+	kfree(new_usi_sb);
+	kfree(new_counts);
+	kfree(new_branchperms);
+	kfree(addargs);
 	if (path)
 		putname(path);
 
@@ -476,7 +470,7 @@ int unionfs_ioctl_delbranch(struct super
 
 	/* This doesn't open a file, so we might have to free the map here. */
 	if (atomic_read(&stopd(sb)->usi_putmaps[pmindex]->count) == 0) {
-		KFREE(stopd(sb)->usi_putmaps[pmindex]);
+		kfree(stopd(sb)->usi_putmaps[pmindex]);
 		stopd(sb)->usi_putmaps[pmindex] = NULL;
 	}
 
@@ -503,7 +497,7 @@ int unionfs_ioctl_rdwrbranch(struct inod
 		goto out;
 
 	err = -ENOMEM;
-	rdwrargs = KMALLOC(sizeof(struct unionfs_rdwrbranch_args), GFP_UNIONFS);
+	rdwrargs = kmalloc(sizeof(struct unionfs_rdwrbranch_args), GFP_KERNEL);
 	if (!rdwrargs)
 		goto out;
 
@@ -534,7 +528,7 @@ int unionfs_ioctl_rdwrbranch(struct inod
       out:
 	unlock_dentry(inode->i_sb->s_root);
 	unionfs_write_unlock(inode->i_sb);
-	KFREE(rdwrargs);
+	kfree(rdwrargs);
 
 	print_exit_status(err);
 
Index: unionfs-20060109-2055/commonfops.c
===================================================================
--- unionfs-20060109-2055.orig/commonfops.c
+++ unionfs-20060109-2055/commonfops.c
@@ -47,7 +47,7 @@ static inline void branchput_gen(int gen
 		stopd(sb)->usi_putmaps[generation - stopd(sb)->usi_firstputmap]
 		    = NULL;
 		fist_dprint(8, "Freeing putmap %d.\n", generation);
-		KFREE(putmap);
+		kfree(putmap);
 	}
 }
 
@@ -61,16 +61,16 @@ static char *get_random_name(int size, u
 		return NULL;
 
 	if (!name)
-		name = KMALLOC(size + 1, GFP_UNIONFS);
+		name = kmalloc(size + 1, GFP_KERNEL);
 	if (!name) {
 		name = ERR_PTR(-ENOMEM);
 		goto out;
 	}
 	strncpy(name, WHPFX, WHLEN);
 
-	tmpbuf = KMALLOC(size, GFP_UNIONFS);
+	tmpbuf = kmalloc(size, GFP_KERNEL);
 	if (!tmpbuf) {
-		KFREE(name);
+		kfree(name);
 		name = ERR_PTR(-ENOMEM);
 		goto out;
 	}
@@ -99,7 +99,7 @@ static char *get_random_name(int size, u
 	name[size] = '\0';
 
       out:
-	KFREE(tmpbuf);
+	kfree(tmpbuf);
 	return (name);
 
 }
@@ -153,7 +153,7 @@ static int copyup_deleted_file(struct fi
 	unlock_dir(hidden_dir_dentry);
 
       out:
-	KFREE(name);
+	kfree(name);
 	print_exit_status(err);
 	return err;
 }
@@ -203,7 +203,7 @@ int unionfs_file_revalidate(struct file 
 			}
 		}
 		if (ftohf_ptr(file)) {
-			KFREE(ftohf_ptr(file));
+			kfree(ftohf_ptr(file));
 			ftohf_ptr(file) = NULL;
 		}
 
@@ -215,7 +215,7 @@ int unionfs_file_revalidate(struct file 
 			int size =
 			    sizeof(struct file *) * (sbmax(sb) -
 						     UNIONFS_INLINE_OBJECTS);
-			ftohf_ptr(file) = KMALLOC(size, GFP_UNIONFS);
+			ftohf_ptr(file) = kmalloc(size, GFP_KERNEL);
 			if (!ftohf_ptr(file)) {
 				err = -ENOMEM;
 				goto out;
@@ -364,12 +364,11 @@ int unionfs_open(struct inode *inode, st
 	print_entry_location();
 
 	ftopd_lhs(file) =
-	    KMALLOC(sizeof(struct unionfs_file_info), GFP_UNIONFS);
+	    kzalloc(sizeof(struct unionfs_file_info), GFP_KERNEL);
 	if (!ftopd(file)) {
 		err = -ENOMEM;
 		goto out;
 	}
-	memset(ftopd(file), 0, sizeof(struct unionfs_file_info));
 	fbstart(file) = -1;
 	fbend(file) = -1;
 	atomic_set(&ftopd(file)->ufi_generation,
@@ -378,7 +377,7 @@ int unionfs_open(struct inode *inode, st
 		int size =
 		    sizeof(struct file *) * (sbmax(inode->i_sb) -
 					     UNIONFS_INLINE_OBJECTS);
-		ftohf_ptr(file) = KMALLOC(size, GFP_UNIONFS);
+		ftohf_ptr(file) = kmalloc(size, GFP_KERNEL);
 		if (!ftohf_ptr(file)) {
 			err = -ENOMEM;
 			goto out;
@@ -490,8 +489,8 @@ int unionfs_open(struct inode *inode, st
 		}
 		if (!locked)
 			unionfs_read_unlock(file->f_dentry->d_sb);
-		KFREE(ftohf_ptr(file));
-		KFREE(ftopd(file));
+		kfree(ftohf_ptr(file));
+		kfree(ftopd(file));
 	}
 
 	fist_print_file("OUT: unionfs_open", file);
@@ -530,7 +529,7 @@ int unionfs_file_release(struct inode *i
 			unionfs_read_unlock(inode->i_sb);
 		}
 	}
-	KFREE(ftohf_ptr(file));
+	kfree(ftohf_ptr(file));
 
 	if (ftopd(file)->rdstate) {
 		ftopd(file)->rdstate->uds_access = jiffies;
@@ -546,7 +545,7 @@ int unionfs_file_release(struct inode *i
 		spin_unlock(&itopd(inode)->uii_rdlock);
 		ftopd(file)->rdstate = NULL;
 	}
-	KFREE(ftopd(file));
+	kfree(ftopd(file));
 
 	fist_checkinode(inode, "post unionfs_release");
 
Index: unionfs-20060109-2055/copyup.c
===================================================================
--- unionfs-20060109-2055.orig/copyup.c
+++ unionfs-20060109-2055/copyup.c
@@ -241,7 +241,7 @@ int copyup_named_dentry(struct inode *di
 	/* For symlinks, we must read the link before we lock the directory. */
 	if (S_ISLNK(old_hidden_dentry->d_inode->i_mode)) {
 
-		symbuf = KMALLOC(PATH_MAX, GFP_UNIONFS);
+		symbuf = kmalloc(PATH_MAX, GFP_KERNEL);
 		if (!symbuf) {
 			err = -ENOMEM;
 			goto copyup_readlink_err;
@@ -291,7 +291,7 @@ int copyup_named_dentry(struct inode *di
 	current->fsgid = saved_gid;
 	unlock_dir(new_hidden_parent_dentry);
       copyup_readlink_err:
-	KFREE(symbuf);
+	kfree(symbuf);
 	if (err) {
 		/* get rid of the hidden dentry and all its traces */
 		DPUT(new_hidden_dentry);
@@ -336,7 +336,7 @@ int copyup_named_dentry(struct inode *di
 		}
 
 		/* allocating a buffer */
-		buf = (char *)KMALLOC(PAGE_SIZE, GFP_UNIONFS);
+		buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
 		if (!buf) {
 			err = -ENOMEM;
 			goto out;
@@ -377,7 +377,7 @@ int copyup_named_dentry(struct inode *di
 			}
 		} while ((read_bytes > 0) && (len > 0));
 		set_fs(old_fs);
-		KFREE(buf);
+		kfree(buf);
 	}
 
 	/* Set permissions. */
@@ -530,8 +530,7 @@ struct dentry *create_parents_named(stru
 	old_bstart = dbstart(dentry);
 	old_bend = dbend(dentry);
 
-	path = (struct dentry **)KMALLOC(kmalloc_size, GFP_KERNEL);
-	memset(path, 0, kmalloc_size);
+	path = kzalloc(kmalloc_size, GFP_KERNEL);
 
 	/* assume the negative dentry of unionfs as the parent dentry */
 	parent_dentry = dentry;
@@ -562,15 +561,13 @@ struct dentry *create_parents_named(stru
 			kmalloc_size *= 2;
 			num_dentry = kmalloc_size / sizeof(struct dentry *);
 
-			tmp_path =
-			    (struct dentry **)KMALLOC(kmalloc_size, GFP_KERNEL);
+			tmp_path = kzalloc(kmalloc_size, GFP_KERNEL);
 			if (!tmp_path) {
 				hidden_dentry = ERR_PTR(-ENOMEM);
 				goto out;
 			}
-			memset(tmp_path, 0, kmalloc_size);
 			memcpy(tmp_path, path, old_kmalloc_size);
-			KFREE(path);
+			kfree(path);
 			path = tmp_path;
 			tmp_path = NULL;
 		}
@@ -702,7 +699,7 @@ struct dentry *create_parents_named(stru
 		child_dentry = path[--count];
 	}
       out:
-	KFREE(path);
+	kfree(path);
 	fist_print_dentry("OUT: create_parents_named", dentry);
 	print_exit_pointer(hidden_dentry);
 	return hidden_dentry;
Index: unionfs-20060109-2055/dirhelper.c
===================================================================
--- unionfs-20060109-2055.orig/dirhelper.c
+++ unionfs-20060109-2055/dirhelper.c
@@ -48,7 +48,7 @@ int delete_whiteouts(struct dentry *dent
 	hidden_dir_dentry = dtohd_index(dentry, bindex);
 	BUG_ON(!S_ISDIR(hidden_dir_dentry->d_inode->i_mode));
 
-	name = (char *)__get_free_page(GFP_UNIONFS);
+	name = (char *)__get_free_page(GFP_KERNEL);
 	if (!name) {
 		err = -ENOMEM;
 		goto out;
@@ -182,7 +182,7 @@ int check_empty(struct dentry *dentry, s
 	if (0 <= bopaque && bopaque < bend)
 		bend = bopaque;
 
-	buf = KMALLOC(sizeof(struct unionfs_rdutil_callback), GFP_UNIONFS);
+	buf = kmalloc(sizeof(struct unionfs_rdutil_callback), GFP_KERNEL);
 	if (!buf) {
 		err = -ENOMEM;
 		goto out;
@@ -241,7 +241,7 @@ int check_empty(struct dentry *dentry, s
 			*namelist = buf->rdstate;
 		else if (buf->rdstate)
 			free_rdstate(buf->rdstate);
-		KFREE(buf);
+		kfree(buf);
 	}
 
 	unionfs_read_unlock(sb);
Index: unionfs-20060109-2055/inode.c
===================================================================
--- unionfs-20060109-2055.orig/inode.c
+++ unionfs-20060109-2055/inode.c
@@ -191,7 +191,7 @@ static int unionfs_create(struct inode *
 
       out:
 	DPUT(whiteout_dentry);
-	KFREE(name);
+	kfree(name);
 
 	fist_print_dentry("OUT unionfs_create :", dentry);
 	unlock_dentry(dentry);
@@ -323,7 +323,7 @@ static int unionfs_link(struct dentry *o
 	if (!new_dentry->d_inode)
 		d_drop(new_dentry);
 
-	KFREE(name);
+	kfree(name);
 
 	unlock_dentry(new_dentry);
 	unlock_dentry(old_dentry);
@@ -451,7 +451,7 @@ static int unionfs_symlink(struct inode 
 	if (!dentry->d_inode)
 		d_drop(dentry);
 
-	KFREE(name);
+	kfree(name);
 	fist_print_dentry("OUT unionfs_symlink :", dentry);
 	unlock_dentry(dentry);
 	print_exit_status(err);
@@ -602,7 +602,7 @@ static int unionfs_mkdir(struct inode *p
 	if (!dentry->d_inode)
 		d_drop(dentry);
 
-	KFREE(name);
+	kfree(name);
 
 	fist_print_dentry("OUT unionfs_mkdir :", dentry);
 	unlock_dentry(dentry);
@@ -714,7 +714,7 @@ static int unionfs_mknod(struct inode *d
 		d_drop(dentry);
 
 	if (name) {
-		KFREE(name);
+		kfree(name);
 	}
 
 	fist_print_dentry("OUT unionfs_mknod :", dentry);
@@ -764,7 +764,7 @@ static void *unionfs_follow_link(struct 
 	print_entry_location();
 
 	/* This is freed by the put_link method assuming a successful call. */
-	buf = (char *)KMALLOC(len, GFP_UNIONFS);
+	buf = kmalloc(len, GFP_KERNEL);
 	if (!buf) {
 		err = -ENOMEM;
 		goto out;
@@ -776,7 +776,7 @@ static void *unionfs_follow_link(struct 
 	err = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
 	set_fs(old_fs);
 	if (err < 0) {
-		KFREE(buf);
+		kfree(buf);
 		buf = NULL;
 		goto out;
 	}
@@ -802,7 +802,7 @@ void unionfs_put_link(struct dentry *den
 	char *link;
 	print_entry_location();
 	link = nd_get_link(nd);
-	KFREE(link);
+	kfree(link);
 	print_exit_location();
 }
 
Index: unionfs-20060109-2055/main.c
===================================================================
--- unionfs-20060109-2055.orig/main.c
+++ unionfs-20060109-2055/main.c
@@ -74,12 +74,11 @@ int unionfs_interpose(struct dentry *den
 			int size =
 			    (sbmax(sb) -
 			     UNIONFS_INLINE_OBJECTS) * sizeof(struct inode *);
-			itohi_ptr(inode) = KMALLOC(size, GFP_UNIONFS);
+			itohi_ptr(inode) = kzalloc(size, GFP_KERNEL);
 			if (!itohi_ptr(inode)) {
 				err = -ENOMEM;
 				goto out;
 			}
-			memset(itohi_ptr(inode), 0, size);
 		}
 		memset(itohi_inline(inode), 0,
 		       UNIONFS_INLINE_OBJECTS * sizeof(struct inode *));
@@ -277,16 +276,13 @@ static int parse_dirs_option(struct supe
 		err = -ENOMEM;
 
 		hidden_root_info->udi_dentry_p =
-		    KMALLOC(sizeof(struct dentry *) * pobjects, GFP_UNIONFS);
+		    kcalloc(pobjects, sizeof(struct dentry *), GFP_KERNEL);
 		if (!hidden_root_info->udi_dentry_p)
 			goto out;
 
-		memset(hidden_root_info->udi_dentry_p, 0,
-		       sizeof(struct dentry *) * pobjects);
-
 		stohs_ptr(sb) =
-		    KMALLOC(sizeof(struct super_block *) *
-			    pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(struct super_block *) *
+			    pobjects, GFP_KERNEL);
 		if (!stohs_ptr(sb))
 			goto out;
 
@@ -294,17 +290,17 @@ static int parse_dirs_option(struct supe
 		       pobjects * sizeof(struct super_block *));
 
 		stopd(sb)->usi_sbcount_p =
-		    KMALLOC(sizeof(atomic_t) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(atomic_t) * pobjects, GFP_KERNEL);
 		if (!stopd(sb)->usi_sbcount_p)
 			goto out;
 
 		stopd(sb)->usi_branchperms_p =
-		    KMALLOC(sizeof(int) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(int) * pobjects, GFP_KERNEL);
 		if (!stopd(sb)->usi_branchperms_p)
 			goto out;
 
 		stohiddenmnt_ptr(sb) =
-		    KMALLOC(sizeof(struct vfsmount *) * pobjects, GFP_UNIONFS);
+		    kmalloc(sizeof(struct vfsmount *) * pobjects, GFP_KERNEL);
 		if (!stohiddenmnt_ptr(sb))
 			goto out;
 
@@ -439,10 +435,9 @@ static struct unionfs_dentry_info *union
 	/* allocate private data area */
 	err = -ENOMEM;
 	hidden_root_info =
-	    KMALLOC(sizeof(struct unionfs_dentry_info), GFP_UNIONFS);
+	    kzalloc(sizeof(struct unionfs_dentry_info), GFP_KERNEL);
 	if (!hidden_root_info)
 		goto out_error;
-	memset(hidden_root_info, 0, sizeof(struct unionfs_dentry_info));
 	hidden_root_info->udi_bstart = -1;
 	hidden_root_info->udi_bend = -1;
 	hidden_root_info->udi_bopaque = -1;
@@ -602,16 +597,16 @@ static struct unionfs_dentry_info *union
 		if (stohiddenmnt_index(sb, bindex))
 			mntput(stohiddenmnt_index(sb, bindex));
 	}
-	KFREE(hidden_root_info->udi_dentry_p);
-	KFREE(hidden_root_info);
+	kfree(hidden_root_info->udi_dentry_p);
+	kfree(hidden_root_info);
 
-	KFREE(stohiddenmnt_ptr(sb));
+	kfree(stohiddenmnt_ptr(sb));
 	stohiddenmnt_ptr(sb) = NULL;
-	KFREE(stopd(sb)->usi_sbcount_p);
+	kfree(stopd(sb)->usi_sbcount_p);
 	stopd(sb)->usi_sbcount_p = NULL;
-	KFREE(stopd(sb)->usi_branchperms_p);
+	kfree(stopd(sb)->usi_branchperms_p);
 	stopd(sb)->usi_branchperms_p = NULL;
-	KFREE(stohs_ptr(sb));
+	kfree(stohs_ptr(sb));
 	stohs_ptr(sb) = NULL;
 
 	hidden_root_info = ERR_PTR(err);
@@ -620,153 +615,6 @@ static struct unionfs_dentry_info *union
 	return hidden_root_info;
 }
 
-#ifdef FIST_MALLOC_DEBUG
-/* for malloc debugging */
-atomic_t unionfs_malloc_counter;
-atomic_t unionfs_mallocs_outstanding;
-atomic_t unionfs_dget_counter;
-atomic_t unionfs_dgets_outstanding;
-
-void *unionfs_kmalloc(size_t len, int flag, int line, const char *file)
-{
-	void *ptr = (void *)kmalloc(len, flag);
-	if (ptr) {
-		atomic_inc(&unionfs_malloc_counter);
-		atomic_inc(&unionfs_mallocs_outstanding);
-		printk("KM:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_malloc_counter),
-		       atomic_read(&unionfs_mallocs_outstanding), ptr, line,
-		       file);
-	}
-	return ptr;
-}
-
-void unionfs_kfree(void *ptr, int line, const char *file)
-{
-	atomic_inc(&unionfs_malloc_counter);
-	if (ptr) {
-		BUG_ON(IS_ERR(ptr));
-		atomic_dec(&unionfs_mallocs_outstanding);
-	}
-	printk("KF:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_malloc_counter),
-	       atomic_read(&unionfs_mallocs_outstanding), ptr, line, file);
-	kfree(ptr);
-}
-
-void record_set(struct dentry *upper, int index, struct dentry *ptr,
-		struct dentry *old, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	printk("DD:%d:%d:%d:%p:%d:%s %p, %d\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       old ? atomic_read(&old->d_count) : 0, old, line, file, upper,
-	       index);
-	atomic_inc(&unionfs_dget_counter);
-	printk("DS:%d:%d:%d:%p:%d:%s %p, %d\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file, upper,
-	       index);
-}
-
-void record_path_lookup(struct nameidata *nd, int line, const char *file)
-{
-	struct dentry *ptr = nd->dentry;
-	if (ptr) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DL:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-}
-
-void record_path_release(struct nameidata *nd, int line, const char *file)
-{
-	struct dentry *ptr = nd->dentry;
-
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr)
-		atomic_dec(&unionfs_dgets_outstanding);
-	printk("DP:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-}
-
-struct file *unionfs_dentry_open(struct dentry *ptr, struct vfsmount *mnt,
-				 int flags, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr)
-		atomic_dec(&unionfs_dgets_outstanding);
-	printk("DO:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-	return dentry_open(ptr, mnt, flags);
-}
-
-struct dentry *unionfs_dget(struct dentry *ptr, int line, const char *file)
-{
-	ptr = dget(ptr);
-	if (ptr) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DG:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-	return ptr;
-}
-
-struct dentry *unionfs_dget_parent(struct dentry *child, int line,
-				   const char *file)
-{
-	struct dentry *ptr;
-
-	ptr = dget_parent(child);
-	atomic_inc(&unionfs_dget_counter);
-	atomic_inc(&unionfs_dgets_outstanding);
-	printk("DG:%d:%d:%d:%p:%d:%s\n",
-	       atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       atomic_read(&ptr->d_count), ptr, line, file);
-
-	return ptr;
-}
-
-struct dentry *unionfs_lookup_one_len(const char *name, struct dentry *parent,
-				      int len, int line, const char *file)
-{
-	struct dentry *ptr = lookup_one_len(name, parent, len);
-	if (ptr && !IS_ERR(ptr)) {
-		atomic_inc(&unionfs_dget_counter);
-		atomic_inc(&unionfs_dgets_outstanding);
-		printk("DL:%d:%d:%d:%p:%d:%s\n",
-		       atomic_read(&unionfs_dget_counter),
-		       atomic_read(&unionfs_dgets_outstanding),
-		       atomic_read(&ptr->d_count), ptr, line, file);
-	}
-	return ptr;
-}
-
-void unionfs_dput(struct dentry *ptr, int line, const char *file)
-{
-	atomic_inc(&unionfs_dget_counter);
-	if (ptr) {
-		BUG_ON(IS_ERR(ptr));
-		atomic_dec(&unionfs_dgets_outstanding);
-	}
-	printk("DP:%d:%d:%d:%p:%d:%s\n", atomic_read(&unionfs_dget_counter),
-	       atomic_read(&unionfs_dgets_outstanding),
-	       ptr ? atomic_read(&ptr->d_count) : 0, ptr, line, file);
-	dput(ptr);
-}
-
-#endif				/* FIST_MALLOC_DEBUG */
-
 static int
 unionfs_read_super(struct super_block *sb, void *raw_data, int silent)
 {
@@ -788,7 +636,7 @@ unionfs_read_super(struct super_block *s
 	/*
 	 * Allocate superblock private data
 	 */
-	stopd_lhs(sb) = KMALLOC(sizeof(struct unionfs_sb_info), GFP_UNIONFS);
+	stopd_lhs(sb) = kmalloc(sizeof(struct unionfs_sb_info), GFP_KERNEL);
 	if (!stopd(sb)) {
 		printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
 		err = -ENOMEM;
@@ -887,7 +735,7 @@ unionfs_read_super(struct super_block *s
 
       out_freedpd:
 	if (dtopd(sb->s_root)) {
-		KFREE(dtohd_ptr(sb->s_root));
+		kfree(dtohd_ptr(sb->s_root));
 		free_dentry_private_data(dtopd(sb->s_root));
 	}
 	DPUT(sb->s_root);
@@ -911,21 +759,21 @@ unionfs_read_super(struct super_block *s
 			if (stopd(sb) && stohiddenmnt_index(sb, bindex))
 				mntput(stohiddenmnt_index(sb, bindex));
 		}
-		KFREE(hidden_root_info->udi_dentry_p);
-		KFREE(hidden_root_info);
+		kfree(hidden_root_info->udi_dentry_p);
+		kfree(hidden_root_info);
 		hidden_root_info = NULL;
 	}
       out_free:
-	KFREE(stohiddenmnt_ptr(sb));
-	KFREE(stopd(sb)->usi_sbcount_p);
-	KFREE(stopd(sb)->usi_branchperms_p);
-	KFREE(stohs_ptr(sb));
-	KFREE(stopd(sb));
+	kfree(stohiddenmnt_ptr(sb));
+	kfree(stopd(sb)->usi_sbcount_p);
+	kfree(stopd(sb)->usi_branchperms_p);
+	kfree(stohs_ptr(sb));
+	kfree(stopd(sb));
 	stopd_lhs(sb) = NULL;
       out:
 	if (hidden_root_info && !IS_ERR(hidden_root_info)) {
-		KFREE(hidden_root_info->udi_dentry_p);
-		KFREE(hidden_root_info);
+		kfree(hidden_root_info->udi_dentry_p);
+		kfree(hidden_root_info);
 	}
 	print_exit_status(err);
 	return err;
@@ -962,11 +810,6 @@ static int __init init_unionfs_fs(void)
 
 	fist_set_debug_value(init_debug);
 
-#ifdef FIST_MALLOC_DEBUG
-	atomic_set(&unionfs_malloc_counter, 0);
-	atomic_set(&unionfs_mallocs_outstanding, 0);
-#endif				/* FIST_MALLOC_DEBUG */
-
 	if ((err = init_filldir_cache()))
 		goto out;
 	if ((err = init_inode_cache()))
Index: unionfs-20060109-2055/persistent_inode.c
===================================================================
--- unionfs-20060109-2055.orig/persistent_inode.c
+++ unionfs-20060109-2055/persistent_inode.c
@@ -61,7 +61,7 @@ static int verify_forwardmap(struct supe
 		goto out;
 	}
 	spd->usi_bmap =
-	    KMALLOC(sizeof(struct bmapent) * header.usedbranches, GFP_UNIONFS);
+	    kmalloc(sizeof(struct bmapent) * header.usedbranches, GFP_KERNEL);
 	spd->usi_num_bmapents = header.usedbranches;
 	if (!spd->usi_bmap) {
 		err = -ENOMEM;
@@ -84,7 +84,7 @@ static int verify_forwardmap(struct supe
 	}
 	set_fs(oldfs);
 	mallocsize = sizeof(int) * header.usedbranches;
-	spd->usi_fsnum_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_fsnum_table = kmalloc(mallocsize, GFP_KERNEL);
 	if (!spd->usi_fsnum_table) {
 		err = -ENOMEM;
 		goto out_err;
@@ -95,9 +95,9 @@ static int verify_forwardmap(struct supe
 	goto out;
       out_err:
 	if (spd->usi_bmap)
-		KFREE(spd->usi_bmap);
+		kfree(spd->usi_bmap);
 	if (spd->usi_fsnum_table)
-		KFREE(spd->usi_fsnum_table);
+		kfree(spd->usi_fsnum_table);
       out:
 	print_exit_status(err);
 	return err;
@@ -253,22 +253,20 @@ int init_imap_data(struct super_block *s
 	spd->usi_bnum_table = NULL;
 
 	mallocsize = sizeof(struct file *) * (hidden_root_info->udi_bend + 1);
-	spd->usi_reversemaps = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_reversemaps = kzalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_reversemaps)) {
 		err = -ENOMEM;
 		goto out_error;
 	}
-	memset(spd->usi_reversemaps, 0, mallocsize);
 
-	spd->usi_map_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_map_table = kzalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_map_table)) {
 		err = -ENOMEM;
 		goto out_error;
 	}
-	memset(spd->usi_map_table, 0, mallocsize);
 
 	mallocsize = sizeof(int) * (hidden_root_info->udi_bend + 1);
-	spd->usi_bnum_table = KMALLOC(mallocsize, GFP_UNIONFS);
+	spd->usi_bnum_table = kmalloc(mallocsize, GFP_KERNEL);
 	if (IS_ERR(spd->usi_bnum_table)) {
 		err = -ENOMEM;
 		goto out_error;
@@ -283,17 +281,17 @@ int init_imap_data(struct super_block *s
       out_error:
 
 	if (spd->usi_reversemaps) {
-		KFREE(spd->usi_reversemaps);
+		kfree(spd->usi_reversemaps);
 		spd->usi_reversemaps = NULL;
 	}
 
 	if (spd->usi_map_table) {
-		KFREE(spd->usi_map_table);
+		kfree(spd->usi_map_table);
 		spd->usi_map_table = NULL;
 	}
 
 	if (spd->usi_bnum_table) {
-		KFREE(spd->usi_bnum_table);
+		kfree(spd->usi_bnum_table);
 		spd->usi_bnum_table = NULL;
 
 	}
@@ -323,17 +321,17 @@ void cleanup_imap_data(struct super_bloc
 		count--;
 	}
 	if (spd->usi_reversemaps) {
-		KFREE(spd->usi_reversemaps);
+		kfree(spd->usi_reversemaps);
 		spd->usi_reversemaps = NULL;
 	}
 
 	if (spd->usi_map_table) {
-		KFREE(spd->usi_map_table);
+		kfree(spd->usi_map_table);
 		spd->usi_map_table = NULL;
 	}
 
 	if (spd->usi_bnum_table) {
-		KFREE(spd->usi_bnum_table);
+		kfree(spd->usi_bnum_table);
 		spd->usi_bnum_table = NULL;
 	}
 	if (spd->usi_forwardmap) {
Index: unionfs-20060109-2055/rdstate.c
===================================================================
--- unionfs-20060109-2055.orig/rdstate.c
+++ unionfs-20060109-2055/rdstate.c
@@ -150,7 +150,7 @@ struct unionfs_dir_state *alloc_rdstate(
 	    (mallocsize -
 	     sizeof(struct unionfs_dir_state)) / sizeof(struct list_head);
 
-	rdstate = KMALLOC(mallocsize, GFP_UNIONFS);
+	rdstate = kmalloc(mallocsize, GFP_KERNEL);
 	if (!rdstate)
 		return NULL;
 
@@ -177,7 +177,7 @@ struct unionfs_dir_state *alloc_rdstate(
 static void free_filldir_node(struct filldir_node *node)
 {
 	if (node->namelen >= DNAME_INLINE_LEN_MIN)
-		KFREE(node->name);
+		kfree(node->name);
 	kmem_cache_free(unionfs_filldir_cachep, node);
 }
 
@@ -198,7 +198,7 @@ void free_rdstate(struct unionfs_dir_sta
 		}
 	}
 
-	KFREE(state);
+	kfree(state);
 }
 
 struct filldir_node *find_filldir_node(struct unionfs_dir_state *rdstate,
@@ -295,7 +295,7 @@ int add_filldir_node(struct unionfs_dir_
 	if (namelen < DNAME_INLINE_LEN_MIN) {
 		new->name = new->iname;
 	} else {
-		new->name = (char *)KMALLOC(namelen + 1, GFP_UNIONFS);
+		new->name = kmalloc(namelen + 1, GFP_KERNEL);
 		if (!new->name) {
 			kmem_cache_free(unionfs_filldir_cachep, new);
 			new = NULL;
Index: unionfs-20060109-2055/rename.c
===================================================================
--- unionfs-20060109-2055.orig/rename.c
+++ unionfs-20060109-2055/rename.c
@@ -128,7 +128,7 @@ static int do_rename(struct inode *old_d
 			set_dbend(new_dentry, bindex);
 	}
 
-	KFREE(wh_name);
+	kfree(wh_name);
 
 	fist_print_dentry("OUT: do_rename, old_dentry", old_dentry);
 	fist_print_dentry("OUT: do_rename, new_dentry", new_dentry);
@@ -605,7 +605,7 @@ static int unionfs_rename_all(struct ino
 	print_entry_location();
 
 	parent_dentry = old_dentry->d_parent;
-	name = KMALLOC(old_dentry->d_name.len + 1, GFP_UNIONFS);
+	name = kmalloc(old_dentry->d_name.len + 1, GFP_KERNEL);
 	if (!name) {
 		err = -ENOMEM;
 		goto out;
@@ -710,7 +710,7 @@ static int unionfs_rename_all(struct ino
 		err = eio;
 
       out:
-	KFREE(name);
+	kfree(name);
 	print_exit_status(err);
 	return err;
 }
@@ -746,7 +746,7 @@ static struct dentry *lookup_whiteout(st
 	}
 	unlock_dentry(parent);
 	DPUT(parent);
-	KFREE(whname);
+	kfree(whname);
 	return wh_dentry;
 }
 
Index: unionfs-20060109-2055/super.c
===================================================================
--- unionfs-20060109-2055.orig/super.c
+++ unionfs-20060109-2055/super.c
@@ -53,13 +53,12 @@ static void unionfs_read_inode(struct in
 		int size =
 		    (sbmax(inode->i_sb) -
 		     UNIONFS_INLINE_OBJECTS) * sizeof(struct inode *);
-		itohi_ptr(inode) = KMALLOC(size, GFP_UNIONFS);
+		itohi_ptr(inode) = kzalloc(size, GFP_KERNEL);
 		if (!itohi_ptr(inode)) {
 			printk(KERN_ERR
 			       "No kernel memory when allocating lower-pointer array!\n");
 			BUG();
 		}
-		memset(itohi_ptr(inode), 0, size);
 	}
 	memset(itohi_inline(inode), 0,
 	       UNIONFS_INLINE_OBJECTS * sizeof(struct inode *));
@@ -133,12 +132,12 @@ static void unionfs_put_super(struct sup
 		for (bindex = bstart; bindex <= bend; bindex++)
 			BUG_ON(branch_count(sb, bindex) != 0);
 
-		KFREE(stohs_ptr(sb));
-		KFREE(stohiddenmnt_ptr(sb));
-		KFREE(spd->usi_sbcount_p);
-		KFREE(spd->usi_branchperms_p);
-		KFREE(spd->usi_putmaps);
-		KFREE(spd);
+		kfree(stohs_ptr(sb));
+		kfree(stohiddenmnt_ptr(sb));
+		kfree(spd->usi_sbcount_p);
+		kfree(spd->usi_branchperms_p);
+		kfree(spd->usi_putmaps);
+		kfree(spd);
 		stopd_lhs(sb) = NULL;
 	}
 	fist_dprint(6, "unionfs: released super\n");
@@ -297,7 +296,7 @@ static void unionfs_clear_inode(struct i
 	// XXX: why this assertion fails?
 	// because it doesn't like us
 	// BUG_ON((inode->i_state & I_DIRTY) != 0);
-	KFREE(itohi_ptr(inode));
+	kfree(itohi_ptr(inode));
 	itohi_ptr(inode) = NULL;
 
 	print_exit_location();
@@ -437,7 +436,7 @@ static int unionfs_show_options(struct s
 
 	lock_dentry(sb->s_root);
 
-	tmp = __get_free_page(GFP_UNIONFS);
+	tmp = __get_free_page(GFP_KERNEL);
 	if (!tmp) {
 		ret = -ENOMEM;
 		goto out;
Index: unionfs-20060109-2055/unionfs.h
===================================================================
--- unionfs-20060109-2055.orig/unionfs.h
+++ unionfs-20060109-2055/unionfs.h
@@ -48,9 +48,6 @@
 /* Mount time flags */
 #define MOUNT_FLAG(sb)     (stopd(sb)->usi_mount_flag)
 
-/* What type of flags to use for kmalloc, etc. */
-#define GFP_UNIONFS GFP_KERNEL
-
 /*UUID typedef needed later*/
 typedef uint8_t uuid_t[16];
 
@@ -620,7 +617,7 @@ static inline char *alloc_whname(const c
 {
 	char *buf;
 
-	buf = KMALLOC(len + WHLEN + 1, GFP_UNIONFS);
+	buf = kmalloc(len + WHLEN + 1, GFP_KERNEL);
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
Index: unionfs-20060109-2055/fist.h
===================================================================
--- unionfs-20060109-2055.orig/fist.h
+++ unionfs-20060109-2055/fist.h
@@ -92,9 +92,6 @@
  */
 
 #ifdef FIST_MALLOC_DEBUG
-extern void *unionfs_kmalloc(size_t len, int flag, int line, const char *file);
-extern void unionfs_kfree(void *ptr, int line, const char *file);
-
 extern struct dentry *unionfs_dget_parent(struct dentry *child, int line,
 					  const char *file);
 extern struct dentry *unionfs_dget(struct dentry *ptr, int line,
@@ -110,8 +107,6 @@ struct file *unionfs_dentry_open(struct 
 void record_set(struct dentry *upper, int index, struct dentry *ptr,
 		struct dentry *old, int line, const char *file);
 
-#define KMALLOC(size,flag) unionfs_kmalloc((size),(flag),__LINE__,__FILE__)
-#define KFREE(ptr) unionfs_kfree((ptr),__LINE__,__FILE__)
 #define DGET(d) unionfs_dget((d),__LINE__,__FILE__)
 #define DPUT(d) unionfs_dput((d),__LINE__,__FILE__)
 #define LOOKUP_ONE_LEN(name,parent,len) unionfs_lookup_one_len((name),(parent),(len),__LINE__,__FILE__)
@@ -124,8 +119,6 @@ void record_set(struct dentry *upper, in
 # define DENTRY_OPEN(d,m,f) unionfs_dentry_open((d),(m),(f),__LINE__,__FILE__)
 # define GET_PARENT(dentry) unionfs_dget_parent((dentry),__LINE__,__FILE__)
 #else				/* not FIST_MALLOC_DEBUG */
-# define KMALLOC(a,b)		kmalloc((a),(b))
-# define KFREE(a)		kfree((a))
 # define DPUT(a)		dput((a))
 # define DGET(a)		dget((a))
 # define LOOKUP_ONE_LEN(a,b,c)	lookup_one_len((a),(b),(c))

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-10 12:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-10 12:40 [PATCH] unionfs: kmalloc cleanups Pekka J Enberg
  -- strict thread matches above, loose matches on Subject: below --
2006-01-10 12:36 Pekka J Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).