diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 8dc4f5c493fc..b4625cecc151 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -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);