[PATCH 2/4] squashfs: kmalloc (less stack, less casts)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jörn

-- 
Rules of Optimization:
Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet.
-- M.A. Jackson 


Signed-off-by: Jörn Engel <[email protected]>
---

 fs/squashfs/inode.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

--- linux-2.6.12-rc2cow/fs/squashfs/inode.c~squashfs_cu2	2005-04-20 08:11:10.000000000 +0200
+++ linux-2.6.12-rc2cow/fs/squashfs/inode.c	2005-04-20 16:34:43.619956672 +0200
@@ -1453,11 +1453,14 @@ static int squashfs_readdir(struct file 
 		next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
 		dir_count;
 	squashfs_dir_header dirh;
-	char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
-	squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
+	squashfs_dir_entry *dire;
 
 	TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
 
+	dire = kmalloc(sizeof(*dire) + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
+	if (!dire)
+		return -ENOMEM;
+
 	length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
 				SQUASHFS_I(i)->u.s2.directory_index_start,
 				SQUASHFS_I(i)->u.s2.directory_index_offset,
@@ -1533,6 +1536,7 @@ static int squashfs_readdir(struct file 
 					squashfs_filetype_table[dire->type])
 					< 0) {
 				TRACE("Filldir returned less than 0\n");
+				kfree(dire);
 				return dirs_read;
 			}
 			file->f_pos = length;
@@ -1540,11 +1544,13 @@ static int squashfs_readdir(struct file 
 		}
 	}
 
+	kfree(dire);
 	return dirs_read;
 
 failed_read:
 	ERROR("Unable to read directory block [%x:%x]\n", next_block,
 		next_offset);
+	kfree(dire);
 	return 0;
 }
 
@@ -1562,12 +1568,15 @@ static struct dentry *squashfs_lookup(st
 				next_offset = SQUASHFS_I(i)->offset, length = 0,
 				dir_count;
 	squashfs_dir_header dirh;
-	char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
-	squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
+	squashfs_dir_entry *dire;
 	int sorted = sBlk->s_major == 2 && sBlk->s_minor >= 1;
 
 	TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
 
+	dire = kmalloc(sizeof(*dire) + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
+	if (!dire)
+		return ERR_PTR(-ENOMEM);
+
 	length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
 				SQUASHFS_I(i)->u.s2.directory_index_start,
 				SQUASHFS_I(i)->u.s2.directory_index_offset,
@@ -1645,7 +1654,8 @@ static struct dentry *squashfs_lookup(st
 
 exit_loop:
 	d_add(dentry, inode);
-	return ERR_PTR(0);
+	kfree(dire);
+	return NULL;
 
 failed_read:
 	ERROR("Unable to read directory block [%x:%x]\n", next_block,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux