mtd: mtdchar: enable mmap() for MTD_RAM devices with a physical map

The mmap() path in mtdchar has been intentionally dead since commit
9fdca4d ('mtd: kill dead code in mtdchar_mmap') with the comment
'This is broken because it assumes the MTD device is map-based'.

Re-enable mmap() for MTD_RAM devices that explicitly set mtd->priv to
a valid struct map_info with a known physical address (map->phys !=
NO_XIP). The NULL and NO_XIP guards prevent the broken assumptions
that caused the original removal from applying to any other device.

All other MTD types continue to return -ENODEV as before.

This is a prerequisite for Everspin MRAM on Cadence OSPI (DAC mode)
which exposes the memory as a directly CPU-addressable AHB window.

Signed-off-by: Heinrich Toews <ht@twx-software.de>
This commit is contained in:
Heinrich Toews
2026-04-07 16:35:22 +02:00
parent c02ca98757
commit 1259dde287
+6 -5
View File
@@ -1381,11 +1381,12 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
struct mtd_info *mtd = mfi->mtd;
struct map_info *map = mtd->priv;
/* This is broken because it assumes the MTD device is map-based
and that mtd->priv is a valid struct map_info. It should be
replaced with something that uses the mtd_get_unmapped_area()
operation properly. */
if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) {
/*
* Only MTD_RAM devices that have a valid map_info with a physical
* address (e.g. MRAM on a Cadence OSPI DAC window) support mmap().
* All other MTD types return -ENODEV as before.
*/
if (mtd->type == MTD_RAM && map && map->phys != NO_XIP) {
#ifdef pgprot_noncached
if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory))
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);