summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Huber <nico.huber@secunet.com>2018-12-05 13:26:20 +0100
committerNico Huber <nico.h@gmx.de>2018-12-22 17:08:22 +0000
commit993e162d4f0ae2c0719999b8fb7e6e3418f173d3 (patch)
tree3eba1c0de5a9bc27de06f94f1215d1cf8f7d0687
parent5639af6408bb26bcddc5de9ba12fed182a74f02e (diff)
downloadflashrom-993e162d4f0ae2c0719999b8fb7e6e3418f173d3.tar.gz
flashrom-993e162d4f0ae2c0719999b8fb7e6e3418f173d3.tar.bz2
flashrom-993e162d4f0ae2c0719999b8fb7e6e3418f173d3.zip
dediprog: Fix small, unaligned reads
This never was a use case until now but the `--fmap` code makes it obvious: Unaligned reads that were smaller than the `chunksize` here, were extended without considering the length of the buffer read into. With that fixed we run into the next problem: dediprog_spi_bulk_read() shouldn't report an error when an empty read is unaligned. Change-Id: Ie12b62499ebfdb467d5126c00d327c76077ddead Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/c/30051 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com> Reviewed-on: https://review.coreboot.org/c/30380 Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--dediprog.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/dediprog.c b/dediprog.c
index 2f5b441fe..70660d48e 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -425,15 +425,15 @@ static int dediprog_spi_bulk_read(struct flashctx *flash, uint8_t *buf, unsigned
struct libusb_transfer *transfers[DEDIPROG_ASYNC_TRANSFERS] = { NULL, };
struct libusb_transfer *transfer;
+ if (len == 0)
+ return 0;
+
if ((start % chunksize) || (len % chunksize)) {
msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug at flashrom@flashrom.org\n",
__func__, start, len);
return 1;
}
- if (len == 0)
- return 0;
-
/* Command packet size of protocols: new 10 B, old 5 B. */
uint8_t data_packet[is_new_prot() ? 10 : 5];
unsigned int value, idx;
@@ -503,7 +503,7 @@ static int dediprog_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int
int ret;
/* chunksize must be 512, other sizes will NOT work at all. */
const unsigned int chunksize = 0x200;
- unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0;
+ unsigned int residue = start % chunksize ? min(len, chunksize - start % chunksize) : 0;
unsigned int bulklen;
dediprog_set_leds(LED_BUSY);