Skip to contentSkip to conversation

OMAP: hsmmc: fix memory leak

PATCH In review Aaro Koskinen 3 participants 6 messages Feb 8, 2010 – Feb 10, 2010

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

PATCH 1/1 OMAP: hsmmc: fix memory leak

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

---
 arch/arm/mach-omap2/hsmmc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/hsmmc.c +6 -1
index 1156b28..9ad2295 100644
@@ -145,6 +145,7 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 {
 	struct omap2_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -171,7 +172,7 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 			      GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -256,6 +257,10 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 1 line
1.5.6.5
maintainer
#1 lore raw
Quoted 3 lines · Aaro Koskinen

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

Looks like this is safe to do as platform_device_add_data does kmemdup on the data.

BTW, if you want to create a version for 2.6.33, we should still have enough time to queue it as a fix. It's a very limited size leak though, but still a leak.

Regards,

Tony

Quoted 40 lines
---
 arch/arm/mach-omap2/hsmmc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/hsmmc.c +6 -1
index 1156b28..9ad2295 100644
@@ -145,6 +145,7 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 {
 	struct omap2_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -171,7 +172,7 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 			      GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -256,6 +257,10 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 1 line
1.5.6.5
#2 lore raw

Hi,

Quoted 11 lines · Tony Lindgren
Quoted 3 lines · Aaro Koskinen

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

Looks like this is safe to do as platform_device_add_data does kmemdup on the data.

BTW, if you want to create a version for 2.6.33, we should still have enough time to queue it as a fix. It's a very limited size leak though, but still a leak.

The version for 2.6.33 is below (also attached).

...

From: Aaro Koskinen <[email protected]>
Date: Thu, 4 Feb 2010 13:06:59 +0200
Subject: [PATCH] OMAP: hsmmc: fix memory leak

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

---
 arch/arm/mach-omap2/mmc-twl4030.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/mmc-twl4030.c +6 -1
index 0c3c72d..8afe9dd 100644
@@ -408,6 +408,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 {
 	struct twl4030_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -434,7 +435,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 		mmc = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -532,6 +533,10 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 1 line
1.5.6.5

From 6d15f48ecc177bde18033af2884eb2c5ce53bfd7 Mon Sep 17 00:00:00 2001
From: Aaro Koskinen <[email protected]>
Date: Thu, 4 Feb 2010 13:06:59 +0200
Subject: [PATCH] OMAP: hsmmc: fix memory leak

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

---
 arch/arm/mach-omap2/mmc-twl4030.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/mmc-twl4030.c +6 -1
index 0c3c72d..8afe9dd 100644
@@ -408,6 +408,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 {
 	struct twl4030_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -434,7 +435,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 		mmc = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -532,6 +533,10 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 1 line
1.5.6.5
maintainer
#3 lore raw

PATCH 1/1 OMAP: hsmmc: fix memory leak

Hi

Added LAKML to Cc for a quick review there too.

Quoted 8 lines · Aaro Koskinen

Hi,

Quoted 5 lines · Tony Lindgren
Quoted 3 lines · Aaro Koskinen

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

Quoted 8 lines
Quoted 6 lines

Looks like this is safe to do as platform_device_add_data does kmemdup on the data.

BTW, if you want to create a version for 2.6.33, we should still have enough time to queue it as a fix. It's a very limited size leak though, but still a leak.

The version for 2.6.33 is below (also attached).

Thanks, added to omap-fixes for 2.6.33.

Regards,

Tony

Quoted 98 lines

From: Aaro Koskinen <[email protected]>
Date: Thu, 4 Feb 2010 13:06:59 +0200
Subject: [PATCH] OMAP: hsmmc: fix memory leak

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

---
 arch/arm/mach-omap2/mmc-twl4030.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/mmc-twl4030.c +6 -1
index 0c3c72d..8afe9dd 100644
@@ -408,6 +408,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 {
 	struct twl4030_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -434,7 +435,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 		mmc = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -532,6 +533,10 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 15 lines
1.5.6.5

From 6d15f48ecc177bde18033af2884eb2c5ce53bfd7 Mon Sep 17 00:00:00 2001
From: Aaro Koskinen <[email protected]>
Date: Thu, 4 Feb 2010 13:06:59 +0200
Subject: [PATCH] OMAP: hsmmc: fix memory leak

The platform data allocated with kmalloc() will become unreachable once
the init is complete, so it should be freed. The problem was discovered
by kmemleak.

Signed-off-by: Aaro Koskinen <[email protected]>
---
 arch/arm/mach-omap2/mmc-twl4030.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/mmc-twl4030.c +6 -1
index 0c3c72d..8afe9dd 100644
@@ -408,6 +408,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 {
 	struct twl4030_hsmmc_info *c;
 	int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
+	int i;
 
 	if (cpu_is_omap2430()) {
 		control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
@@ -434,7 +435,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 		mmc = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
 		if (!mmc) {
 			pr_err("Cannot allocate memory for mmc device!\n");
-			return;
+			goto done;
 		}
 
 		if (c->name)
@@ -532,6 +533,10 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 			continue;
 		c->dev = mmc->dev;
 	}
+
+done:
+	for (i = 0; i < nr_hsmmc; i++)
+		kfree(hsmmc_data[i]);
 }
 
 #endif
Signature · 1 line
1.5.6.5
Acked-by Adrian Hunter on v1 1/1
#4 lore raw
In reply to Aaro Koskinen
Quoted 5 lines · Aaro Koskinen

The platform data allocated with kmalloc() will become unreachable once the init is complete, so it should be freed. The problem was discovered by kmemleak.

You forgot to add:

Signature · 7 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html