[PATCH] mtd: Use I/O memory accessors when in an uncached
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Thu Nov 19 20:47:29 PST 2026
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mtd: phram: wrong I/O accessor memcpy_fromio() used in
phram_write()
- [Low] mtd: phram: missing __iomem casts in phram_erase(),
phram_read(), phram_write()
- [Low] mtd: phram: redundant DT lookup on every I/O instead of using
phram->cached
--
commit 652c886e91fa425e4122f1ebcb9ef0f2b874fd28
Author: Edward Adam Davis <eadavis at sina.com>
mtd: Use I/O memory accessors when in an uncached
This commit uses I/O memory accessors instead of standard memset() and
memcpy() in phram_erase(), phram_read(), and phram_write() when the phram
mapping is uncached.
> diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
> index b42cadcd76b11..95bd5a9d7e482 100644
> --- a/drivers/mtd/devices/phram.c
> +++ b/drivers/mtd/devices/phram.c
> @@ -43,8 +43,13 @@ static LIST_HEAD(phram_list);
> static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
> {
> u_char *start = mtd->priv;
> + struct device_node *np = mtd_get_of_node(mtd);
> + bool cached = np ? !of_property_read_bool(np, "no-map") : false;
[Severity: Low]
Can phram_erase(), phram_read(), and phram_write() read
container_of(mtd, struct phram_mtd_list, mtd)->cached instead of calling
of_property_read_bool() on every I/O? register_device() already computes
this flag once and stores it in new->cached.
> - memset(start + instr->addr, 0xff, instr->len);
> + if (cached)
> + memset(start + instr->addr, 0xff, instr->len);
> + else
> + memset_io(start + instr->addr, 0xff, instr->len);
[Severity: Low]
Since start is u_char *, passing start + offset to memset_io(),
memcpy_fromio(), and memcpy_toio() without a (void __iomem *) cast
triggers sparse address-space warnings across phram_erase(), phram_read(),
and phram_write().
>
> return 0;
> }
> @@ -66,8 +71,13 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
> size_t *retlen, u_char *buf)
> {
> u_char *start = mtd->priv;
> + struct device_node *np = mtd_get_of_node(mtd);
> + bool cached = np ? !of_property_read_bool(np, "no-map") : false;
>
> - memcpy(buf, start + from, len);
> + if (cached)
> + memcpy(buf, start + from, len);
> + else
> + memcpy_fromio(buf, start + from, len);
> *retlen = len;
> return 0;
> }
> @@ -76,8 +86,13 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
> size_t *retlen, const u_char *buf)
> {
> u_char *start = mtd->priv;
> + struct device_node *np = mtd_get_of_node(mtd);
> + bool cached = np ? !of_property_read_bool(np, "no-map") : false;
>
> - memcpy(start + to, buf, len);
> + if (cached)
> + memcpy(start + to, buf, len);
> + else
> + memcpy_fromio(start + to, buf, len);
[Severity: High]
Should phram_write() call memcpy_toio() instead of memcpy_fromio()?
memcpy_fromio(dst, src, count) treats src (buf) as __iomem and dst
(start + to) as normal RAM: it aligns src rather than dst and writes to
dst via put_unaligned(). When start + to is not aligned to sizeof(long),
writing to an uncached phram device issues unaligned word stores to
Device memory and triggers an alignment fault on arm64.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120043709.99845-1-eadavis@sina.com?part=1
More information about the linux-mtd
mailing list