spi: spi-mem: fix coverity report CID 537478
authorMikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Sat, 1 Nov 2025 06:24:24 +0000 (09:24 +0300)
committerMichael Trimarchi <michael@amarulasolutions.com>
Tue, 18 Nov 2025 19:07:41 +0000 (20:07 +0100)
commitc3c758c20d3560639bfad6ac367f1a13278d67ca
tree5d38793f4b6c403d19caf416a5c0eb7b08791484
parentc675162bcb32360a45fee7a9ba9588241916549b
spi: spi-mem: fix coverity report CID 537478

Coverity finds a potential integer overflow in the following code:

  ncycles += ((op->data.nbytes * 8) / op->data.buswidth) / (op->data.dtr ? 2 : 1);

A quick analysis shows that the only caller of the suspicious code is the
spinand_select_op_variant() function from the drivers/mtd/nand/spi/core.c
file.

According to the code the value of op->data.nbytes is equal to

  nanddev_per_page_oobsize(nand) + nanddev_page_size(nand)

Therefore it's maximum value a bit larger than 4Kb (I never seen flashes
with page size large than 4Kb). So op->data.nbytes always fits within
13 bits. As result an overflow will never happen.

Anyway it's better fix an issue to eliminate the error message.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
drivers/spi/spi-mem.c