]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mtd: nand: ecc-mxic: Fix use of uninitialized variable ret
authorMikhail Arkhipov <m.arhipov@rosa.ru>
Tue, 8 Apr 2025 21:39:06 +0000 (00:39 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:07:15 +0000 (11:07 +0100)
commit4d9d6e4be09472aa72953caca3dbefdc27846170
treee27e91416ba915378bece25de7db4c7cb5df3635
parent21528806560510458378ea52c37e35b0773afaea
mtd: nand: ecc-mxic: Fix use of uninitialized variable ret

[ Upstream commit d95846350aac72303036a70c4cdc69ae314aa26d ]

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: 48e6633a9fa2 ("mtd: nand: mxic-ecc: Add Macronix external ECC engine support")
Signed-off-by: Mikhail Arkhipov <m.arhipov@rosa.ru>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mtd/nand/ecc-mxic.c