[v2] clk: ti: Fix error handling in ti_clk_parse_divider_data()
diff mbox series

Message ID 20190115194625.GA1074@kadam
State New
Headers show
Series
  • [v2] clk: ti: Fix error handling in ti_clk_parse_divider_data()
Related show

Commit Message

Dan Carpenter Jan. 15, 2019, 7:46 p.m. UTC
The ti_clk_parse_divider_data() function is only called from
_get_div_table_from_setup().  That function doesn't look at the return
value but instead looks at the "*table" pointer.  In this case, if the
kcalloc() fails then *table is NULL (which means success).  It should
instead be an error pointer.

The ti_clk_parse_divider_data() function has two callers.  One checks
for errors and the other doesn't.  I have fixed it so now both handle
errors.

Fixes: 4f6be5655dc9 ("clk: ti: divider: add driver internal API for parsing divider data")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2:  I somehow didn't compile the v1 of this patch so it had a couple
     stupid bugs.  I'm very sorry.

 drivers/clk/ti/divider.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Stephen Boyd Jan. 24, 2019, 7:24 p.m. UTC | #1
Quoting Dan Carpenter (2019-01-15 11:46:25)
> The ti_clk_parse_divider_data() function is only called from
> _get_div_table_from_setup().  That function doesn't look at the return
> value but instead looks at the "*table" pointer.  In this case, if the
> kcalloc() fails then *table is NULL (which means success).  It should
> instead be an error pointer.
> 
> The ti_clk_parse_divider_data() function has two callers.  One checks
> for errors and the other doesn't.  I have fixed it so now both handle
> errors.
> 
> Fixes: 4f6be5655dc9 ("clk: ti: divider: add driver internal API for parsing divider data")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---

Applied to clk-fixes

I'm going to add Tero's ack to this because it isn't really that
different.
Tero Kristo Jan. 24, 2019, 7:50 p.m. UTC | #2
On 24/01/2019 21:24, Stephen Boyd wrote:
> Quoting Dan Carpenter (2019-01-15 11:46:25)
>> The ti_clk_parse_divider_data() function is only called from
>> _get_div_table_from_setup().  That function doesn't look at the return
>> value but instead looks at the "*table" pointer.  In this case, if the
>> kcalloc() fails then *table is NULL (which means success).  It should
>> instead be an error pointer.
>>
>> The ti_clk_parse_divider_data() function has two callers.  One checks
>> for errors and the other doesn't.  I have fixed it so now both handle
>> errors.
>>
>> Fixes: 4f6be5655dc9 ("clk: ti: divider: add driver internal API for parsing divider data")
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>> ---
> 
> Applied to clk-fixes
> 
> I'm going to add Tero's ack to this because it isn't really that
> different.
> 

Yeah, thats ok. Thanks Stephen.

-Tero
--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Patch
diff mbox series

diff --git a/drivers/clk/ti/divider.c b/drivers/clk/ti/divider.c
index 8d77090ad94a..0241450f3eb3 100644
--- a/drivers/clk/ti/divider.c
+++ b/drivers/clk/ti/divider.c
@@ -403,8 +403,10 @@  int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
 	num_dividers = i;
 
 	tmp = kcalloc(valid_div + 1, sizeof(*tmp), GFP_KERNEL);
-	if (!tmp)
+	if (!tmp) {
+		*table = ERR_PTR(-ENOMEM);
 		return -ENOMEM;
+	}
 
 	valid_div = 0;
 	*width = 0;
@@ -439,6 +441,7 @@  struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
 {
 	struct clk_omap_divider *div;
 	struct clk_omap_reg *reg;
+	int ret;
 
 	if (!setup)
 		return NULL;
@@ -458,6 +461,12 @@  struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
 		div->flags |= CLK_DIVIDER_POWER_OF_TWO;
 
 	div->table = _get_div_table_from_setup(setup, &div->width);
+	if (IS_ERR(div->table)) {
+		ret = PTR_ERR(div->table);
+		kfree(div);
+		return ERR_PTR(ret);
+	}
+
 
 	div->shift = setup->bit_shift;
 	div->latch = -EINVAL;