From: Detlev Zundel Date: Fri, 29 Apr 2011 15:11:12 +0200 Subject: [U-Boot] [PATCH 3/7] JFFS2: Calculate buf_len before we read data from flash In-Reply-To: <001e01cc0230$e0268b90$6401a8c0@LENOVOE5CA6843> (Baidu Liu's message of "Sun, 24 Apr 2011 11:36:46 +0800") References: <001e01cc0230$e0268b90$6401a8c0@LENOVOE5CA6843> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Baidu, > 1/ We should calculate the buf_len before we call > get_fl_mem(). If I read your change correctly, then do you mean the following? When we know what we want to read, we can calculate buf_len to be the maximum size of the data to be read. Without this, we usually read EMPTY_SCAN_SIZE which is too much. This is only an optimization change. Maybe this text will help people understand better what the change tries to do. > diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c > index 8eb77b1..be6ac78 100644 > --- a/fs/jffs2/jffs2_1pass.c > +++ b/fs/jffs2/jffs2_1pass.c > @@ -1643,6 +1643,8 @@ jffs2_1pass_build_lists(struct part_info * part) > case JFFS2_NODETYPE_INODE: > if (buf_ofs + buf_len < ofs + sizeof(struct > jffs2_raw_inode)) { > + buf_len = min_t(uint32_t, buf_size, sector_ofs > + + part->sector_size - ofs); I am somewhat uncomfortable that "buf_len" is used in the if condition before it is recalculated inside. Are you sure that this cannot lead to problems, i.e. can buf_len become larger than it was when entering the condition? > get_fl_mem((u32)part->offset + ofs, > buf_len, buf); > buf_ofs = ofs; > @@ -1659,11 +1661,11 @@ jffs2_1pass_build_lists(struct part_info * part) > } > break; > case JFFS2_NODETYPE_DIRENT: > - if (buf_ofs + buf_len < ofs + sizeof(struct > - jffs2_raw_dirent) + > - ((struct > - jffs2_raw_dirent *) > - node)->nsize) { > + if (buf_ofs + buf_len < ofs + > + sizeof(struct jffs2_raw_dirent) + > + ((struct jffs2_raw_dirent *)node)->nsize) { > + buf_len = min_t(uint32_t, buf_size, sector_ofs > + + part->sector_size - ofs); The same question for this case. Cheers Detlev -- Those who do not understand Unix are condemned to reinvent it, poorly. - Henry Spencer, University of Toronto Unix hack -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de