summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Held <felix-coreboot@felixheld.de>2021-12-10 18:38:16 +0100
committerFelix Held <felix-coreboot@felixheld.de>2021-12-15 22:39:07 +0000
commite3ae755575e0646f9dd47400a1dfc6018e16e9a8 (patch)
treeb02655b6722c8361e771a3989f812ec26742e222
parent856d6bc6d3d7c19be0e17c6fc6ad089868bf4b54 (diff)
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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/60121 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Raul Rangel <rrangel@chromium.org>
-rw-r--r--src/drivers/spi/spi-generic.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/drivers/spi/spi-generic.c b/src/drivers/spi/spi-generic.c
index 116daf9088..9796663da2 100644
--- a/src/drivers/spi/spi-generic.c
+++ b/src/drivers/spi/spi-generic.c
@@ -98,8 +98,14 @@ unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
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);
}