[PATCH 3/3] mtd: block2mtd: convert _block2mtd_erase() to folios

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Oct 14 20:45:56 PDT 2026


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: missing folio->mapping re-validation after folio_lock()
--

commit 5d3ba379c345de78b1eb892e6685b2e8f75987f5
Author: Tal Zussman <tz2294 at columbia.edu>

mtd: block2mtd: convert _block2mtd_erase() to folios

Erase through a folio instead of a page, and use memchr_inv() to check
whether a range still needs erasing instead of the open-coded scan.
This removes four hidden compound_head() calls per page, and the last
user of page_read(), so remove that too.

> diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
> index 910669d6bb943..a1d24fef415dd 100644
> --- a/drivers/mtd/devices/block2mtd.c
> +++ b/drivers/mtd/devices/block2mtd.c
[ ... ]
>  /* erase a specified part of the device */
>  static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
>  {
>  	struct address_space *mapping = dev->bdev_file->f_mapping;
[ ... ]
> +	while (len) {
> +		folio = read_mapping_folio(mapping, to >> PAGE_SHIFT, NULL);
> +		if (IS_ERR(folio))
> +			return PTR_ERR(folio);
> +
> +		offset = offset_in_folio(folio, to);
> +		chunk = min(len, folio_size(folio) - offset);
> +		p = folio_address(folio) + offset;
> +		if (memchr_inv(p, 0xff, chunk)) {
> +			folio_lock(folio);
> +			memset(p, 0xff, chunk);
> +			folio_mark_dirty(folio);
> +			folio_unlock(folio);

[Severity: Medium]
Could _block2mtd_erase() modify a truncated folio here?

If the folio is truncated from the page cache while waiting for folio_lock(),
we could proceed with modifying the memory without it ever being written back
to the device. Should this re-validate that folio->mapping == mapping after
acquiring the lock?

> +			balance_dirty_pages_ratelimited(mapping);
> +		}
> +		folio_put(folio);
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014-block2mtd-folio-v1-0-19d24ae676ee@columbia.edu?part=3



More information about the linux-mtd mailing list