Felix Held has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/60121 )
Change subject: drivers/spi/spi-generic: fix edge case in spi_crop_chunk ......................................................................
drivers/spi/spi-generic: fix edge case in spi_crop_chunk
In the case of deduct_cmd_len being set and the adjusted cmd_len >= ctrlr_max, ctrlr_max wasn't being adjusted and still had the value of ctrlr->max_xfer_size. Handle this edge case (which we should never run into) by setting ctrlr_max to 0 and printing a warning to the console.
Signed-off-by: Felix Held felix-coreboot@felixheld.de Change-Id: I9941b2947bb0a44dfae8ee69f509795dfb0cb241 --- M src/drivers/spi/spi-generic.c 1 file changed, 8 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/21/60121/1
diff --git a/src/drivers/spi/spi-generic.c b/src/drivers/spi/spi-generic.c index 116daf9..9796663 100644 --- a/src/drivers/spi/spi-generic.c +++ b/src/drivers/spi/spi-generic.c @@ -98,8 +98,14 @@ if (deduct_opcode_len) cmd_len--;
- if (deduct_cmd_len && (ctrlr_max > cmd_len)) - ctrlr_max -= cmd_len; + if (deduct_cmd_len) { + if (ctrlr_max >= cmd_len) { + ctrlr_max -= cmd_len; + } else { + ctrlr_max = 0; + printk(BIOS_WARNING, "%s: Command longer than buffer\n", __func__); + } + }
return MIN(ctrlr_max, buf_len); }