Skip to contentSkip to conversation

Followup fixes on the mtdparts spread patchset

PATCH New Scott Wood 3 participants 6 messages Sep 9, 2010 – Sep 10, 2010 Memory technology devices (MTD)

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

Consolidate some code in mtd_get_len_incl_bad(), and fix a condition where a valid partition could be reported as truncated if it has a good block at the end of the device (unlikely, since the BBT is usually there).

Fix mid-block declarations in net_part_size().

---
 common/cmd_mtdparts.c |    5 +++--
 drivers/mtd/mtdcore.c |   15 +++++----------
 2 files changed, 8 insertions(+), 12 deletions(-)
common/cmd_mtdparts.c +3 -2
index 17865b7..5481c88 100644
@@ -1228,15 +1228,16 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
  */
 static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
 {
+	uint64_t i, net_size = 0;
+
 	if (!mtd->block_isbad)
 		return part->size;
 
-	uint64_t i, net_size = 0;
-
 	for (i = 0; i < part->size; i += mtd->erasesize) {
 		if (!mtd->block_isbad(mtd, part->offset + i))
 			net_size += mtd->erasesize;
 	}
+
 	return net_size;
 }
 #endif
drivers/mtd/mtdcore.c +5 -10
index 78f2a08..a195dda 100644
@@ -162,11 +162,6 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 	*truncated = 0;
 	*len_incl_bad = 0;
 
-	if (offset >= mtd->size) {
-		*truncated = 1;
-		return;
-	}
-
 	if (!mtd->block_isbad) {
 		*len_incl_bad = length;
 		return;
@@ -176,6 +171,11 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 	uint64_t block_len;
 
 	while (len_excl_bad < length) {
+		if (offset >= mtd->size) {
+			*truncated = 1;
+			return;
+		}
+
 		block_len = mtd->erasesize - (offset & (mtd->erasesize - 1));
 
 		if (!mtd->block_isbad(mtd, offset & ~(mtd->erasesize - 1)))
@@ -183,11 +183,6 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 
 		*len_incl_bad += block_len;
 		offset       += block_len;
-
-		if (offset >= mtd->size) {
-			*truncated = 1;
-			break;
-		}
 	}
 }
 #endif /* defined(CONFIG_CMD_MTDPARTS_SPREAD) */
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

Hi Scott,

Thank you for picking up the 'mtdparts spread' patch series into u-boot-nand-flash next by applying the v6 series and doing this fixup on-top. It is greatly appreciated.

Quoted 26 lines · Scott Wood

Consolidate some code in mtd_get_len_incl_bad(), and fix a condition where a valid partition could be reported as truncated if it has a good block at the end of the device (unlikely, since the BBT is usually there).

Fix mid-block declarations in net_part_size().

---
?common/cmd_mtdparts.c | ? ?5 +++-- ?drivers/mtd/mtdcore.c | ? 15 +++++---------- ?2 files changed, 8 insertions(+), 12 deletions(-)

common/cmd_mtdparts.c +0 -0
index 17865b7..5481c88 100644
@@ -1228,15 +1228,16 @@ static int generate_mtdparts_save(char *buf, u32 buflen)

?*/
?static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part) ?{
+ ? ? ? uint64_t i, net_size = 0;
+
? ? ? ?if (!mtd->block_isbad)
? ? ? ? ? ? ? ?return part->size;

Quoted 10 lines

- ? ? ? uint64_t i, net_size = 0;
-
? ? ? ?for (i = 0; i < part->size; i += mtd->erasesize) { ? ? ? ? ? ? ? ?if (!mtd->block_isbad(mtd, part->offset + i)) ? ? ? ? ? ? ? ? ? ? ? ?net_size += mtd->erasesize; ? ? ? ?}
+
? ? ? ?return net_size;
?}
?#endif

It's fine by me but I'm curious: why move the declaration of the stack variables i and net_size to before the check of the block_isbad function pointer? Before this change, I think there would be no allocation of these variables on the stack if the block_isbad function pointer is null.

