Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Edward Adam Davis" <eadavis@sina.com>,
	syzbot+ee09ee2112d03c35f1f7@syzkaller.appspotmail.com
Cc: joern@lazybastard.org, linux-mtd@lists.infradead.org,
	miquel.raynal@bootlin.com, richard@nod.at,
	syzkaller-bugs@googlegroups.com, vigneshr@ti.com
Subject: Re: [PATCH] mtd: Use I/O memory accessors when in an uncached
Date: Fri, 20 Nov 2026 04:47:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-224471@kernel.org> (raw)
In-Reply-To: <20261120043709.99845-1-eadavis@sina.com>

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@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

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

      reply	other threads:[~2026-11-20  4:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  1:49 [syzbot] [mtd?] BUG: unable to handle kernel paging request in phram_read syzbot
2026-11-20  4:37 ` [PATCH] mtd: Use I/O memory accessors when in an uncached Edward Adam Davis
2026-11-20  4:47   ` 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-224471@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eadavis@sina.com \
    --cc=joern@lazybastard.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=syzbot+ee09ee2112d03c35f1f7@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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