linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Fix error handling paths of all basic clock register() routines
@ 2012-04-10  3:54 Viresh Kumar
  2012-05-01 22:48 ` Mike Turquette
  0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2012-04-10  3:54 UTC (permalink / raw)
  To: linux-arm-kernel

This fixes following in error handling paths of register() routines of all basic
clock types:
- Free memory for clock type, allocated with kmalloc or kzalloc if
  clk_register() fails.
- No, need to free memory for clock type, if allocation fails for it.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/clk/clk-divider.c      |    2 +-
 drivers/clk/clk-fixed-factor.c |    2 +-
 drivers/clk/clk-fixed-rate.c   |   25 ++++++++++++++++++++-----
 drivers/clk/clk-gate.c         |    2 +-
 drivers/clk/clk-mux.c          |    8 +++++++-
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index d5ac6a7..68158ce 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -192,8 +192,8 @@ struct clk *clk_register_divider(struct device *dev, const char *name,
 	if (clk)
 		return clk;
 
-out:
 	kfree(div->parent[0]);
+out:
 	kfree(div);
 
 	return NULL;
diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 7c5e1fc..879b6cc 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -89,8 +89,8 @@ struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
 	if (clk)
 		return clk;
 
-out:
 	kfree(fix->parent[0]);
+out:
 	kfree(fix);
 
 	return NULL;
diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c
index 90c79fb..4245aa1 100644
--- a/drivers/clk/clk-fixed-rate.c
+++ b/drivers/clk/clk-fixed-rate.c
@@ -45,6 +45,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
 {
 	struct clk_fixed_rate *fixed;
 	char **parent_names = NULL;
+	struct clk *clk;
 	u8 len;
 
 	fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
@@ -61,22 +62,36 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
 		parent_names = kmalloc(sizeof(char *), GFP_KERNEL);
 
 		if (! parent_names)
-			goto out;
+			goto out_register;
 
 		len = sizeof(char) * strlen(parent_name);
 
 		parent_names[0] = kmalloc(len, GFP_KERNEL);
 
-		if (!parent_names[0])
-			goto out;
+		if (!parent_names[0]) {
+			kfree(parent_names);
+			parent_names = NULL;
+			goto out_register;
+		}
 
 		strncpy(parent_names[0], parent_name, len);
 	}
 
-out:
-	return clk_register(dev, name,
+out_register:
+	clk = clk_register(dev, name,
 			&clk_fixed_rate_ops, &fixed->hw,
 			parent_names,
 			(parent_name ? 1 : 0),
 			flags);
+	if (clk)
+		return clk;
+
+	if (parent_names) {
+		kfree(parent_names[0]);
+		kfree(parent_names);
+	}
+
+	kfree(fixed);
+
+	return NULL;
 }
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index b35eef9..7b2c473 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -138,8 +138,8 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
 			flags);
 	if (clk)
 		return clk;
-out:
 	kfree(gate->parent[0]);
+out:
 	kfree(gate);
 
 	return NULL;
diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index c71ad1f..38816bf 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -96,6 +96,7 @@ struct clk *clk_register_mux(struct device *dev, const char *name,
 		u8 clk_mux_flags, spinlock_t *lock)
 {
 	struct clk_mux *mux;
+	struct clk *clk;
 
 	mux = kmalloc(sizeof(struct clk_mux), GFP_KERNEL);
 
@@ -111,6 +112,11 @@ struct clk *clk_register_mux(struct device *dev, const char *name,
 	mux->flags = clk_mux_flags;
 	mux->lock = lock;
 
-	return clk_register(dev, name, &clk_mux_ops, &mux->hw,
+	clk = clk_register(dev, name, &clk_mux_ops, &mux->hw,
 			parent_names, num_parents, flags);
+	if (clk)
+		return clk;
+
+	kfree(mux);
+	return NULL;
 }
-- 
1.7.9

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] clk: Fix error handling paths of all basic clock register() routines
  2012-04-10  3:54 [PATCH] clk: Fix error handling paths of all basic clock register() routines Viresh Kumar
@ 2012-05-01 22:48 ` Mike Turquette
  2012-05-02  3:25   ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Turquette @ 2012-05-01 22:48 UTC (permalink / raw)
  To: linux-arm-kernel

On 20120410-09:24, Viresh Kumar wrote:
> This fixes following in error handling paths of register() routines of all basic
> clock types:
> - Free memory for clock type, allocated with kmalloc or kzalloc if
>   clk_register() fails.
> - No, need to free memory for clock type, if allocation fails for it.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
> ---
>  drivers/clk/clk-divider.c      |    2 +-
>  drivers/clk/clk-fixed-factor.c |    2 +-
>  drivers/clk/clk-fixed-rate.c   |   25 ++++++++++++++++++++-----
>  drivers/clk/clk-gate.c         |    2 +-
>  drivers/clk/clk-mux.c          |    8 +++++++-
>  5 files changed, 30 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index d5ac6a7..68158ce 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -192,8 +192,8 @@ struct clk *clk_register_divider(struct device *dev, const char *name,
>  	if (clk)
>  		return clk;
>  
> -out:
>  	kfree(div->parent[0]);
> +out:
>  	kfree(div);
>  
>  	return NULL;

Hi Viresh,

My apologies for taking so long to get back to you on this.  This patch
completely fell through the cracks.

Anyways my clk-next branch refactored this code and does The Right Thing
now, so I won't be taking this patch.

Thanks,
Mike

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] clk: Fix error handling paths of all basic clock register() routines
  2012-05-01 22:48 ` Mike Turquette
@ 2012-05-02  3:25   ` Viresh Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2012-05-02  3:25 UTC (permalink / raw)
  To: linux-arm-kernel

On 5/2/2012 4:18 AM, Mike Turquette wrote:
> My apologies for taking so long to get back to you on this.  This patch
> completely fell through the cracks.
> 
> Anyways my clk-next branch refactored this code and does The Right Thing
> now, so I won't be taking this patch.

Ya i already knew this. Thats why didn't had it my last patchset.

-- 
viresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-02  3:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-10  3:54 [PATCH] clk: Fix error handling paths of all basic clock register() routines Viresh Kumar
2012-05-01 22:48 ` Mike Turquette
2012-05-02  3:25   ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).