Skip to contentSkip to conversation

clk: meson: probe clean-ups

PATCH In review Jerome Brunet 2 participants 5 messages Jan 18, 2018

Subsystems (3)
lore
Share & tools
lore

Jerome Brunet

author maintainer
#0 lore raw

cover clk: meson: probe clean-ups

This changeset feature a couple of clean-ups in the probe function of meson's clock controllers. It is the beginning of a refactoring of meson's clock controllers

Jerome Brunet (2):
clk: meson: use dev pointer where possible
clk: meson: use devm_of_clk_add_hw_provider

 drivers/clk/meson/axg.c     | 12 ++++++------
 drivers/clk/meson/gxbb.c    |  7 ++++---
 drivers/clk/meson/meson8b.c |  4 ++--
 3 files changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
2.14.3
author maintainer
#1 lore raw

PATCH 1/2 clk: meson: use dev pointer where possible

The 'dev' pointer is directly available in gxbb and axg clock controller, so consistently use it instead of going the through the 'pdev' pointer once in while

---
 drivers/clk/meson/axg.c  | 8 ++++----
 drivers/clk/meson/gxbb.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/clk/meson/axg.c +4 -4
index 1294f3ad7cd5..87aba8e871a0 100644
@@ -873,7 +873,7 @@ static int axg_clkc_probe(struct platform_device *pdev)
 	void __iomem *clk_base;
 	int ret, clkid, i;
 
-	clkc_data = of_device_get_match_data(&pdev->dev);
+	clkc_data = of_device_get_match_data(dev);
 	if (!clkc_data)
 		return -EINVAL;
 
@@ -881,9 +881,9 @@ static int axg_clkc_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -EINVAL;
-	clk_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	clk_base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!clk_base) {
-		dev_err(&pdev->dev, "Unable to map clk base\n");
+		dev_err(dev, "Unable to map clk base\n");
 		return -ENXIO;
 	}
 
@@ -918,7 +918,7 @@ static int axg_clkc_probe(struct platform_device *pdev)
 		ret = devm_clk_hw_register(dev,
 					clkc_data->hw_onecell_data->hws[clkid]);
 		if (ret) {
-			dev_err(&pdev->dev, "Clock registration failed\n");
+			dev_err(dev, "Clock registration failed\n");
 			return ret;
 		}
 	}
drivers/clk/meson/gxbb.c +1 -1
index af24455af5b4..ba1023983d79 100644
@@ -1976,7 +1976,7 @@ static int gxbb_clkc_probe(struct platform_device *pdev)
 	int ret, clkid, i;
 	struct device *dev = &pdev->dev;
 
-	clkc_data = of_device_get_match_data(&pdev->dev);
+	clkc_data = of_device_get_match_data(dev);
 	if (!clkc_data)
 		return -EINVAL;
 
Signature · 1 line
2.14.3
author maintainer
#3 lore raw

PATCH 2/2 clk: meson: use devm_of_clk_add_hw_provider

In reply to Jerome Brunet

There is no remove callbacks in meson's clock controllers and of_clk_del_provider is never called if of_clk_add_hw_provider has been executed, introducing a potential memory leak.
Fixing this by the using the devm variant.

In reality, the leak would never happen since these controllers are never unloaded once in use ... still, this is worth cleaning.

---
 drivers/clk/meson/axg.c     | 4 ++--
 drivers/clk/meson/gxbb.c    | 5 +++--
 drivers/clk/meson/meson8b.c | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/clk/meson/axg.c +2 -2
index 87aba8e871a0..02f4401d7bc3 100644
@@ -923,8 +923,8 @@ static int axg_clkc_probe(struct platform_device *pdev)
 		}
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			clkc_data->hw_onecell_data);
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   clkc_data->hw_onecell_data);
 }
 
 static struct platform_driver axg_driver = {
drivers/clk/meson/gxbb.c +3 -2
index ba1023983d79..472a3cfbfbc5 100644
@@ -2028,8 +2028,9 @@ static int gxbb_clkc_probe(struct platform_device *pdev)
 			goto iounmap;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			clkc_data->hw_onecell_data);
+
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   clkc_data->hw_onecell_data);
 
 iounmap:
 	iounmap(clk_base);
