Skip to contentSkip to conversation

mtd-utils: nanddump: write requested length only

PATCH New Gary Bisson 1 participant 1 message Dec 18, 2013 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd-utils: nanddump: write requested length only

nanddump was always writing a whole page of data into the output discarding the length actually requested. This patch allows to write only the remaining length if oob is omitted. In case oob is needed, it makes sense to copy the entire page.

---
 nanddump.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
nanddump.c +8 -2
index 4ee7ed4..300aca6 100644
@@ -445,8 +445,14 @@ int main(int argc, char * const argv[])
 						pretty_buf, PRETTY_BUF_LEN, true, canonical, ofs + i);
 				write(ofd, pretty_buf, strlen(pretty_buf));
 			}
-		} else
-			write(ofd, readbuf, bs);
+		} else {
+			/* Write requested length if oob is omitted */
+			size_t size_left = end_addr - ofs;
+			if (omitoob && (size_left < bs))
+				write(ofd, readbuf, size_left);
+			else
+				write(ofd, readbuf, bs);
+		}
 
 		if (omitoob)
 			continue;
Signature · 1 line
1.8.5.1