Skip to contentSkip to conversation

mtd: physmap: Fix mtd device size

PATCH In review Victor Fusco 2 participants 2 messages Mar 19, 2020 – Apr 27, 2020 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: physmap: Fix mtd device size

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.

---
 drivers/mtd/maps/physmap-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/mtd/maps/physmap-core.c +7 -5
index 8f7f966fa9a7..27cc6ac01ea8 100644
@@ -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

Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#1 lore raw

Hi Victor,

Victor Fusco <[email protected]> wrote on Thu, 19 Mar 2020 14:41:29 +0000:

Quoted 1 line

This patch fixes the mtd device size calculation when there is no gpio

s/mtd/MTD/

S/gpio/GPIO/

Quoted 2 lines

defined. The previous size calculation could return values lower than those defined on the 'reg' field of the Device Tree, rasing 'attempt to

s/rasing/raising/ ?

Quoted 22 lines

access beyond end of device' errors during device access.

---
 drivers/mtd/maps/physmap-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/mtd/maps/physmap-core.c +0 -5
index 8f7f966fa9a7..27cc6ac01ea8 100644
@@ -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;
 

drivers/mtd/maps/physmap-core.c static int physmap_flash_probe(struct platform_device *dev) · line 534

Quoted 10 lines
drivers/mtd/maps/physmap-core.c +6 -0
 		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);

I didn't check the driver but are you sure info->win_order and maps[i].map_priv_1 do not need to be initialized? Also are these fields still needed if you stop using them? (just asking)

drivers/mtd/maps/physmap-core.c static int physmap_flash_probe(struct platform_device *dev) · line 535

Quoted 1 line
drivers/mtd/maps/physmap-core.c +1 -0
+

Extra new line

Quoted 5 lines
drivers/mtd/maps/physmap-core.c +0 -0
 		}
 
 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS

base-commit: 5076190daded2197f62fe92cf69674488be44175

Thanks,
Miquèl

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