JFFS2: Calculate buf_len before we read data from flash
PATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
1/ We should calculate the buf_len before we call get_fl_mem().
--- fs/jffs2/jffs2_1pass.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
fs/jffs2/jffs2_1pass.c +7 -5
@@ -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);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);get_fl_mem ((u32 )part->offset + ofs, buf_len, buf); buf_ofs = ofs;
Signature · 1 line
1.7.3.1.msysgit.0
PATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
Hi Baidu,
Quoted 2 lines
1/ We should calculate the
buf_lenbefore we callget_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.
fs/jffs2/jffs2_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 1647
Quoted 10 lines
fs/jffs2/jffs2_1pass.c +2
-0@@ -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?
Quoted 7 lines
fs/jffs2/jffs2_1pass.c +0
-0get_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 :
fs/jffs2/jffs2_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 1668
Quoted 10 lines
fs/jffs2/jffs2_1pass.c +5
-5-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
Signature · 7 lines
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
PATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
Hi,Detlev
2011/4/29 Detlev Zundel <[email protected]>:
Quoted 10 lines
Hi Baidu,
Quoted 2 lines
?1/ We should calculate the
buf_lenbefore 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_lento be the ?maximum size of the data to be read. ?Without this, we usually read ?EMPTY_SCAN_SIZE which is too much.
Yes,you are right.
Quoted 4 lines
?This is only an optimization change.
Maybe this text will help people understand better what the change tries to do.
The patch comments may be enough to explain what my changes is. We can see the code:buf_len = min_t() everywhere the get_fl_mem() called.
Quoted 7 lines
Quoted 7 lines
fs/jffs2/jffs2_1pass.c +0
-0@@ -1643,6 +1643,8 @@ jffs2_1pass_build_lists(struct part_info * part)? ? ? ? ? ? ? ? ? ? ? case
JFFS2_NODETYPE_INODE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (buf_ofs+buf_len< ofs + sizeof(struct
Quoted 8 lines
Quoted 3 lines
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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. canbuf_lenbecome larger than it was when entering the condition?
It works well in my boards.
PATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
Hi Baidu,
[...]
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
fs/jffs2/jffs2_1pass.c +0
-0@@ -1643,6 +1643,8 @@ jffs2_1pass_build_lists(struct part_info * part)? ? ? ? ? ? ? ? ? ? ? case
JFFS2_NODETYPE_INODE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (buf_ofs+buf_len< ofs + sizeof(structQuoted 8 lines
Quoted 3 lines
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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. canbuf_lenbecome larger than it was when entering the condition?
Quoted 1 line
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.
Cheers
Detlev
Signature · 7 lines
Als ich entf?hrt wurde, begannen meine Eltern aktiv zu werden.
Sie vermieteten mein Zimmer.
-- Woody Allen
--
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.dePATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
Hi, Detlev :
2011/4/30 Detlev Zundel <[email protected]>:
Quoted 20 lines
Hi Baidu,
[...]
Quoted 16 lines
Quoted 15 lines
Quoted 10 lines
fs/jffs2/jffs2_1pass.c +0
-0@@ -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. canbuf_lenbecome larger than it was when entering the condition?
Quoted 5 lines
Quoted 1 line
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.
PATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
Hi Baidu,
Quoted 23 lines
Hi, Detlev :
2011/4/30 Detlev Zundel <[email protected]>:
Quoted 20 lines
Hi Baidu,
[...]
Quoted 16 lines
Quoted 15 lines
Quoted 10 lines
fs/jffs2/jffs2_1pass.c +0
-0@@ -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. canbuf_lenbecome larger than it was when entering the condition?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
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
Signature · 6 lines
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.dePATCH 3/7 JFFS2: Calculate buf_len before we read data from flash
In reply to Detlev ZundelHi,Detlev
2011/4/29 Detlev Zundel <[email protected]>:
Quoted 10 lines
Hi Baidu,
Quoted 2 lines
?1/ We should calculate the
buf_lenbefore 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_lento be the ?maximum size of the data to be read. ?Without this, we usually read ?EMPTY_SCAN_SIZE which is too much.
Yes,you are right.
Quoted 4 lines
?This is only an optimization change.
Maybe this text will help people understand better what the change tries to do.
The patch comments may be enough to explain what my changes is. We can see the code:buf_len = min_t() everywhere the get_fl_mem() called.
Quoted 7 lines
Quoted 7 lines
fs/jffs2/jffs2_1pass.c +0
-0@@ -1643,6 +1643,8 @@ jffs2_1pass_build_lists(struct part_info * part)? ? ? ? ? ? ? ? ? ? ? case
JFFS2_NODETYPE_INODE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (buf_ofs+buf_len< ofs + sizeof(struct
Quoted 8 lines
Quoted 3 lines
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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. canbuf_lenbecome larger than it was when entering the condition?
It works well in my boards.