All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Orgad Shaneh" <orgads@gmail.com>,
	miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
	tsbogend@alpha.franken.de
Cc: linux-mtd@lists.infradead.org, linusw@kernel.org,
	kaloz@kernel.org, ulli.kroll@googlemail.com, john@phrozen.org,
	nico@fluxnic.net, dwmw2@infradead.org, corbet@lwn.net
Subject: Re: [PATCH v4 2/4] mtd: cfi_cmdset_0002: implement point() for simple linear maps
Date: Tue, 17 Nov 2026 21:57:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-219722@kernel.org> (raw)
In-Reply-To: <20261117214141.3826637-3-orgads@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: cfi_cmdset_0002: non-NULL *virt left set on error in
  cfi_amdstd_point()
--

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

mtd: cfi_cmdset_0002: implement point() for simple linear maps

This commit implements the point() and unpoint() methods for linearly
mapped AMD/Fujitsu CFI flash chips using simple map accessors, and updates
the cramfs documentation accordingly.

> diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
> index 100cab95a17b1..1fc2709539ed0 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0002.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0002.c

[ ... ]

> @@ -1215,6 +1245,133 @@ do {  \
>
>  #endif
>
> +static int do_point_onechip(struct map_info *map, struct flchip *chip,
> +			    loff_t adr, size_t len)
> +{
> +	unsigned long cmd_addr;
> +	struct cfi_private *cfi = map->fldrv_priv;
> +	int ret;
> +
> +	adr += chip->start;
> +
> +	/* Ensure cmd read/writes are aligned. */
> +	cmd_addr = adr & ~(map_bankwidth(map) - 1);
> +
> +	mutex_lock(&chip->mutex);
> +	ret = get_chip(map, chip, cmd_addr, FL_POINT);
> +	if (!ret) {
> +		if (chip->state != FL_POINT && chip->state != FL_READY)
> +			map_write(map, CMD(0xf0), cmd_addr);
> +
> +		chip->state = FL_POINT;
> +		chip->ref_point_counter++;
> +	}
> +	mutex_unlock(&chip->mutex);
> +
> +	return ret;
> +}
> +
> +static int cfi_amdstd_point(struct mtd_info *mtd, loff_t from, size_t len,
> +			    size_t *retlen, void **virt, resource_size_t *phys)
> +{
> +	struct map_info *map = mtd->priv;
> +	struct cfi_private *cfi = map->fldrv_priv;
> +	unsigned long ofs, last_end = 0;
> +	int chipnum;
> +	int ret = -EINVAL;
> +
> +	if (!map->virt)
> +		return -EINVAL;
> +
> +	/* ofs: offset within the first chip that the first read should start */
> +	chipnum = (from >> cfi->chipshift);
> +	ofs = from - (chipnum << cfi->chipshift);
> +
> +	*virt = map->virt + cfi->chips[chipnum].start + ofs;
> +	if (phys)
> +		*phys = map->phys + cfi->chips[chipnum].start + ofs;
> +
> +	while (len) {
> +		unsigned long thislen;
> +
> +		if (chipnum >= cfi->numchips)
> +			break;
> +
> +		/* We cannot point across chips that are virtually disjoint */
> +		if (!last_end)
> +			last_end = cfi->chips[chipnum].start;
> +		else if (cfi->chips[chipnum].start != last_end)
> +			break;
> +
> +		if ((len + ofs - 1) >> cfi->chipshift)
> +			thislen = (1 << cfi->chipshift) - ofs;
> +		else
> +			thislen = len;
> +
> +		ret = do_point_onechip(map, &cfi->chips[chipnum], ofs, thislen);
> +		if (ret)
> +			break;
> +
> +		*retlen += thislen;
> +		len -= thislen;
> +
> +		ofs = 0;
> +		last_end += 1 << cfi->chipshift;
> +		chipnum++;
> +	}
> +	return *retlen ? 0 : ret;
> +}

[Severity: Medium]
Does cfi_amdstd_point() leave *virt set to a non-NULL address when
do_point_onechip() fails on the first chip?

Unlike cfi_intelext_point(), which always returns 0, cfi_amdstd_point()
returns ret when *retlen is 0, after already assigning *virt.  In
jffs2_scan_medium(), flashbuf is only reset to NULL when mtd_point()
returns 0 with a short pointlen:

fs/jffs2/scan.c:jffs2_scan_medium() {
	...
	ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
			(void **)&flashbuf, NULL);
	if (!ret && pointlen < c->mtd->size) {
		/* Don't muck about if it won't let us point to the whole flash */
		jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
			  pointlen);
		mtd_unpoint(c->mtd, 0, pointlen);
		flashbuf = NULL;
	}
	if (ret && ret != -EOPNOTSUPP)
		jffs2_dbg(1, "MTD point failed %d\n", ret);
#endif
	if (!flashbuf) {
	...
}

If do_point_onechip() returns an error on the first chip, flashbuf remains
non-NULL with buf_size == 0, so jffs2_scan_medium() scans the mapping
directly without holding the chip in FL_POINT or array mode and then calls
mtd_unpoint(c->mtd, 0, c->mtd->size) on cleanup.  Setting *virt and *phys
only after at least one chip is pointed, or clearing *virt on error, would
avoid this.

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

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-11-17 21:57 UTC|newest]

Thread overview: 16+ 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 ` 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   ` 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:41   ` Orgad Shaneh
2026-11-17 21:57   ` sashiko-bot [this message]
2026-11-17 22:06     ` Orgad Shaneh
2026-11-17 21:41 ` [PATCH v4 3/4] MIPS: Octeon: flash: allocate the map per device Orgad Shaneh
2026-11-17 21:41   ` Orgad Shaneh
2026-11-17 21:50   ` 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 21:41   ` Orgad Shaneh
2026-11-17 22:06   ` sashiko-bot
2026-11-18  6:35     ` Orgad Shaneh

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-219722@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dwmw2@infradead.org \
    --cc=john@phrozen.org \
    --cc=kaloz@kernel.org \
    --cc=linusw@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.