linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs
@ 2018-05-02 14:28 Dinh Nguyen
  2018-05-02 14:28 ` [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver Dinh Nguyen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dinh Nguyen @ 2018-05-02 14:28 UTC (permalink / raw)
  To: linux-clk; +Cc: dinguyen, sboyd, mturquette, linux-kernel

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>
---
 drivers/clk/socfpga/clk-s10.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/clk/socfpga/clk-s10.c b/drivers/clk/socfpga/clk-s10.c
index 3a11c38..c788997 100644
--- a/drivers/clk/socfpga/clk-s10.c
+++ b/drivers/clk/socfpga/clk-s10.c
@@ -260,44 +260,43 @@ 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_CAST(clk_data);
 
 	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_CAST(clk_table);
 
 	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);
+	clk_data = __socfpga_s10_clk_init(pdev, STRATIX10_NUM_CLKS);
 	if (!clk_data)
 		return -ENOMEM;
 
@@ -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[] = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver
  2018-05-02 14:28 [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Dinh Nguyen
@ 2018-05-02 14:28 ` Dinh Nguyen
  2018-05-15 21:53   ` Stephen Boyd
  2018-05-15 21:53 ` [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Stephen Boyd
  2018-05-15 21:55 ` Stephen Boyd
  2 siblings, 1 reply; 5+ messages in thread
From: Dinh Nguyen @ 2018-05-02 14:28 UTC (permalink / raw)
  To: linux-clk; +Cc: dinguyen, sboyd, mturquette, linux-kernel

The Stratix10 clock driver is essential to system operation, so their
removal should never happen.

Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
---
 drivers/clk/socfpga/clk-s10.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/clk/socfpga/clk-s10.c b/drivers/clk/socfpga/clk-s10.c
index c788997..3c953ca 100644
--- a/drivers/clk/socfpga/clk-s10.c
+++ b/drivers/clk/socfpga/clk-s10.c
@@ -329,6 +329,7 @@ static struct platform_driver stratix10_clkmgr_driver = {
 	.probe		= s10_clkmgr_probe,
 	.driver		= {
 		.name	= "stratix10-clkmgr",
+		.suppress_bind_attrs = true,
 		.of_match_table = stratix10_clkmgr_match_table,
 	},
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs
  2018-05-02 14:28 [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Dinh Nguyen
  2018-05-02 14:28 ` [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver Dinh Nguyen
@ 2018-05-15 21:53 ` Stephen Boyd
  2018-05-15 21:55 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-05-15 21:53 UTC (permalink / raw)
  To: Dinh Nguyen, linux-clk; +Cc: dinguyen, mturquette, linux-kernel

Quoting Dinh Nguyen (2018-05-02 07:28:32)
> +       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_CAST(clk_data);

I had to make these ERR_PTR(-ENOMEM), but otherwise I applied this to
clk-next.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver
  2018-05-02 14:28 ` [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver Dinh Nguyen
@ 2018-05-15 21:53   ` Stephen Boyd
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-05-15 21:53 UTC (permalink / raw)
  To: Dinh Nguyen, linux-clk; +Cc: dinguyen, mturquette, linux-kernel

Quoting Dinh Nguyen (2018-05-02 07:28:33)
> The Stratix10 clock driver is essential to system operation, so their
> removal should never happen.
> 
> Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs
  2018-05-02 14:28 [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Dinh Nguyen
  2018-05-02 14:28 ` [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver Dinh Nguyen
  2018-05-15 21:53 ` [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Stephen Boyd
@ 2018-05-15 21:55 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-05-15 21:55 UTC (permalink / raw)
  To: Dinh Nguyen, linux-clk; +Cc: dinguyen, mturquette, linux-kernel

Quoting Dinh Nguyen (2018-05-02 07:28:32)
> -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);
> +       clk_data = __socfpga_s10_clk_init(pdev, STRATIX10_NUM_CLKS);
>         if (!clk_data)

And this needs to be updated to check for an error pointer, which I did.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-15 21:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 14:28 [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Dinh Nguyen
2018-05-02 14:28 ` [PATCH 2/2] clk: socfpga: stratix10: suppress unbinding platform's clock driver Dinh Nguyen
2018-05-15 21:53   ` Stephen Boyd
2018-05-15 21:53 ` [PATCH 1/2] clk: socfpga: stratix10: use platform driver APIs Stephen Boyd
2018-05-15 21:55 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).