[PATCH 0/2] reset: uniphier: follow-up fix, clean-up

STALE3663d

7 messages, 2 authors, 2016-08-24 · open the first message on its own page

[PATCH 0/2] reset: uniphier: follow-up fix, clean-up

From: Masahiro Yamada <hidden>
Date: 2016-08-24 06:39:34

Hi Philipp,

Here is two follow-up patches.
  - add missing static
  - use of_device_get_match_data() rather than of_match_node()
    for the probe clean-up

The initial commit of the driver is still on the top of
"reset/next" branch.

If possible, could you squash these two into the initial one?
Nobody would be bothered with this.



Masahiro Yamada (2):
  reset: uniphier: add static qualifier to probe function
  reset: uniphier: use of_device_get_match_data() to get matched data

 drivers/reset/reset-uniphier.c | 81 +++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 41 deletions(-)

-- 
1.9.1

[PATCH 1/2] reset: uniphier: add static qualifier to probe function

From: Masahiro Yamada <hidden>
Date: 2016-08-24 06:39:33

I missed this in the initial commit.

Signed-off-by: Masahiro Yamada <redacted>
---

 drivers/reset/reset-uniphier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 9de071f..41c62af 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -385,7 +385,7 @@ static const struct of_device_id uniphier_reset_match[] = {
 };
 MODULE_DEVICE_TABLE(of, uniphier_reset_match);
 
-int uniphier_reset_probe(struct platform_device *pdev)
+static int uniphier_reset_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	const struct of_device_id *match;
-- 
1.9.1

[PATCH 2/2] reset: uniphier: use of_device_get_match_data() to get matched data

From: Masahiro Yamada <hidden>
Date: 2016-08-24 06:39:36

Use of_device_get_match_data() instead of of_match_node().  With
this, we can retrieve the .data field of the OF match table more
easily.  No more need to define (or declare) the match table before
the probe callback.  I prefer to collect boilerplates at the bottom
of the file, so moved it below.

Signed-off-by: Masahiro Yamada <redacted>
---

 drivers/reset/reset-uniphier.c | 81 +++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 41c62af..9b3f2cd 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -16,6 +16,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset-controller.h>
@@ -285,6 +286,45 @@ static const struct reset_control_ops uniphier_reset_ops = {
 	.status = uniphier_reset_status,
 };
 