drivers/clk/meson/meson8b.c +2 -2
index 3ffea80c1308..abac079ff77f 100644
@@ -878,8 +878,8 @@ static int meson8b_clkc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			&meson8b_hw_onecell_data);
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   &meson8b_hw_onecell_data);
 }
 
 static const struct of_device_id meson8b_clkc_match_table[] = {
Signature · 1 line
2.14.3
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] clk: meson: use devm_of_clk_add_hw_provider

Quoted 52 lines · Jerome Brunet

There is no remove callbacks in meson's clock controllers and of_clk_del_provider is never called if of_clk_add_hw_provider has been executed, introducing a potential memory leak.
Fixing this by the using the devm variant.

In reality, the leak would never happen since these controllers are never unloaded once in use ... still, this is worth cleaning.

---
 drivers/clk/meson/axg.c     | 4 ++--
 drivers/clk/meson/gxbb.c    | 5 +++--
 drivers/clk/meson/meson8b.c | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/clk/meson/axg.c +2 -2
index 87aba8e871a0..02f4401d7bc3 100644
@@ -923,8 +923,8 @@ static int axg_clkc_probe(struct platform_device *pdev)
 		}
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			clkc_data->hw_onecell_data);
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   clkc_data->hw_onecell_data);
 }
 
 static struct platform_driver axg_driver = {
drivers/clk/meson/gxbb.c +3 -2
index ba1023983d79..472a3cfbfbc5 100644
@@ -2028,8 +2028,9 @@ static int gxbb_clkc_probe(struct platform_device *pdev)
 			goto iounmap;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			clkc_data->hw_onecell_data);
+
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   clkc_data->hw_onecell_data);
 
 iounmap:
 	iounmap(clk_base);
drivers/clk/meson/meson8b.c +0 -0
index 3ffea80c1308..abac079ff77f 100644

drivers/clk/meson/meson8b.c static int meson8b_clkc_probe(struct platform_device *pdev) · line 885

Quoted 10 lines
drivers/clk/meson/meson8b.c +2 -2
@@ -878,8 +878,8 @@ static int meson8b_clkc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
-			&meson8b_hw_onecell_data);
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   &meson8b_hw_onecell_data);
 }
 
 static const struct of_device_id meson8b_clkc_match_table[] = {

Well devm is allocating a devm structure to unregister the clocks when removed, which will never happen so this allocation is useless.

Anyway it's cleaner if we do some other stuff after this call in the future.

Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] clk: meson: use dev pointer where possible

In reply to Jerome Brunet
Quoted 50 lines · Jerome Brunet

The 'dev' pointer is directly available in gxbb and axg clock controller, so consistently use it instead of going the through the 'pdev' pointer once in while

---
 drivers/clk/meson/axg.c  | 8 ++++----
 drivers/clk/meson/gxbb.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/clk/meson/axg.c +4 -4
index 1294f3ad7cd5..87aba8e871a0 100644
@@ -873,7 +873,7 @@ static int axg_clkc_probe(struct platform_device *pdev)
 	void __iomem *clk_base;
 	int ret, clkid, i;
 
-	clkc_data = of_device_get_match_data(&pdev->dev);
+	clkc_data = of_device_get_match_data(dev);
 	if (!clkc_data)
 		return -EINVAL;
 
@@ -881,9 +881,9 @@ static int axg_clkc_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -EINVAL;
-	clk_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	clk_base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!clk_base) {
-		dev_err(&pdev->dev, "Unable to map clk base\n");
+		dev_err(dev, "Unable to map clk base\n");
 		return -ENXIO;
 	}
 
@@ -918,7 +918,7 @@ static int axg_clkc_probe(struct platform_device *pdev)
 		ret = devm_clk_hw_register(dev,
 					clkc_data->hw_onecell_data->hws[clkid]);
 		if (ret) {
-			dev_err(&pdev->dev, "Clock registration failed\n");
+			dev_err(dev, "Clock registration failed\n");
 			return ret;
 		}
 	}
drivers/clk/meson/gxbb.c +0 -0
index af24455af5b4..ba1023983d79 100644

drivers/clk/meson/gxbb.c static int gxbb_clkc_probe(struct platform_device *pdev) · line 1982

Quoted 8 lines
drivers/clk/meson/gxbb.c +1 -1
@@ -1976,7 +1976,7 @@ static int gxbb_clkc_probe(struct platform_device *pdev)
 	int ret, clkid, i;
 	struct device *dev = &pdev->dev;
 
-	clkc_data = of_device_get_match_data(&pdev->dev);
+	clkc_data = of_device_get_match_data(dev);
 	if (!clkc_data)
 		return -EINVAL;