linux-stable/drivers/mtd
Christian Marangi cce311f8bb mtd: limit OTP NVMEM cell parse to non-NAND devices
[ Upstream commit d2d73a6dd1 ]

MTD OTP logic is very fragile on parsing NVMEM cell and can be
problematic with some specific kind of devices.

The problem was discovered by e87161321a ("mtd: rawnand: macronix:
OTP access for MX30LFxG18AC") where OTP support was added to a NAND
device. With the case of NAND devices, it does require a node where ECC
info are declared and all the fixed partitions, and this cause the OTP
codepath to parse this node as OTP NVMEM cells, making probe fail and
the NAND device registration fail.

MTD OTP parsing should have been limited to always using compatible to
prevent this error by using node with compatible "otp-user" or
"otp-factory".

NVMEM across the years had various iteration on how cells could be
declared in DT, in some old implementation, no_of_node should have been
enabled but now add_legacy_fixed_of_cells should be used to disable
NVMEM to parse child node as NVMEM cell.

To fix this and limit any regression with other MTD that makes use of
declaring OTP as direct child of the dev node, disable
add_legacy_fixed_of_cells if we detect the MTD type is Nand.

With the following logic, the OTP NVMEM entry is correctly created with
no cells and the MTD Nand is correctly probed and partitions are
correctly exposed.

Fixes: 4b361cfa86 ("mtd: core: add OTP nvmem provider support")
Cc: <stable@vger.kernel.org> # v6.7+
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20240412105030.1598-1-ansuelsmth@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-05-17 12:01:55 +02:00
..
chips mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 17:20:06 +00:00
devices mtd: spear_smi: Use helper function devm_clk_get_enabled() 2023-08-21 09:44:39 +02:00
hyperbus
lpddr mtd: lpddr2_nvm: Convert to devm_platform_ioremap_resource() 2023-07-12 14:08:26 +02:00
maps mtd: maps: physmap-core: fix flash size larger than 32-bit 2024-03-26 18:19:52 -04:00
nand mtd: diskonchip: work around ubsan link failure 2024-05-02 16:32:46 +02:00
parsers Raw NAND core changes: 2023-04-19 20:39:03 +02:00
spi-nor Core MTD changes: 2023-09-03 09:59:53 -07:00
tests
ubi ubi: correct the calculation of fastmap size 2024-04-03 15:28:21 +02:00
Kconfig
Makefile
ftl.c
inftlcore.c
inftlmount.c
mtd_blkdevs.c mtd: Fix gluebi NULL pointer dereference caused by ftl notifier 2024-01-25 15:35:15 -08:00
mtdblock.c mtdblock: make warning messages ratelimited 2023-07-27 17:16:14 +02:00
mtdblock_ro.c mtdblock: make warning messages ratelimited 2023-07-27 17:16:14 +02:00
mtdchar.c mtdchar: mark bits of ioctl handler noinline 2023-06-01 18:12:31 +02:00
mtdconcat.c
mtdcore.c mtd: limit OTP NVMEM cell parse to non-NAND devices 2024-05-17 12:01:55 +02:00
mtdcore.h mtd: use refcount to prevent corruption 2023-07-12 13:30:08 +02:00
mtdoops.c
mtdpart.c mtd: use refcount to prevent corruption 2023-07-12 13:30:08 +02:00
mtdpstore.c
mtdsuper.c mtd: key superblock by device number 2023-08-31 12:47:15 +02:00
mtdswap.c
nftlcore.c
nftlmount.c
rfd_ftl.c
sm_ftl.c mtd: sm_ftl: Fix typos in comments 2023-06-22 23:00:43 +02:00
sm_ftl.h
ssfdc.c