Skip to contentSkip to conversation

drivers/mtd/maps/lantiq-flash.c: drop iounmap for devm_ allocated data

PATCH Applied Julia Lawall 3 participants 3 messages Dec 26, 2011 – Dec 27, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drivers/mtd/maps/lantiq-flash.c: drop iounmap for devm_ allocated data

From: Julia Lawall <[email protected]>

Data allocated with devm_ioremap or devm_ioremap_nocache should not be freed using iounmap, because doing so causes a dangling pointer, and a subsequent double free.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression x;
@@
(
x = devm_ioremap(...)
|
x = devm_ioremap_nocache(...)
)

@@
expression r.x;
@@
* iounmap(x)
// </smpl>

---
 drivers/mtd/maps/lantiq-flash.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/maps/lantiq-flash.c +1 -5
index 4f10e27..7b889de 100644
@@ -159,7 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev)
 	if (!ltq_mtd->mtd) {
 		dev_err(&pdev->dev, "probing failed\n");
 		err = -ENXIO;
-		goto err_unmap;
+		goto err_free;
 	}
 
 	ltq_mtd->mtd->owner = THIS_MODULE;
@@ -179,8 +179,6 @@ ltq_mtd_probe(struct platform_device *pdev)
 
 err_destroy:
 	map_destroy(ltq_mtd->mtd);
-err_unmap:
-	iounmap(ltq_mtd->map->virt);
 err_free:
 	kfree(ltq_mtd->map);
 err_out:
@@ -198,8 +196,6 @@ ltq_mtd_remove(struct platform_device *pdev)
 			mtd_device_unregister(ltq_mtd->mtd);
 			map_destroy(ltq_mtd->mtd);
 		}
-		if (ltq_mtd->map->virt)
-			iounmap(ltq_mtd->map->virt);
 		kfree(ltq_mtd->map);
 		kfree(ltq_mtd);
 	}
#1 lore raw
Quoted 19 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Data allocated with devm_ioremap or devm_ioremap_nocache should not be freed using iounmap, because doing so causes a dangling pointer, and a subsequent double free.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression x;
@@
(
x = devm_ioremap(...)
|
x = devm_ioremap_nocache(...)
)

Quoted 5 lines

@@
expression r.x;
@@
* iounmap(x)
// </smpl>

Thanks Julia,

surely this semantic patch script is worth adding to scripts/coccinelle? Are you going to take care of this?

Quoted 12 lines
---
 drivers/mtd/maps/lantiq-flash.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/maps/lantiq-flash.c +0 -0
index 4f10e27..7b889de 100644

drivers/mtd/maps/lantiq-flash.c ltq_mtd_probe(struct platform_device *pdev) · line 163

Quoted 6 lines
drivers/mtd/maps/lantiq-flash.c +1 -1
@@ -159,7 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev)
 	if (!ltq_mtd->mtd) {
 		dev_err(&pdev->dev, "probing failed\n");
 		err = -ENXIO;
-		goto err_unmap;
+		goto err_free;
 	}

Pushed to l2-mtd-2.6.git, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#2 lore raw
Quoted 26 lines · Artem Bityutskiy
Quoted 19 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Data allocated with devm_ioremap or devm_ioremap_nocache should not be freed using iounmap, because doing so causes a dangling pointer, and a subsequent double free.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression x;
@@
(
x = devm_ioremap(...)
|
x = devm_ioremap_nocache(...)
)

Quoted 5 lines

@@
expression r.x;
@@
* iounmap(x)
// </smpl>

Quoted 4 lines

Thanks Julia,

surely this semantic patch script is worth adding to scripts/coccinelle? Are you going to take care of this?

OK, I will do that.

julia