summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinh Nguyen <dinguyen@kernel.org>2018-05-02 09:28:32 -0500
committerStephen Boyd <sboyd@kernel.org>2018-05-15 14:54:52 -0700
commit1ace0dfd754feef171e9209c8266efb198f5c19c (patch)
treeabff2fc034e49b3f167d8e8c4d8456c32562b91a
parent60cc43fc888428bb2f18f08997432d426a243338 (diff)
downloadop-kernel-dev-1ace0dfd754feef171e9209c8266efb198f5c19c.zip
op-kernel-dev-1ace0dfd754feef171e9209c8266efb198f5c19c.tar.gz
clk: socfpga: stratix10: use platform driver APIs
Use platform driver APIs to map memory so that it will automatically free the memory in case of errors. Signed-off-by: Dinh Nguyen <dinguyen@kernel.org> [sboyd@kernel.org: Return -ENOMEM error pointers, check for error pointer at call site] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
-rw-r--r--drivers/clk/socfpga/clk-s10.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/drivers/clk/socfpga/clk-s10.c b/drivers/clk/socfpga/clk-s10.c
index 3a11c38..1ffe3f0 100644
--- a/drivers/clk/socfpga/clk-s10.c
+++ b/drivers/clk/socfpga/clk-s10.c
@@ -260,46 +260,45 @@ static int s10_clk_register_pll(const struct stratix10_pll_clock *clks,
return 0;
}
-static struct stratix10_clock_data *__socfpga_s10_clk_init(struct device_node *np,
+static struct stratix10_clock_data *__socfpga_s10_clk_init(struct platform_device *pdev,
int nr_clks)
{
+ struct device_node *np = pdev->dev.of_node;
+ struct device *dev = &pdev->dev;
struct stratix10_clock_data *clk_data;
struct clk **clk_table;
+ struct resource *res;
void __iomem *base;
- base = of_iomap(np, 0);
- if (!base) {
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(base)) {
pr_err("%s: failed to map clock registers\n", __func__);
- goto err;
+ return ERR_CAST(base);
}
- clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
+ clk_data = devm_kzalloc(dev, sizeof(*clk_data), GFP_KERNEL);
if (!clk_data)
- goto err;
+ return ERR_PTR(-ENOMEM);
clk_data->base = base;
- clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL);
+ clk_table = devm_kcalloc(dev, nr_clks, sizeof(*clk_table), GFP_KERNEL);
if (!clk_table)
- goto err_data;
+ return ERR_PTR(-ENOMEM);
clk_data->clk_data.clks = clk_table;
clk_data->clk_data.clk_num = nr_clks;
of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
return clk_data;
-
-err_data:
- kfree(clk_data);
-err:
- return NULL;
}
-static int s10_clkmgr_init(struct device_node *np)
+static int s10_clkmgr_init(struct platform_device *pdev)
{
struct stratix10_clock_data *clk_data;
- clk_data = __socfpga_s10_clk_init(np, STRATIX10_NUM_CLKS);
- if (!clk_data)
- return -ENOMEM;
+ clk_data = __socfpga_s10_clk_init(pdev, STRATIX10_NUM_CLKS);
+ if (IS_ERR(clk_data))
+ return PTR_ERR(clk_data);
s10_clk_register_pll(s10_pll_clks, ARRAY_SIZE(s10_pll_clks), clk_data);
@@ -317,11 +316,7 @@ static int s10_clkmgr_init(struct device_node *np)
static int s10_clkmgr_probe(struct platform_device *pdev)
{
- struct device_node *np = pdev->dev.of_node;
-
- s10_clkmgr_init(np);
-
- return 0;
+ return s10_clkmgr_init(pdev);
}
static const struct of_device_id stratix10_clkmgr_match_table[] = {
OpenPOWER on IntegriCloud