Patchwork [U-Boot,2/7] JFFS2: Change allocated buffer size

login
register
mail settings
Submitter Baidu Boy
Date April 24, 2011, 3:36 a.m.
Message ID <001d01cc0230$cb28b470$6401a8c0@LENOVOE5CA6843>
Download mbox | patch
Permalink /patch/92631/
State New
Delegated to: Detlev Zundel
Headers show

Comments

Baidu Boy - April 24, 2011, 3:36 a.m.
1/ The buffer size previous code allocated is the largest file
 length, which may too bigger. And we only use little of the
 buffer. So we change the buffer size to max size of node:
 sizeof(union jffs2_node_union).

Signed-off-by: Baidu Liu <liucai.lfn@gmail.com>
---
 fs/jffs2/jffs2_1pass.c |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

Patch

diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c
index a34756e..8eb77b1 100644
--- a/fs/jffs2/jffs2_1pass.c
+++ b/fs/jffs2/jffs2_1pass.c
@@ -676,12 +676,18 @@  jffs_init_1pass_list(struct part_info *part)
 
 	if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
 		pL = (struct b_lists *)part->jffs2_priv;
-
 		memset(pL, 0, sizeof(*pL));
+		
+		pL->readbuf = malloc(sizeof(union jffs2_node_union));
+		if(!pL->readbuf) {
+			printf("jffs_init_1pass_list: malloc failed\n");
+			return 0;
+		}
 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
 		pL->dir.listCompare = compare_dirents;
 		pL->frag.listCompare = compare_inodes;
 #endif
+		return 1;
 	}
 	return 0;
 }
@@ -1455,7 +1461,6 @@  jffs2_1pass_build_lists(struct part_info * part)
 	u32 counter4 = 0;
 	u32 counterF = 0;
 	u32 counterN = 0;
-	u32 max_totlen = 0;
 	u32 buf_size = DEFAULT_EMPTY_SCAN_SIZE;
 	char *buf;
 
@@ -1652,8 +1657,6 @@  jffs2_1pass_build_lists(struct part_info * part)
 					jffs2_free_cache(part);
 					return 0;
 				}
-				if (max_totlen < node->totlen)
-					max_totlen = node->totlen;
 				break;
 			case JFFS2_NODETYPE_DIRENT:
 				if (buf_ofs + buf_len < ofs + sizeof(struct
@@ -1682,8 +1685,6 @@  jffs2_1pass_build_lists(struct part_info * part)
 					jffs2_free_cache(part);
 					return 0;
 				}
-				if (max_totlen < node->totlen)
-					max_totlen = node->totlen;
 				counterN++;
 				break;
 			case JFFS2_NODETYPE_CLEANMARKER:
@@ -1715,12 +1716,6 @@  jffs2_1pass_build_lists(struct part_info * part)
 	free(buf);
 	putstr("\b\b done.\r\n");		/* close off the dots */
 
-	/* We don't care if malloc failed - then each read operation will
-	 * allocate its own buffer as necessary (NAND) or will read directly
-	 * from flash (NOR).
-	 */
-	pL->readbuf = malloc(max_totlen);
-
 	/* turn the lcd back on. */
 	/* splash(); */