]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.20.16/clk-ti-fix-error-handling-in-ti_clk_parse_divider_da.patch
Linux 4.20.16
[thirdparty/kernel/stable-queue.git] / releases / 4.20.16 / clk-ti-fix-error-handling-in-ti_clk_parse_divider_da.patch
1 From d17f298264024547963e4441c2d0d4df0f4f94ac Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Tue, 15 Jan 2019 22:46:25 +0300
4 Subject: clk: ti: Fix error handling in ti_clk_parse_divider_data()
5
6 [ Upstream commit 303aef8b84272d73999a3207dd05bbe10ed89dc5 ]
7
8 The ti_clk_parse_divider_data() function is only called from
9 _get_div_table_from_setup(). That function doesn't look at the return
10 value but instead looks at the "*table" pointer. In this case, if the
11 kcalloc() fails then *table is NULL (which means success). It should
12 instead be an error pointer.
13
14 The ti_clk_parse_divider_data() function has two callers. One checks
15 for errors and the other doesn't. I have fixed it so now both handle
16 errors.
17
18 Fixes: 4f6be5655dc9 ("clk: ti: divider: add driver internal API for parsing divider data")
19 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
20 Acked-by: Tero Kristo <t-kristo@ti.com>
21 Signed-off-by: Stephen Boyd <sboyd@kernel.org>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 ---
24 drivers/clk/ti/divider.c | 11 ++++++++++-
25 1 file changed, 10 insertions(+), 1 deletion(-)
26
27 diff --git a/drivers/clk/ti/divider.c b/drivers/clk/ti/divider.c
28 index 8d77090ad94a..0241450f3eb3 100644
29 --- a/drivers/clk/ti/divider.c
30 +++ b/drivers/clk/ti/divider.c
31 @@ -403,8 +403,10 @@ int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
32 num_dividers = i;
33
34 tmp = kcalloc(valid_div + 1, sizeof(*tmp), GFP_KERNEL);
35 - if (!tmp)
36 + if (!tmp) {
37 + *table = ERR_PTR(-ENOMEM);
38 return -ENOMEM;
39 + }
40
41 valid_div = 0;
42 *width = 0;
43 @@ -439,6 +441,7 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
44 {
45 struct clk_omap_divider *div;
46 struct clk_omap_reg *reg;
47 + int ret;
48
49 if (!setup)
50 return NULL;
51 @@ -458,6 +461,12 @@ struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup)
52 div->flags |= CLK_DIVIDER_POWER_OF_TWO;
53
54 div->table = _get_div_table_from_setup(setup, &div->width);
55 + if (IS_ERR(div->table)) {
56 + ret = PTR_ERR(div->table);
57 + kfree(div);
58 + return ERR_PTR(ret);
59 + }
60 +
61
62 div->shift = setup->bit_shift;
63 div->latch = -EINVAL;
64 --
65 2.19.1
66