mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: tsbogend@alpha.franken.de, "Orgad Shaneh" <orgads@gmail.com>,
	miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mips@vger.kernel.org, nico@fluxnic.net, corbet@lwn.net,
	linux-doc@vger.kernel.org, john@phrozen.org, kaloz@openwrt.org,
	ulli.kroll@googlemail.com, linusw@kernel.org,
	linux-kernel@vger.kernel.org, dwmw2@infradead.org,
	linux-mtd@lists.infradead.org
Subject: Re: [PATCH v3 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC
Date: Sun, 11 Oct 2026 06:39:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-167073@kernel.org> (raw)
In-Reply-To: <20261011062908.2365879-4-orgads@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: cavium: global state corruption of flash_map on multiple probes
--

commit c32cf6c857e3356732452178a52a4e739fcaf273
Author: Orgad Shaneh <orgads@gmail.com>

MIPS: Octeon: flash: use the simple map accessors without a shared eMMC

This commit modifies the Octeon flash driver to conditionally use simple map
accessors when the bootbus is not shared with an eMMC host. Doing so avoids
unnecessary semaphore usage and enables MTD to use the point() method
for faster jffs2 mounts. It also adds early bank width validation before
mapping memory.

> diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
> index 3395acde4d60a..5448d5139c640 100644
> --- a/arch/mips/cavium-octeon/flash_setup.c
> +++ b/arch/mips/cavium-octeon/flash_setup.c

[ ... ]

> @@ -102,11 +119,20 @@ static int octeon_flash_probe(struct platform_device *pdev)
>  		flash_map.virt = ioremap(flash_map.phys, flash_map.size);
>  		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;
> +		/*
> +		 * The boot bus semaphore only serializes the flash against
> +		 * an eMMC host that shares the bus (the CIU3 parts have
> +		 * their own). Without one, use the simple accessors: they
> +		 * let MTD point at the flash, so jffs2 scans it in place.
> +		 */
> +		if (octeon_flash_bus_shared()) {
> +			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;
> +		} else {
> +			simple_map_init(&flash_map);
> +		}
>  		mymtd = do_map_probe("cfi_probe", &flash_map);

[Severity: High]
Can this cause global state corruption if multiple flash devices are probed?

Looking at arch/mips/cavium-octeon/flash_setup.c, flash_map is defined as a
single static struct map_info instance:

static struct map_info flash_map;

If multiple cfi-flash devices are present on the platform bus,
octeon_flash_probe() will be called for each of them. A second probe will
overwrite the phys, virt, size, and bankwidth fields of the shared flash_map
instance.

Since do_map_probe() passes a pointer to flash_map to the CFI layer, both
mtd_info instances will retain a reference to this single map via mtd->priv. Any
I/O on the first flash device would then use the mapped memory, size, and CFI
state of the second device, which could lead to data corruption.

Does it make sense to allocate struct map_info dynamically per device instead?

>  		if (mymtd) {
>  			mymtd->owner = THIS_MODULE;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011062908.2365879-1-orgads@gmail.com?part=3

      reply	other threads:[~2026-10-11  6:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10 17:21 [PATCH 0/3] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-10-10 17:21 ` [PATCH 1/3] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
2026-10-10 17:21 ` [PATCH 2/3] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
2026-10-10 17:31   ` sashiko-bot
2026-10-10 17:21 ` [PATCH 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
2026-10-10 17:32   ` sashiko-bot
2026-10-10 18:08 ` [PATCH v2 0/3] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-10-10 18:08   ` [PATCH v2 1/3] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
2026-10-10 18:08   ` [PATCH v2 2/3] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
2026-10-10 18:18     ` sashiko-bot
2026-10-10 18:08   ` [PATCH v2 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
2026-10-10 18:18     ` sashiko-bot
2026-10-11  6:29 ` [PATCH v3 0/3] mtd: point() for cfi_cmdset_0002, on simple maps only Orgad Shaneh
2026-10-11  6:29   ` [PATCH v3 1/3] mtd: maps: only point() maps read through the simple accessors Orgad Shaneh
2026-10-11  6:29   ` [PATCH v3 2/3] mtd: cfi_cmdset_0002: implement point() for simple linear maps Orgad Shaneh
2026-10-11  6:29   ` [PATCH v3 3/3] MIPS: Octeon: flash: use the simple map accessors without a shared eMMC Orgad Shaneh
2026-10-11  6:39     ` sashiko-bot [this message]

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=sashiko-outbox-167073@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dwmw2@infradead.org \
    --cc=john@phrozen.org \
    --cc=kaloz@openwrt.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=orgads@gmail.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --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

all inboxes | Powered by JetHome®