From patchwork Sun Apr 24 03:36:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baidu Boy X-Patchwork-Id: 92631 X-Patchwork-Delegate: dzu@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A3084B6FBD for ; Sun, 24 Apr 2011 13:36:40 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F3EB7280BC; Sun, 24 Apr 2011 05:36:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HUApdmKwsnAh; Sun, 24 Apr 2011 05:36:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2445C280A9; Sun, 24 Apr 2011 05:36:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5834F280A9 for ; Sun, 24 Apr 2011 05:36:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q7q2aYu0eD5i for ; Sun, 24 Apr 2011 05:36:33 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pz0-f44.google.com (mail-pz0-f44.google.com [209.85.210.44]) by theia.denx.de (Postfix) with ESMTPS id 051F4280A8 for ; Sun, 24 Apr 2011 05:36:31 +0200 (CEST) Received: by pzk30 with SMTP id 30so920376pzk.3 for ; Sat, 23 Apr 2011 20:36:29 -0700 (PDT) Received: by 10.68.19.134 with SMTP id f6mr4432105pbe.31.1303616189520; Sat, 23 Apr 2011 20:36:29 -0700 (PDT) Received: from LENOVOE5CA6843 ([121.229.190.251]) by mx.google.com with ESMTPS id r2sm2103260pbp.99.2011.04.23.20.36.21 (version=SSLv3 cipher=OTHER); Sat, 23 Apr 2011 20:36:27 -0700 (PDT) From: "Baidu Liu" To: , Date: Sun, 24 Apr 2011 11:36:14 +0800 Message-ID: <001d01cc0230$cb28b470$6401a8c0@LENOVOE5CA6843> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcwCMMNR+a9ez6hGSgmuVNZ/VK/+wA== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3664 Subject: [U-Boot] [PATCH 2/7] JFFS2: Change allocated buffer size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- fs/jffs2/jffs2_1pass.c | 19 +++++++------------ 1 files changed, 7 insertions(+), 12 deletions(-) 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(); */