Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25f0c659 authored by Amol Lad's avatar Amol Lad Committed by David Woodhouse
Browse files

ioremap balanced with iounmap for drivers/mtd subsystem



ioremap must be balanced by an iounmap and failing to do so can result
in a memory leak.

Tested (compilation only) with:
- allmodconfig
- Modifying drivers/mtd/maps/Kconfig and drivers/mtd/nand/Kconfig to
make sure that the changed file is compiling without warning

Signed-off-by: default avatarAmol Lad <amol@verismonetworks.com>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent dd8e9ed6
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ static struct mtd_partition arctic_partitions[PARTITIONS] = {
static int __init
init_arctic_mtd(void)
{
	int err = 0;

	printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);

	arctic_mtd_map.virt = ioremap(PADDR, SIZE);
@@ -109,12 +111,20 @@ init_arctic_mtd(void)
	printk("%s: probing %d-bit flash bus\n", NAME, BUSWIDTH * 8);
	arctic_mtd = do_map_probe("cfi_probe", &arctic_mtd_map);

	if (!arctic_mtd)
	if (!arctic_mtd) {
		iounmap((void *) arctic_mtd_map.virt);
		return -ENXIO;
	}

	arctic_mtd->owner = THIS_MODULE;

	return add_mtd_partitions(arctic_mtd, arctic_partitions, PARTITIONS);
	err = add_mtd_partitions(arctic_mtd, arctic_partitions, PARTITIONS);
	if (err) {
		printk("%s: add_mtd_partitions failed\n", NAME);
		iounmap((void *) arctic_mtd_map.virt);
	}

	return err;
}

static void __exit
+12 −2
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ static struct mtd_partition beech_partitions[2] = {
static int __init
init_beech_mtd(void)
{
	int err = 0;

	printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);

	beech_mtd_map.virt = ioremap(PADDR, SIZE);
@@ -86,12 +88,20 @@ init_beech_mtd(void)
	printk("%s: probing %d-bit flash bus\n", NAME, BUSWIDTH * 8);
	beech_mtd = do_map_probe("cfi_probe", &beech_mtd_map);

	if (!beech_mtd)
	if (!beech_mtd) {
		iounmap((void *) beech_mtd_map.virt);
		return -ENXIO;
	}

	beech_mtd->owner = THIS_MODULE;

	return add_mtd_partitions(beech_mtd, beech_partitions, 2);
	err = add_mtd_partitions(beech_mtd, beech_partitions, 2);
	if (err) {
		printk("%s: add_mtd_partitions failed\n", NAME);
		iounmap((void *) beech_mtd_map.virt);
	}

	return err;
}

static void __exit
+16 −2
Original line number Diff line number Diff line
@@ -171,7 +171,14 @@ int __init init_cstm_mips_ixx(void)
		cstm_mips_ixx_map[i].phys = cstm_mips_ixx_board_desc[i].window_addr;
		cstm_mips_ixx_map[i].virt = ioremap(cstm_mips_ixx_board_desc[i].window_addr, cstm_mips_ixx_board_desc[i].window_size);
		if (!cstm_mips_ixx_map[i].virt) {
			int j = 0;
			printk(KERN_WARNING "Failed to ioremap\n");
			for (j = 0; j < i; j++) {
				if (cstm_mips_ixx_map[j].virt) {
					iounmap((void *)cstm_mips_ixx_map[j].virt);
					cstm_mips_ixx_map[j].virt = 0;
				}
			}
			return -EIO;
	        }
		cstm_mips_ixx_map[i].name = cstm_mips_ixx_board_desc[i].name;
@@ -204,9 +211,16 @@ int __init init_cstm_mips_ixx(void)
	                cstm_mips_ixx_map[i].map_priv_2 = (unsigned long)mymtd;
		        add_mtd_partitions(mymtd, parts, cstm_mips_ixx_board_desc[i].num_partitions);
		}
		else
		else {
			for (i = 0; i < PHYSMAP_NUMBER; i++) {
				if (cstm_mips_ixx_map[i].virt) {
					iounmap((void *)cstm_mips_ixx_map[i].virt);
					cstm_mips_ixx_map[i].virt = 0;
				}
			}
			return -ENXIO;
		}
	}
	return 0;
}

+4 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ int __init init_ebony(void)
					ARRAY_SIZE(ebony_small_partitions));
	} else {
		printk("map probe failed for flash\n");
		iounmap(ebony_small_map.virt);
		return -ENXIO;
	}

@@ -117,6 +118,7 @@ int __init init_ebony(void)

	if (!ebony_large_map.virt) {
		printk("Failed to ioremap flash\n");
		iounmap(ebony_small_map.virt);
		return -EIO;
	}

@@ -129,6 +131,8 @@ int __init init_ebony(void)
					ARRAY_SIZE(ebony_large_partitions));
	} else {
		printk("map probe failed for flash\n");
		iounmap(ebony_small_map.virt);
		iounmap(ebony_large_map.virt);
		return -ENXIO;
	}

+3 −0
Original line number Diff line number Diff line
@@ -218,8 +218,11 @@ int __init init_fortunet(void)
				map_regions[ix].map_info.size);
			if(!map_regions[ix].map_info.virt)
			{
				int j = 0;
				printk(MTD_FORTUNET_PK "%s flash failed to ioremap!\n",
					map_regions[ix].map_info.name);
				for (j = 0 ; j < ix; j++)
					iounmap(map_regions[j].map_info.virt);
				return -ENXIO;
			}
			simple_map_init(&map_regions[ix].map_info);
Loading