From: Detlev Zundel Date: Mon, 02 May 2011 14:25:26 +0200 Subject: [U-Boot] [PATCH 3/7] JFFS2: Calculate buf_len before we read data from flash In-Reply-To: (Baidu Liu's message of "Sat, 30 Apr 2011 08:48:23 +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, > Hi, Detlev : > > 2011/4/30 Detlev Zundel : >> Hi Baidu, >> >> [...] >> >>>>> 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? >>> >>> It works well in my boards. >> >> Aha. ?I am all happy for you that this works, but we really need to be >> as sure as we can be that the code does the right thing. ?"It works for >> me" is not enough. > > Please read every line code in the uboot jffs2 carefully. Know more > about JFFS2. I was asking you a question about a potential problem that I see with your changes. Can you answer the question or not? If you cannot answer it, then you are changing things that you do not understand. Personally I don't trust bug-fixes that are not understood completely. Cheers Detlev -- Mit einem Leben wie dem meinen, Doktor - wer braucht da noch Traeume? - Alex Portnoy -- 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