* [PATCH] mtd: lantiq-flash: Fix NULL pointer dereference in probe
@ 2026-11-06 1:49 Guo Zihao
2026-11-17 13:32 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Guo Zihao @ 2026-11-06 1:49 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: Yangtao Li, linux-mtd, linux-kernel, stable
ltq_mtd_probe() dereferences ltq_mtd->map->virt before the map_info
structure is allocated: the map pointer itself is still NULL when
ltq_mtd->map->virt is assigned, because the structure is allocated a
few lines below. Any device with a "lantiq,nor" compatible therefore
crashes the kernel with a NULL pointer dereference during probe.
Assign the mapping after the map_info allocation instead.
Fixes: 6145e07e9c77 ("mtd: lantiq-flash: Use devm_platform_get_and_ioremap_resource()")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---
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 80d467eba..5c2ace302 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.50.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mtd: lantiq-flash: Fix NULL pointer dereference in probe
2026-11-06 1:49 [PATCH] mtd: lantiq-flash: Fix NULL pointer dereference in probe Guo Zihao
@ 2026-11-17 13:32 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-11-17 13:32 UTC (permalink / raw)
To: Guo Zihao
Cc: Richard Weinberger, Vignesh Raghavendra, Yangtao Li, linux-mtd,
linux-kernel, stable
On 06/11/2026 at 09:49:28 +08, Guo Zihao <guozh23@xiaopeng.com> wrote:
> ltq_mtd_probe() dereferences ltq_mtd->map->virt before the map_info
> structure is allocated: the map pointer itself is still NULL when
> ltq_mtd->map->virt is assigned, because the structure is allocated a
> few lines below. Any device with a "lantiq,nor" compatible therefore
> crashes the kernel with a NULL pointer dereference during probe.
>
> Assign the mapping after the map_info allocation instead.
>
> Fixes: 6145e07e9c77 ("mtd: lantiq-flash: Use devm_platform_get_and_ioremap_resource()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
Hello, this is a duplicate of a wider series from Simon Wunderlich, I
took his since there are more behavioral fixes.
Thanks for the contribution anyway!
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 1:49 [PATCH] mtd: lantiq-flash: Fix NULL pointer dereference in probe Guo Zihao
2026-11-17 13:32 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox