Skip to content

Commit d958463

Browse files
Mikhail Arkhipovmiquelraynal
authored andcommitted
mtd: nand: ecc-mxic: Fix use of uninitialized variable ret
If ctx->steps is zero, the loop processing ECC steps is skipped, and the variable ret remains uninitialized. It is later checked and returned, which leads to undefined behavior and may cause unpredictable results in user space or kernel crashes. This scenario can be triggered in edge cases such as misconfigured geometry, ECC engine misuse, or if ctx->steps is not validated after initialization. Initialize ret to zero before the loop to ensure correct and safe behavior regardless of the ctx->steps value. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 48e6633 ("mtd: nand: mxic-ecc: Add Macronix external ECC engine support") Signed-off-by: Mikhail Arkhipov <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 25e08bf commit d958463

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/mtd/nand/ecc-mxic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ static int mxic_ecc_finish_io_req_external(struct nand_device *nand,
614614
{
615615
struct mxic_ecc_engine *mxic = nand_to_mxic(nand);
616616
struct mxic_ecc_ctx *ctx = nand_to_ecc_ctx(nand);
617-
int nents, step, ret;
617+
int nents, step, ret = 0;
618618

619619
if (req->mode == MTD_OPS_RAW)
620620
return 0;

0 commit comments

Comments
 (0)