clk: mediatek: Provide mtk_devm_alloc_clk_data
authorMarkus Schneider-Pargmann <msp@baylibre.com>
Mon, 22 Aug 2022 15:26:50 +0000 (17:26 +0200)
committerStephen Boyd <sboyd@kernel.org>
Fri, 30 Sep 2022 22:07:43 +0000 (15:07 -0700)
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>
drivers/clk/mediatek/clk-mtk.c
drivers/clk/mediatek/clk-mtk.h

index a8ae65302837c944bdace87025f128bd8f49c77b..105fec8f49351750a59f6e4bef8ce410a77cec24 100644 (file)
 #include "clk-mtk.h"
 #include "clk-gate.h"
 
-struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num)
+static void mtk_init_clk_data(struct clk_hw_onecell_data *clk_data,
+                             unsigned int clk_num)
 {
        int i;
+
+       clk_data->num = clk_num;
+
+       for (i = 0; i < clk_num; i++)
+               clk_data->hws[i] = ERR_PTR(-ENOENT);
+}
+
+struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
+                                                   unsigned int clk_num)
+{
        struct clk_hw_onecell_data *clk_data;
 
-       clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL);
+       clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num),
+                               GFP_KERNEL);
        if (!clk_data)
                return NULL;
 
-       clk_data->num = clk_num;
+       mtk_init_clk_data(clk_data, clk_num);
 
-       for (i = 0; i < clk_num; i++)
-               clk_data->hws[i] = ERR_PTR(-ENOENT);
+       return clk_data;
+}
+EXPORT_SYMBOL_GPL(mtk_devm_alloc_clk_data);
+
+struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num)
+{
+       struct clk_hw_onecell_data *clk_data;
+
+       clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL);
+       if (!clk_data)
+               return NULL;
+
+       mtk_init_clk_data(clk_data, clk_num);
 
        return clk_data;
 }
index 62d650045cbaf6334bf2c6f35711f756f5a5922b..63ae7941aa92f10c03483f288ab352aed44637ee 100644 (file)
@@ -184,6 +184,8 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
                                 struct clk_hw_onecell_data *clk_data);
 
 struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
+struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
+                                                   unsigned int clk_num);
 void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
 
 struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,