I double-checked and there were no warnings from 'make' 'MAKEALL' (I'm using (Sourcery G++ Lite 2009q1-203) 4.3.3 here) or checkpatch.pl (from 2.6.36-rc3) before this change. Just curious -- I am interested in learning so I can produce and submit patchsets that meet the standards of this list in the future.

Quoted 39 lines
drivers/mtd/mtdcore.c +5 -10
index 78f2a08..a195dda 100644
@@ -162,11 +162,6 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 ? ? ? ?*truncated = 0;
 ? ? ? ?*len_incl_bad = 0;
 
- ? ? ? if (offset >= mtd->size) {
- ? ? ? ? ? ? ? *truncated = 1;
- ? ? ? ? ? ? ? return;
- ? ? ? }
-
 ? ? ? ?if (!mtd->block_isbad) {
 ? ? ? ? ? ? ? ?*len_incl_bad = length;
 ? ? ? ? ? ? ? ?return;
@@ -176,6 +171,11 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 ? ? ? ?uint64_t block_len;
 
 ? ? ? ?while (len_excl_bad < length) {
+ ? ? ? ? ? ? ? if (offset >= mtd->size) {
+ ? ? ? ? ? ? ? ? ? ? ? *truncated = 1;
+ ? ? ? ? ? ? ? ? ? ? ? return;
+ ? ? ? ? ? ? ? }
+
 ? ? ? ? ? ? ? ?block_len = mtd->erasesize - (offset & (mtd->erasesize - 1));
 
 ? ? ? ? ? ? ? ?if (!mtd->block_isbad(mtd, offset & ~(mtd->erasesize - 1)))
@@ -183,11 +183,6 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
 
 ? ? ? ? ? ? ? ?*len_incl_bad += block_len;
 ? ? ? ? ? ? ? ?offset ? ? ? += block_len;
-
- ? ? ? ? ? ? ? if (offset >= mtd->size) {
- ? ? ? ? ? ? ? ? ? ? ? *truncated = 1;
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? }
 ? ? ? ?}
 ?}
Quoted 1 line

?#endif /* defined(CONFIG_CMD_MTDPARTS_SPREAD) */

Awesome! Thank you for fixing that edge case.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca

author
#2 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

Quoted 3 lines · On Fri, 10 Sep 2010 10:35:04 -0400 Ben Gardiner <[email protected]>…

It's fine by me but I'm curious: why move the declaration of the stack variables i and net_size to before the check of the block_isbad function pointer?

U-Boot coding style prohibits mid-block declarations.

Quoted 3 lines

Before this change, I think there would be no
allocation of these variables on the stack if the block_isbad function pointer is null.

The change should not make any difference in the generated code. The compiler is not going to delay its creation of the stack frame just because of where the variables are declared.

-Scott

#3 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

Quoted 9 lines · Scott Wood
Quoted 3 lines · On Fri, 10 Sep 2010 10:35:04 -0400 Ben Gardiner <[email protected]>…

It's fine by me but I'm curious: why move the declaration of the stack variables i and net_size to before the check of the block_isbad function pointer?

U-Boot coding style prohibits mid-block declarations.

Quoted 7 lines
Quoted 3 lines

Before this change, I think there would be no
allocation of these variables on the stack if the block_isbad function pointer is null.

The change should not make any difference in the generated code. ?The compiler is not going to delay its creation of the stack frame just because of where the variables are declared.

Ok. I understand now; thank you for clearing that up, Scott.

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca

#4 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

In reply to Ben Gardiner

Dear Ben Gardiner,

Quoted 6 lines · In message <[email protected]> you…

It's fine by me but I'm curious: why move the declaration of the stack variables i and net_size to before the check of the block_isbad function pointer? Before this change, I think there would be no allocation of these variables on the stack if the block_isbad function pointer is null.

The optimizer is more clever than you assume.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Life is a game. Money is how we keep score.              - Ted Turner
#5 lore raw

PATCH 1/1 Followup fixes on the mtdparts spread patchset

Hi Wolfgang,

Quoted 11 lines · Wolfgang Denk

Dear Ben Gardiner,

Quoted 6 lines · In message <[email protected]> you…

It's fine by me but I'm curious: why move the declaration of the stack variables i and net_size to before the check of the block_isbad function pointer? Before this change, I think there would be no allocation of these variables on the stack if the block_isbad function pointer is null.

The optimizer is more clever than you assume.

I see -- I'll start giving it the benefit of the doubt then :)

Best Regards,
Ben Gardiner

---
Nanometrics Inc.
http://www.nanometrics.ca