Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mtd: physmap: Fix mtd device size
@ 2020-03-19 14:41 Victor Fusco
  0 siblings, 0 replies; only message in thread
From: Victor Fusco @ 2020-03-19 14:41 UTC (permalink / raw)
  To: linux-mtd; +Cc: Victor Fusco

This patch fixes the mtd device size calculation when there is no gpio
defined. The previous size calculation could return values lower than
those defined on the 'reg' field of the Device Tree, rasing 'attempt to
access beyond end of device' errors during device access.

Signed-off-by: Victor Fusco <victor@cartesi.io>
---
 drivers/mtd/maps/physmap-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-core.c
index 8f7f966fa9a7..27cc6ac01ea8 100644
--- a/drivers/mtd/maps/physmap-core.c
+++ b/drivers/mtd/maps/physmap-core.c
@@ -520,17 +520,19 @@ static int physmap_flash_probe(struct platform_device *dev)
 		if (!info->maps[i].phys)
 			info->maps[i].phys = res->start;
 
-		info->win_order = get_bitmask_order(resource_size(res)) - 1;
-		info->maps[i].size = BIT(info->win_order +
-					 (info->gpios ?
-					  info->gpios->ndescs : 0));
-
 		info->maps[i].map_priv_1 = (unsigned long)dev;
 
 		if (info->gpios) {
+			info->win_order = get_bitmask_order(resource_size(res)) - 1;
+			info->maps[i].size = BIT(info->win_order +
+					         info->gpios->ndescs);
+
 			err = physmap_addr_gpios_map_init(&info->maps[i]);
 			if (err)
 				goto err_out;
+		} else {
+			info->maps[i].size = resource_size(res);
+
 		}
 
 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS

base-commit: 5076190daded2197f62fe92cf69674488be44175
-- 
2.17.1


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19 14:41 [PATCH] mtd: physmap: Fix mtd device size Victor Fusco

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git