Skip to contentSkip to conversation

clk: st: Fix memory leak

PATCH In review Valentin Ilie 3 participants 5 messages Apr 22, 2014 – May 23, 2014 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: st: Fix memory leak

When it fails to allocate div, gate should be free'd before return

---
 drivers/clk/st/clkgen-pll.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/st/clkgen-pll.c +3 -1
index bca0a0b..a886702 100644
@@ -521,8 +521,10 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
 	gate->lock = odf_lock;
 
 	div = kzalloc(sizeof(*div), GFP_KERNEL);
-	if (!div)
+	if (!div) {
+		kfree(gate);
 		return ERR_PTR(-ENOMEM);
+	}
 
 	div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
 	div->reg = reg + pll_data->odf[odf].offset;
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 24 lines · Valentin Ilie

When it fails to allocate div, gate should be free'd before return

---
 drivers/clk/st/clkgen-pll.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/st/clkgen-pll.c +3 -2
index bca0a0b..a886702 100644
@@ -521,8 +521,10 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
        gate->lock = odf_lock;
 
        div = kzalloc(sizeof(*div), GFP_KERNEL);
-       if (!div)
+       if (!div) {
+               kfree(gate);
                return ERR_PTR(-ENOMEM);
+       }
 
        div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
        div->reg = reg + pll_data->odf[odf].offset;
--
Quoted 2 lines

1.8.3.2

Can someone look into this?

Signature · 1 line
Valentin Ilie
#2 lore raw

Hi Valentin
Thanks for the patch, i agree with it.

Mike do you planned to integrate this patch ?

Gabriel.

Best Regards.

Quoted 29 lines · Valentin Ilie
Quoted 24 lines · Valentin Ilie

When it fails to allocate div, gate should be free'd before return

---
  drivers/clk/st/clkgen-pll.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/st/clkgen-pll.c +3 -2
index bca0a0b..a886702 100644
@@ -521,8 +521,10 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
         gate->lock = odf_lock;
 
         div = kzalloc(sizeof(*div), GFP_KERNEL);
-       if (!div)
+       if (!div) {
+               kfree(gate);
                 return ERR_PTR(-ENOMEM);
+       }
 
         div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
         div->reg = reg + pll_data->odf[odf].offset;
--
Quoted 2 lines

1.8.3.2

Can someone look into this?

#3 lore raw

Hi,

Even though the probability of getting a memory leak here is small I think this patch is worth applying.

Thanks,
Valentin

Quoted 45 lines · Gabriel Fernandez

Hi Valentin
Thanks for the patch, i agree with it.

Mike do you planned to integrate this patch ?

Gabriel.

Best Regards.

Quoted 32 lines · Valentin Ilie
Quoted 25 lines · Valentin Ilie

When it fails to allocate div, gate should be free'd before return

---
  drivers/clk/st/clkgen-pll.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/st/clkgen-pll.c +3 -1
index bca0a0b..a886702 100644
@@ -521,8 +521,10 @@ static struct clk * __init clkgen_odf_register(const
 char *parent_name,
         gate->lock = odf_lock;
 
         div = kzalloc(sizeof(*div), GFP_KERNEL);
-       if (!div)
+       if (!div) {
+               kfree(gate);
                 return ERR_PTR(-ENOMEM);
+       }
 
         div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
         div->reg = reg + pll_data->odf[odf].offset;
Quoted 3 lines

--
1.8.3.2

Can someone look into this?

Signature · 2 lines
Valentin Ilie
+(40) 746 188 558
#4 lore raw
In reply to Valentin Ilie

Quoting Valentin Ilie (2014-04-22 06:15:54)

Quoted 3 lines

When it fails to allocate div, gate should be free'd before return

Taken into clk-fixes.

Regards,
Mike

Quoted 23 lines
---
 drivers/clk/st/clkgen-pll.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/st/clkgen-pll.c +3 -1
index bca0a0b..a886702 100644
@@ -521,8 +521,10 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
        gate->lock = odf_lock;
 
        div = kzalloc(sizeof(*div), GFP_KERNEL);
-       if (!div)
+       if (!div) {
+               kfree(gate);
                return ERR_PTR(-ENOMEM);
+       }
 
        div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
        div->reg = reg + pll_data->odf[odf].offset;
Signature · 1 line
1.8.3.2