+static int uniphier_reset_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct uniphier_reset_priv *priv;
+	const struct uniphier_reset_data *p, *data;
+	struct regmap *regmap;
+	struct device_node *parent;
+	unsigned int nr_resets = 0;
+
+	data = of_device_get_match_data(dev);
+	WARN_ON(!data);
+
+	parent = of_get_parent(dev->of_node); /* parent should be syscon node */
+	regmap = syscon_node_to_regmap(parent);
+	of_node_put(parent);
+	if (IS_ERR(regmap)) {
+		dev_err(dev, "failed to get regmap (error %ld)\n",
+			PTR_ERR(regmap));
+		return PTR_ERR(regmap);
+	}
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	for (p = data; p->id != UNIPHIER_RESET_ID_END; p++)
+		nr_resets = max(nr_resets, p->id + 1);
+
+	priv->rcdev.ops = &uniphier_reset_ops;
+	priv->rcdev.owner = dev->driver->owner;
+	priv->rcdev.of_node = dev->of_node;
+	priv->rcdev.nr_resets = nr_resets;
+	priv->dev = dev;
+	priv->regmap = regmap;
+	priv->data = data;
+
+	return devm_reset_controller_register(&pdev->dev, &priv->rcdev);
+}
+
 static const struct of_device_id uniphier_reset_match[] = {
 	/* System reset */
 	{
@@ -385,47 +425,6 @@ static const struct of_device_id uniphier_reset_match[] = {
 };
 MODULE_DEVICE_TABLE(of, uniphier_reset_match);
 
-static int uniphier_reset_probe(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-	const struct of_device_id *match;
-	struct uniphier_reset_priv *priv;
-	const struct uniphier_reset_data *p;
-	struct regmap *regmap;
-	struct device_node *parent;
-	unsigned int nr_resets = 0;
-
-	match = of_match_node(uniphier_reset_match, pdev->dev.of_node);
-	if (!match)
-		return -ENODEV;
-
-	parent = of_get_parent(dev->of_node); /* parent should be syscon node */
-	regmap = syscon_node_to_regmap(parent);
-	of_node_put(parent);
-	if (IS_ERR(regmap)) {
-		dev_err(dev, "failed to get regmap (error %ld)\n",
-			PTR_ERR(regmap));
-		return PTR_ERR(regmap);
-	}
-
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-
-	for (p = match->data; p->id != UNIPHIER_RESET_ID_END; p++)
-		nr_resets = max(nr_resets, p->id + 1);
-
-	priv->rcdev.ops = &uniphier_reset_ops;
-	priv->rcdev.owner = dev->driver->owner;
-	priv->rcdev.of_node = dev->of_node;
-	priv->rcdev.nr_resets = nr_resets;
-	priv->dev = dev;
-	priv->regmap = regmap;
-	priv->data = match->data;
-
-	return devm_reset_controller_register(&pdev->dev, &priv->rcdev);
-}
-
 static struct platform_driver uniphier_reset_driver = {
 	.probe = uniphier_reset_probe,
 	.driver = {
-- 
1.9.1

Re: [PATCH 2/2] reset: uniphier: use of_device_get_match_data() to get matched data

From: Philipp Zabel <p.zabel@pengutronix.de>
Date: 2016-08-24 12:28:44

Hi Masahiro,

Am Mittwoch, den 24.08.2016, 15:40 +0900 schrieb Masahiro Yamada:
quoted hunk
Use of_device_get_match_data() instead of of_match_node().  With
this, we can retrieve the .data field of the OF match table more
easily.  No more need to define (or declare) the match table before
the probe callback.  I prefer to collect boilerplates at the bottom
of the file, so moved it below.

Signed-off-by: Masahiro Yamada <redacted>
---

 drivers/reset/reset-uniphier.c | 81 +++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 41c62af..9b3f2cd 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -16,6 +16,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset-controller.h>
@@ -285,6 +286,45 @@ static const struct reset_control_ops uniphier_reset_ops = {
 	.status = uniphier_reset_status,
 };
 
+static int uniphier_reset_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct uniphier_reset_priv *priv;
+	const struct uniphier_reset_data *p, *data;
+	struct regmap *regmap;
+	struct device_node *parent;
+	unsigned int nr_resets = 0;
+
+	data = of_device_get_match_data(dev);
+	WARN_ON(!data);
I know right now this can't happen anyway, but you did return -EINVAL
here before. Maybe use:

	if (WARN_ON(!data))
		return -EINVAL;

instead? I can fix it up if you agree.
+	parent = of_get_parent(dev->of_node); /* parent should be syscon node */
+	regmap = syscon_node_to_regmap(parent);
+	of_node_put(parent);
+	if (IS_ERR(regmap)) {
+		dev_err(dev, "failed to get regmap (error %ld)\n",
+			PTR_ERR(regmap));
+		return PTR_ERR(regmap);
+	}
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	for (p = data; p->id != UNIPHIER_RESET_ID_END; p++)
If in the future somebody forgets to set OF match data, this would be a
NULL pointer dereference.

regards
Philipp

Re: [PATCH 1/2] reset: uniphier: add static qualifier to probe function

From: Philipp Zabel <p.zabel@pengutronix.de>
Date: 2016-08-24 12:28:45

Am Mittwoch, den 24.08.2016, 15:40 +0900 schrieb Masahiro Yamada:
quoted hunk
I missed this in the initial commit.

Signed-off-by: Masahiro Yamada <redacted>
---

 drivers/reset/reset-uniphier.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 9de071f..41c62af 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -385,7 +385,7 @@ static const struct of_device_id uniphier_reset_match[] = {
 };
 MODULE_DEVICE_TABLE(of, uniphier_reset_match);
 
-int uniphier_reset_probe(struct platform_device *pdev)
+static int uniphier_reset_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	const struct of_device_id *match;
Thanks, I've squashed this into the original commit.

regards
Philipp

Re: [PATCH 2/2] reset: uniphier: use of_device_get_match_data() to get matched data

From: Masahiro Yamada <hidden>
Date: 2016-08-24 12:30:22

Hi Philipp,

2016-08-24 21:27 GMT+09:00 Philipp Zabel [off-list ref]:
Hi Masahiro,

Am Mittwoch, den 24.08.2016, 15:40 +0900 schrieb Masahiro Yamada:
quoted
Use of_device_get_match_data() instead of of_match_node().  With
this, we can retrieve the .data field of the OF match table more
easily.  No more need to define (or declare) the match table before
the probe callback.  I prefer to collect boilerplates at the bottom
of the file, so moved it below.

Signed-off-by: Masahiro Yamada <redacted>
---

 drivers/reset/reset-uniphier.c | 81 +++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 41c62af..9b3f2cd 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -16,6 +16,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset-controller.h>
@@ -285,6 +286,45 @@ static const struct reset_control_ops uniphier_reset_ops = {
      .status = uniphier_reset_status,
 };

+static int uniphier_reset_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct uniphier_reset_priv *priv;
+     const struct uniphier_reset_data *p, *data;
+     struct regmap *regmap;
+     struct device_node *parent;
+     unsigned int nr_resets = 0;
+
+     data = of_device_get_match_data(dev);
+     WARN_ON(!data);
I know right now this can't happen anyway, but you did return -EINVAL
here before. Maybe use:

        if (WARN_ON(!data))
                return -EINVAL;

instead? I can fix it up if you agree.
I agree.

Please fix it up.  Thanks!


-- 
Best Regards
Masahiro Yamada

Re: [PATCH 2/2] reset: uniphier: use of_device_get_match_data() to get matched data

From: Philipp Zabel <p.zabel@pengutronix.de>
Date: 2016-08-24 13:32:43

Am Mittwoch, den 24.08.2016, 21:29 +0900 schrieb Masahiro Yamada:
[...]
quoted
quoted
@@ -285,6 +286,45 @@ static const struct reset_control_ops uniphier_reset_ops = {
      .status = uniphier_reset_status,
 };

+static int uniphier_reset_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct uniphier_reset_priv *priv;
+     const struct uniphier_reset_data *p, *data;
+     struct regmap *regmap;
+     struct device_node *parent;
+     unsigned int nr_resets = 0;
+
+     data = of_device_get_match_data(dev);
+     WARN_ON(!data);
I know right now this can't happen anyway, but you did return -EINVAL
here before. Maybe use:

        if (WARN_ON(!data))
                return -EINVAL;

instead? I can fix it up if you agree.
I agree.

Please fix it up.  Thanks!
Ok, done.

regards
Philipp
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help