[PATCH 1/5] mtd: maps: lantiq-flash: fix NULL pointer dereference on probe
Simon Wunderlich
sw at simonwunderlich.de
Sat Nov 14 02:06:03 PST 2026
Since commit 6145e07e9c77 ("mtd: lantiq-flash: Use
devm_platform_get_and_ioremap_resource()"), ltq_mtd_probe() stores the
ioremapped address in ltq_mtd->map->virt before ltq_mtd->map is
allocated. ltq_mtd comes from devm_kzalloc(), so map is still NULL at
that point and the probe dereferences a NULL pointer on every board
with a "lantiq,nor" node.
Allocate the map before mapping the resource.
Found by code inspection while porting a lantiq-flash change from
OpenWrt, which replaces this probe function downstream.
Fixes: 6145e07e9c77 ("mtd: lantiq-flash: Use devm_platform_get_and_ioremap_resource()")
Cc: stable at vger.kernel.org
Signed-off-by: Simon Wunderlich <sw at simonwunderlich.de>
---
drivers/mtd/maps/lantiq-flash.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index 80d467eba92a..5c2ace302b50 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -118,15 +118,15 @@ ltq_mtd_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ltq_mtd);
- ltq_mtd->map->virt = devm_platform_get_and_ioremap_resource(pdev, 0, <q_mtd->res);
- if (IS_ERR(ltq_mtd->map->virt))
- return PTR_ERR(ltq_mtd->map->virt);
-
ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info),
GFP_KERNEL);
if (!ltq_mtd->map)
return -ENOMEM;
+ ltq_mtd->map->virt = devm_platform_get_and_ioremap_resource(pdev, 0, <q_mtd->res);
+ if (IS_ERR(ltq_mtd->map->virt))
+ return PTR_ERR(ltq_mtd->map->virt);
+
ltq_mtd->map->phys = ltq_mtd->res->start;
ltq_mtd->map->size = resource_size(ltq_mtd->res);
--
2.47.3
More information about the linux-mtd
mailing list