From: Simon Wunderlich <sw@simonwunderlich.de>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
linux-mtd@lists.infradead.org
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
devicetree@vger.kernel.org,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
linux-mips@vger.kernel.org, Hauke Mehrtens <hauke@hauke-m.de>,
Aleksander Jan Bajkowski <olek2@wp.pl>,
John Crispin <john@phrozen.org>,
Sebastien Decourriere <sebtx452@gmail.com>,
Yangtao Li <frank.li@vivo.com>,
linux-kernel@vger.kernel.org,
Simon Wunderlich <sw@simonwunderlich.de>,
stable@vger.kernel.org
Subject: [PATCH 1/5] mtd: maps: lantiq-flash: fix NULL pointer dereference on probe
Date: Sat, 14 Nov 2026 11:06:03 +0100 [thread overview]
Message-ID: <20261114100608.3432120-2-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261114100608.3432120-1-sw@simonwunderlich.de>
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@vger.kernel.org
Signed-off-by: Simon Wunderlich <sw@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
next prev parent reply other threads:[~2026-11-14 10:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 10:06 [PATCH 0/5] mtd: maps: lantiq-flash: support boot loaders using the EBU endianness swap Simon Wunderlich
2026-11-14 10:06 ` Simon Wunderlich [this message]
2026-11-14 10:06 ` [PATCH 2/5] dt-bindings: mtd: Add lantiq,nor Simon Wunderlich
2026-11-14 10:06 ` [PATCH 3/5] mips: lantiq: xway: sysctrl: export ltq_ebu_membase Simon Wunderlich
2026-11-14 10:06 ` [PATCH 4/5] mtd: maps: lantiq-flash: honour the EBU's own endianness swap Simon Wunderlich
2026-11-14 10:06 ` [PATCH 5/5] mips: lantiq: danube: rename NOR node on EASY50712 reference board Simon Wunderlich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114100608.3432120-2-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=frank.li@vivo.com \
--cc=hauke@hauke-m.de \
--cc=john@phrozen.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=olek2@wp.pl \
--cc=richard@nod.at \
--cc=robh@kernel.org \
--cc=sebtx452@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®