Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: map_ram: prevent use of point and unpoint when NO_XIP is set

When the DT property no-unaligned-direct-access is set, map->phys is set
to NO_XIP. With this property set, the flash should not be exposed
directly to MTD users, since it cannot be mapped.

map_ram() exposes the flash direct access unconditionally which leads to
access errors (when the bus width does not match the RAM width).

Therefore do not set point and unpoint when NO_XIP is set.

Signed-off-by: Shivamurthy Shastri <shivamurthy.shastri@linutronix.de>
Reviewed-by: Benedikt Spranger <b.spranger@linutronix.de>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230919113320.16953-1-shivamurthy.shastri@linutronix.de

authored by

Shivamurthy Shastri and committed by
Miquel Raynal
3cff177f 28a05da7

+6 -2
+6 -2
drivers/mtd/chips/map_ram.c
··· 70 70 mtd->_read = mapram_read; 71 71 mtd->_write = mapram_write; 72 72 mtd->_panic_write = mapram_write; 73 - mtd->_point = mapram_point; 74 73 mtd->_sync = mapram_nop; 75 - mtd->_unpoint = mapram_unpoint; 76 74 mtd->flags = MTD_CAP_RAM; 77 75 mtd->writesize = 1; 76 + 77 + /* Disable direct access when NO_XIP is set */ 78 + if (map->phys != NO_XIP) { 79 + mtd->_point = mapram_point; 80 + mtd->_unpoint = mapram_unpoint; 81 + } 78 82 79 83 mtd->erasesize = PAGE_SIZE; 80 84 while(mtd->size & (mtd->erasesize - 1))