clk: Fix error handling paths of all basic clock register() routines
PATCH 1/1 clk: Fix error handling paths of all basic clock register() routines
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.
--- 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(-)
drivers/clk/clk-divider.c +1 -1
@@ -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 ;
drivers/clk/clk-fixed-factor.c +1 -1
@@ -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 ;
drivers/clk/clk-fixed-rate.c +20 -5
@@ -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 ; }
drivers/clk/clk-gate.c +1 -1
@@ -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 ;
drivers/clk/clk-mux.c +7 -1
@@ -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 ; }
Signature · 1 line
1.7.9
PATCH 1/1 clk: Fix error handling paths of all basic clock register() routines
Quoted 20 lines · Viresh Kumar
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 ifclk_register()fails.
- No, need to free memory for clock type, if allocation fails for it.Signed-off-by Viresh Kumar <[email protected]>--- 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(-)drivers/clk/clk-divider.c +0
-0
drivers/clk/clk-divider.c struct clk *clk_register_divider(struct device *dev, const char *name, · line 199
Quoted 9 lines
drivers/clk/clk-divider.c +1
-1@@ -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
PATCH 1/1 clk: Fix error handling paths of all basic clock register() routines
Quoted 5 lines · Mike Turquette
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.
Signature · 1 line
viresh