From: Orgad Shaneh <orgads@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
tsbogend@alpha.franken.de
Cc: linux-mtd@lists.infradead.org, linux-mips@vger.kernel.org,
linux-kernel@vger.kernel.org, linusw@kernel.org,
kaloz@kernel.org, ulli.kroll@googlemail.com, john@phrozen.org,
nico@fluxnic.net, dwmw2@infradead.org, corbet@lwn.net,
linux-doc@vger.kernel.org
Subject: [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device
Date: Tue, 17 Nov 2026 21:41:40 +0000 [thread overview]
Message-ID: <20261117214141.3826637-4-orgads@gmail.com> (raw)
In-Reply-To: <20261117214141.3826637-1-orgads@gmail.com>
octeon_flash_probe() fills in one static map_info for every "cfi-flash"
node it binds to, so a second chip select overwrites the phys, virt,
size and bank width of the first while that MTD device still uses the
map. A probe whose do_map_probe() finds no chip also keeps its
ioremap() mapping and still returns success.
Allocate the map with devm_kzalloc(), map it with devm_ioremap() and
fail the probe when no chip is found or the partitions cannot be
registered, so the mapping goes away with the device. mymtd was never
read; drop it.
The driver has no remove(), and the mapping is now device-managed: a
sysfs unbind would unmap the flash while its MTD device stays
registered. Set suppress_bind_attrs to rule that out.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
v4: new. sashiko flagged the shared static flash_map against v2 and
v3 of the next patch; v3 left it as it is in mainline, this fixes
it first.
arch/mips/cavium-octeon/flash_setup.c | 49 ++++++++++++++++-----------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 66d173b..0e5652f 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -18,8 +18,6 @@
#include <asm/octeon/octeon.h>
-static struct map_info flash_map;
-static struct mtd_info *mymtd;
static const char *part_probe_types[] = {
"cmdlinepart",
#if IS_ENABLED(CONFIG_MTD_REDBOOT_PARTS)
@@ -71,6 +69,8 @@ static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
static int octeon_flash_probe(struct platform_device *pdev)
{
union cvmx_mio_boot_reg_cfgx region_cfg;
+ struct map_info *map;
+ struct mtd_info *mtd;
u32 cs;
int r;
struct device_node *np = pdev->dev.of_node;
@@ -85,6 +85,9 @@ static int octeon_flash_probe(struct platform_device *pdev)
*/
region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
if (region_cfg.s.en) {
+ map = devm_kzalloc(&pdev->dev, sizeof(*map), GFP_KERNEL);
+ if (!map)
+ return -ENOMEM;
/*
* The bootloader always takes the flash and sets its
* address so the entire flash fits below
@@ -94,26 +97,32 @@ static int octeon_flash_probe(struct platform_device *pdev)
* access 4MB.
*/
/* Use this name so old part lines work */
- flash_map.name = "phys_mapped_flash";
- flash_map.phys = region_cfg.s.base << 16;
- flash_map.size = 0x1fc00000 - flash_map.phys;
+ map->name = "phys_mapped_flash";
+ map->phys = region_cfg.s.base << 16;
+ map->size = 0x1fc00000 - map->phys;
/* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */
- flash_map.bankwidth = region_cfg.s.width + 1;
- flash_map.virt = ioremap(flash_map.phys, flash_map.size);
+ map->bankwidth = region_cfg.s.width + 1;
+ map->virt = devm_ioremap(&pdev->dev, map->phys, map->size);
+ if (!map->virt)
+ return -ENOMEM;
pr_notice("Bootbus flash: Setting flash for %luMB flash at "
- "0x%08llx\n", flash_map.size >> 20, flash_map.phys);
- WARN_ON(!map_bankwidth_supported(flash_map.bankwidth));
- flash_map.read = octeon_flash_map_read;
- flash_map.write = octeon_flash_map_write;
- flash_map.copy_from = octeon_flash_map_copy_from;
- flash_map.copy_to = octeon_flash_map_copy_to;
- mymtd = do_map_probe("cfi_probe", &flash_map);
- if (mymtd) {
- mymtd->owner = THIS_MODULE;
- mtd_device_parse_register(mymtd, part_probe_types,
- NULL, NULL, 0);
- } else {
+ "0x%08llx\n", map->size >> 20, map->phys);
+ WARN_ON(!map_bankwidth_supported(map->bankwidth));
+ map->read = octeon_flash_map_read;
+ map->write = octeon_flash_map_write;
+ map->copy_from = octeon_flash_map_copy_from;
+ map->copy_to = octeon_flash_map_copy_to;
+ mtd = do_map_probe("cfi_probe", map);
+ if (!mtd) {
pr_err("Failed to register MTD device for flash\n");
+ return -ENXIO;
+ }
+ mtd->owner = THIS_MODULE;
+ r = mtd_device_parse_register(mtd, part_probe_types,
+ NULL, NULL, 0);
+ if (r) {
+ map_destroy(mtd);
+ return r;
}
}
return 0;
@@ -131,6 +140,8 @@ static struct platform_driver of_flash_driver = {
.driver = {
.name = "octeon-of-flash",
.of_match_table = of_flash_match,
+ /* No remove(): the map and the MTD device stay registered */
+ .suppress_bind_attrs = true,
},
.probe = octeon_flash_probe,
};
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-17 21:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 21:41 [PATCH v4 0/4] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 1/4] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
2026-11-17 21:57 ` sashiko-bot
2026-11-17 22:06 ` Orgad Shaneh
2026-11-17 21:41 ` Orgad Shaneh [this message]
2026-11-17 21:50 ` [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device sashiko-bot
2026-11-17 22:06 ` Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 4/4] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
2026-11-17 22:06 ` sashiko-bot
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=20261117214141.3826637-4-orgads@gmail.com \
--to=orgads@gmail.com \
--cc=corbet@lwn.net \
--cc=dwmw2@infradead.org \
--cc=john@phrozen.org \
--cc=kaloz@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-doc@vger.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=nico@fluxnic.net \
--cc=richard@nod.at \
--cc=tsbogend@alpha.franken.de \
--cc=ulli.kroll@googlemail.com \
--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