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>
This commit is contained in:
Felix Held 2021-12-10 18:38:16 +01:00
parent 856d6bc6d3
commit e3ae755575
1 changed files with 8 additions and 2 deletions

View File

@ -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);
}