Skip to content

Commit 50e68b9

Browse files
scosubebarino
authored andcommitted
clk: mediatek: Provide mtk_devm_alloc_clk_data
Provide a helper that replaces the kzalloc with devm_kzalloc so error handling gets easier. Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> Link: https://lore.kernel.org/r/20220822152652.3499972-3-msp@baylibre.com Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent c619781 commit 50e68b9

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

drivers/clk/mediatek/clk-mtk.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,42 @@
1818
#include "clk-mtk.h"
1919
#include "clk-gate.h"
2020

21-
struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num)
21+
static void mtk_init_clk_data(struct clk_hw_onecell_data *clk_data,
22+
unsigned int clk_num)
2223
{
2324
int i;
25+
26+
clk_data->num = clk_num;
27+
28+
for (i = 0; i < clk_num; i++)
29+
clk_data->hws[i] = ERR_PTR(-ENOENT);
30+
}
31+
32+
struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
33+
unsigned int clk_num)
34+
{
2435
struct clk_hw_onecell_data *clk_data;
2536

26-
clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL);
37+
clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num),
38+
GFP_KERNEL);
2739
if (!clk_data)
2840
return NULL;
2941

30-
clk_data->num = clk_num;
42+
mtk_init_clk_data(clk_data, clk_num);
3143

32-
for (i = 0; i < clk_num; i++)
33-
clk_data->hws[i] = ERR_PTR(-ENOENT);
44+
return clk_data;
45+
}
46+
EXPORT_SYMBOL_GPL(mtk_devm_alloc_clk_data);
47+
48+
struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num)
49+
{
50+
struct clk_hw_onecell_data *clk_data;
51+
52+
clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL);
53+
if (!clk_data)
54+
return NULL;
55+
56+
mtk_init_clk_data(clk_data, clk_num);
3457

3558
return clk_data;
3659
}

drivers/clk/mediatek/clk-mtk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
184184
struct clk_hw_onecell_data *clk_data);
185185

186186
struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
187+
struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
188+
unsigned int clk_num);
187189
void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
188190

189191
struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,

0 commit comments

Comments
 (0)