Linux-ARM-MSM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal
@ 2019-11-28 13:34 Georgi Djakov
  2019-11-28 13:34 ` [PATCH 2/5] interconnect: qcom: qcs404: " Georgi Djakov
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:34 UTC (permalink / raw)
  To: linux-pm
  Cc: bjorn.andersson, agross, digetx, evgreen, daidavid1, masneyb,
	sibis, linux-kernel, linux-arm-msm, georgi.djakov

As we will remove items off the list using list_del(), we need to use the
safe version of list_for_each_entry().

Fixes: b5d2f741077a ("interconnect: qcom: Add sdm845 interconnect provider driver")
Reported-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
---
 drivers/interconnect/qcom/sdm845.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/interconnect/qcom/sdm845.c b/drivers/interconnect/qcom/sdm845.c
index 502a6c22b41e..924c2d056d85 100644
--- a/drivers/interconnect/qcom/sdm845.c
+++ b/drivers/interconnect/qcom/sdm845.c
@@ -870,7 +870,7 @@ static int qnoc_remove(struct platform_device *pdev)
 	struct icc_provider *provider = &qp->provider;
 	struct icc_node *n;
 
-	list_for_each_entry(n, &provider->nodes, node_list) {
+	list_for_each_entry_safe(n, &provider->nodes, node_list) {
 		icc_node_del(n);
 		icc_node_destroy(n->id);
 	}

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

* [PATCH 2/5] interconnect: qcom: qcs404: Walk the list safely on node removal
  2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
@ 2019-11-28 13:34 ` " Georgi Djakov
  2019-11-28 13:34 ` [PATCH 3/5] interconnect: qcom: msm8974: " Georgi Djakov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:34 UTC (permalink / raw)
  To: linux-pm
  Cc: bjorn.andersson, agross, digetx, evgreen, daidavid1, masneyb,
	sibis, linux-kernel, linux-arm-msm, georgi.djakov

As we will remove items off the list using list_del(), we need to use the
safe version of list_for_each_entry().

Fixes: 5e4e6c4d3ae0 ("interconnect: qcom: Add QCS404 interconnect provider driver")
Reported-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
---
 drivers/interconnect/qcom/qcs404.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/interconnect/qcom/qcs404.c b/drivers/interconnect/qcom/qcs404.c
index b4966d8f3348..d2b455021416 100644
--- a/drivers/interconnect/qcom/qcs404.c
+++ b/drivers/interconnect/qcom/qcs404.c
@@ -494,7 +494,7 @@ static int qnoc_probe(struct platform_device *pdev)
 
 	return 0;
 err:
-	list_for_each_entry(node, &provider->nodes, node_list) {
+	list_for_each_entry_safe(node, &provider->nodes, node_list) {
 		icc_node_del(node);
 		icc_node_destroy(node->id);
 	}
@@ -510,7 +510,7 @@ static int qnoc_remove(struct platform_device *pdev)
 	struct icc_provider *provider = &qp->provider;
 	struct icc_node *n;
 
-	list_for_each_entry(n, &provider->nodes, node_list) {
+	list_for_each_entry_safe(n, &provider->nodes, node_list) {
 		icc_node_del(n);
 		icc_node_destroy(n->id);
 	}

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

* [PATCH 3/5] interconnect: qcom: msm8974: Walk the list safely on node removal
  2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
  2019-11-28 13:34 ` [PATCH 2/5] interconnect: qcom: qcs404: " Georgi Djakov
@ 2019-11-28 13:34 ` " Georgi Djakov
  2019-11-28 15:15   ` Brian Masney
  2019-11-28 13:34 ` [PATCH 4/5] interconnect: Add a common helper for removing all nodes Georgi Djakov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:34 UTC (permalink / raw)
  To: linux-pm
  Cc: bjorn.andersson, agross, digetx, evgreen, daidavid1, masneyb,
	sibis, linux-kernel, linux-arm-msm, georgi.djakov

As we will remove items off the list using list_del(), we need to use the
safe version of list_for_each_entry().

Fixes: 4e60a9568dc6 ("interconnect: qcom: add msm8974 driver")
Reported-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
---
 drivers/interconnect/qcom/msm8974.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/interconnect/qcom/msm8974.c b/drivers/interconnect/qcom/msm8974.c
index ce599a0c83d9..0a1a8ba6afa7 100644
--- a/drivers/interconnect/qcom/msm8974.c
+++ b/drivers/interconnect/qcom/msm8974.c
@@ -732,7 +732,7 @@ static int msm8974_icc_probe(struct platform_device *pdev)
 	return 0;
 
 err_del_icc:
-	list_for_each_entry(node, &provider->nodes, node_list) {
+	list_for_each_entry_safe(node, &provider->nodes, node_list) {
 		icc_node_del(node);
 		icc_node_destroy(node->id);
 	}
@@ -750,7 +750,7 @@ static int msm8974_icc_remove(struct platform_device *pdev)
 	struct icc_provider *provider = &qp->provider;
 	struct icc_node *n;
 
-	list_for_each_entry(n, &provider->nodes, node_list) {
+	list_for_each_entry_safe(n, &provider->nodes, node_list) {
 		icc_node_del(n);
 		icc_node_destroy(n->id);
 	}

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

* [PATCH 4/5] interconnect: Add a common helper for removing all nodes
  2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
  2019-11-28 13:34 ` [PATCH 2/5] interconnect: qcom: qcs404: " Georgi Djakov
  2019-11-28 13:34 ` [PATCH 3/5] interconnect: qcom: msm8974: " Georgi Djakov
@ 2019-11-28 13:34 ` Georgi Djakov
  2019-11-28 18:20   ` Bjorn Andersson
  2019-11-28 13:34 ` [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal Georgi Djakov
  2019-11-28 18:14 ` [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on " Bjorn Andersson
  4 siblings, 1 reply; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:34 UTC (permalink / raw)
  To: linux-pm
  Cc: bjorn.andersson, agross, digetx, evgreen, daidavid1, masneyb,
	sibis, linux-kernel, linux-arm-msm, georgi.djakov

The removal of all nodes from a provider seem to be a common functionality
for all existing users and it would make sense to factor out this into a
a common helper function.

Suggested-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
---
 drivers/interconnect/core.c           | 22 ++++++++++++++++++++++
 include/linux/interconnect-provider.h |  6 ++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c
index 467c539310f3..0e4852feb395 100644
--- a/drivers/interconnect/core.c
+++ b/drivers/interconnect/core.c
@@ -735,6 +735,28 @@ void icc_node_del(struct icc_node *node)
 }
 EXPORT_SYMBOL_GPL(icc_node_del);
 
+/**
+ * icc_nodes_remove() - remove all previously added nodes from provider
+ * @provider: the interconnect provider we are removing nodes from
+ *
+ * Return: 0 on success, or an error code otherwise
+ */
+int icc_nodes_remove(struct icc_provider *provider)
+{
+	struct icc_node *n, *tmp;
+
+	if (WARN_ON(IS_ERR_OR_NULL(provider)))
+		return -EINVAL;
+
+	list_for_each_entry_safe_reverse(n, tmp, &provider->nodes, node_list) {
+		icc_node_del(n);
+		icc_node_destroy(n->id);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(icc_nodes_remove);
+
 /**
  * icc_provider_add() - add a new interconnect provider
  * @provider: the interconnect provider that will be added into topology
diff --git a/include/linux/interconnect-provider.h b/include/linux/interconnect-provider.h
index b16f9effa555..31440c921216 100644
--- a/include/linux/interconnect-provider.h
+++ b/include/linux/interconnect-provider.h
@@ -98,6 +98,7 @@ int icc_link_create(struct icc_node *node, const int dst_id);
 int icc_link_destroy(struct icc_node *src, struct icc_node *dst);
 void icc_node_add(struct icc_node *node, struct icc_provider *provider);
 void icc_node_del(struct icc_node *node);
+int icc_nodes_remove(struct icc_provider *provider);
 int icc_provider_add(struct icc_provider *provider);
 int icc_provider_del(struct icc_provider *provider);
 
@@ -130,6 +131,11 @@ void icc_node_del(struct icc_node *node)
 {
 }
 
+static inline int icc_nodes_remove(struct icc_provider *provider)
+{
+	return -ENOTSUPP;
+}
+
 static inline int icc_provider_add(struct icc_provider *provider)
 {
 	return -ENOTSUPP;

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

* [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal
  2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
                   ` (2 preceding siblings ...)
  2019-11-28 13:34 ` [PATCH 4/5] interconnect: Add a common helper for removing all nodes Georgi Djakov
@ 2019-11-28 13:34 ` Georgi Djakov
  2019-11-28 13:43   ` Dmitry Osipenko
  2019-11-28 18:14 ` [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on " Bjorn Andersson
  4 siblings, 1 reply; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:34 UTC (permalink / raw)
  To: linux-pm
  Cc: bjorn.andersson, agross, digetx, evgreen, daidavid1, masneyb,
	sibis, linux-kernel, linux-arm-msm, georgi.djakov

There is a new helper function for removing all nodes. Let's use it instead
of duplicating the code.

In addition to the above, instead of duplicating the code, simplify the
probe function error path by calling driver removal function directly.

Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
---
 drivers/interconnect/qcom/msm8974.c | 40 ++++++++++-------------------
 drivers/interconnect/qcom/qcs404.c  | 31 ++++++++--------------
 drivers/interconnect/qcom/sdm845.c  | 29 +++++++--------------
 3 files changed, 33 insertions(+), 67 deletions(-)

diff --git a/drivers/interconnect/qcom/msm8974.c b/drivers/interconnect/qcom/msm8974.c
index 0a1a8ba6afa7..8823dce811c3 100644
--- a/drivers/interconnect/qcom/msm8974.c
+++ b/drivers/interconnect/qcom/msm8974.c
@@ -644,6 +644,15 @@ static int msm8974_icc_set(struct icc_node *src, struct icc_node *dst)
 	return 0;
 }
 
+static int msm8974_icc_remove(struct platform_device *pdev)
+{
+	struct msm8974_icc_provider *qp = platform_get_drvdata(pdev);
+
+	icc_nodes_remove(&qp->provider);
+	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
+	return icc_provider_del(&qp->provider);
+}
+
 static int msm8974_icc_probe(struct platform_device *pdev)
 {
 	const struct msm8974_icc_desc *desc;
@@ -701,7 +710,8 @@ static int msm8974_icc_probe(struct platform_device *pdev)
 	ret = icc_provider_add(provider);
 	if (ret) {
 		dev_err(dev, "error adding interconnect provider: %d\n", ret);
-		goto err_disable_clks;
+		clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
+		return ret;
 	}
 
 	for (i = 0; i < num_nodes; i++) {
@@ -710,7 +720,7 @@ static int msm8974_icc_probe(struct platform_device *pdev)
 		node = icc_node_create(qnodes[i]->id);
 		if (IS_ERR(node)) {
 			ret = PTR_ERR(node);
-			goto err_del_icc;
+			goto err;
 		}
 
 		node->name = qnodes[i]->name;
@@ -731,34 +741,12 @@ static int msm8974_icc_probe(struct platform_device *pdev)
 
 	return 0;
 
-err_del_icc:
-	list_for_each_entry_safe(node, &provider->nodes, node_list) {
-		icc_node_del(node);
-		icc_node_destroy(node->id);
-	}
-	icc_provider_del(provider);
-
-err_disable_clks:
-	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
+err:
+	msm8974_icc_remove(pdev);
 
 	return ret;
 }
 
-static int msm8974_icc_remove(struct platform_device *pdev)
-{
-	struct msm8974_icc_provider *qp = platform_get_drvdata(pdev);
-	struct icc_provider *provider = &qp->provider;
-	struct icc_node *n;
-
-	list_for_each_entry_safe(n, &provider->nodes, node_list) {
-		icc_node_del(n);
-		icc_node_destroy(n->id);
-	}
-	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
-
-	return icc_provider_del(provider);
-}
-
 static const struct of_device_id msm8974_noc_of_match[] = {
 	{ .compatible = "qcom,msm8974-bimc", .data = &msm8974_bimc},
 	{ .compatible = "qcom,msm8974-cnoc", .data = &msm8974_cnoc},
diff --git a/drivers/interconnect/qcom/qcs404.c b/drivers/interconnect/qcom/qcs404.c
index d2b455021416..a4c6ba715f61 100644
--- a/drivers/interconnect/qcom/qcs404.c
+++ b/drivers/interconnect/qcom/qcs404.c
@@ -406,6 +406,15 @@ static int qcom_icc_set(struct icc_node *src, struct icc_node *dst)
 	return 0;
 }
 
+static int qnoc_remove(struct platform_device *pdev)
+{
+	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
+
+	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
+	icc_nodes_remove(&qp->provider);
+	return icc_provider_del(&qp->provider);
+}
+
 static int qnoc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -494,31 +503,11 @@ static int qnoc_probe(struct platform_device *pdev)
 
 	return 0;
 err:
-	list_for_each_entry_safe(node, &provider->nodes, node_list) {
-		icc_node_del(node);
-		icc_node_destroy(node->id);
-	}
-	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
-	icc_provider_del(provider);
+	qnoc_remove(pdev);
 
 	return ret;
 }
 
-static int qnoc_remove(struct platform_device *pdev)
-{
-	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
-	struct icc_provider *provider = &qp->provider;
-	struct icc_node *n;
-
-	list_for_each_entry_safe(n, &provider->nodes, node_list) {
-		icc_node_del(n);
-		icc_node_destroy(n->id);
-	}
-	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
-
-	return icc_provider_del(provider);
-}
-
 static const struct of_device_id qcs404_noc_of_match[] = {
 	{ .compatible = "qcom,qcs404-bimc", .data = &qcs404_bimc },
 	{ .compatible = "qcom,qcs404-pcnoc", .data = &qcs404_pcnoc },
diff --git a/drivers/interconnect/qcom/sdm845.c b/drivers/interconnect/qcom/sdm845.c
index 924c2d056d85..2b8f13e78471 100644
--- a/drivers/interconnect/qcom/sdm845.c
+++ b/drivers/interconnect/qcom/sdm845.c
@@ -768,6 +768,14 @@ static int cmp_vcd(const void *_l, const void *_r)
 		return 1;
 }
 
+static int qnoc_remove(struct platform_device *pdev)
+{
+	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
+
+	icc_nodes_remove(&qp->provider);
+	return icc_provider_del(&qp->provider);
+}
+
 static int qnoc_probe(struct platform_device *pdev)
 {
 	const struct qcom_icc_desc *desc;
@@ -855,29 +863,10 @@ static int qnoc_probe(struct platform_device *pdev)
 
 	return ret;
 err:
-	list_for_each_entry(node, &provider->nodes, node_list) {
-		icc_node_del(node);
-		icc_node_destroy(node->id);
-	}
-
-	icc_provider_del(provider);
+	qnoc_remove(pdev);
 	return ret;
 }
 
-static int qnoc_remove(struct platform_device *pdev)
-{
-	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
-	struct icc_provider *provider = &qp->provider;
-	struct icc_node *n;
-
-	list_for_each_entry_safe(n, &provider->nodes, node_list) {
-		icc_node_del(n);
-		icc_node_destroy(n->id);
-	}
-
-	return icc_provider_del(provider);
-}
-
 static const struct of_device_id qnoc_of_match[] = {
 	{ .compatible = "qcom,sdm845-rsc-hlos", .data = &sdm845_rsc_hlos },
 	{ },

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

* Re: [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal
  2019-11-28 13:34 ` [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal Georgi Djakov
@ 2019-11-28 13:43   ` Dmitry Osipenko
  2019-11-28 13:52     ` Georgi Djakov
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Osipenko @ 2019-11-28 13:43 UTC (permalink / raw)
  To: Georgi Djakov, linux-pm
  Cc: bjorn.andersson, agross, evgreen, daidavid1, masneyb, sibis,
	linux-kernel, linux-arm-msm

28.11.2019 16:34, Georgi Djakov пишет:
> There is a new helper function for removing all nodes. Let's use it instead
> of duplicating the code.
> 
> In addition to the above, instead of duplicating the code, simplify the
> probe function error path by calling driver removal function directly.
> 
> Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
> ---
>  drivers/interconnect/qcom/msm8974.c | 40 ++++++++++-------------------
>  drivers/interconnect/qcom/qcs404.c  | 31 ++++++++--------------
>  drivers/interconnect/qcom/sdm845.c  | 29 +++++++--------------
>  3 files changed, 33 insertions(+), 67 deletions(-)
> 
> diff --git a/drivers/interconnect/qcom/msm8974.c b/drivers/interconnect/qcom/msm8974.c
> index 0a1a8ba6afa7..8823dce811c3 100644
> --- a/drivers/interconnect/qcom/msm8974.c
> +++ b/drivers/interconnect/qcom/msm8974.c
> @@ -644,6 +644,15 @@ static int msm8974_icc_set(struct icc_node *src, struct icc_node *dst)
>  	return 0;
>  }
>  
> +static int msm8974_icc_remove(struct platform_device *pdev)
> +{
> +	struct msm8974_icc_provider *qp = platform_get_drvdata(pdev);
> +
> +	icc_nodes_remove(&qp->provider);
> +	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> +	return icc_provider_del(&qp->provider);
> +}
> +
>  static int msm8974_icc_probe(struct platform_device *pdev)
>  {
>  	const struct msm8974_icc_desc *desc;
> @@ -701,7 +710,8 @@ static int msm8974_icc_probe(struct platform_device *pdev)
>  	ret = icc_provider_add(provider);
>  	if (ret) {
>  		dev_err(dev, "error adding interconnect provider: %d\n", ret);
> -		goto err_disable_clks;
> +		clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> +		return ret;
>  	}
>  
>  	for (i = 0; i < num_nodes; i++) {
> @@ -710,7 +720,7 @@ static int msm8974_icc_probe(struct platform_device *pdev)
>  		node = icc_node_create(qnodes[i]->id);
>  		if (IS_ERR(node)) {
>  			ret = PTR_ERR(node);
> -			goto err_del_icc;
> +			goto err;
>  		}
>  
>  		node->name = qnodes[i]->name;
> @@ -731,34 +741,12 @@ static int msm8974_icc_probe(struct platform_device *pdev)
>  
>  	return 0;
>  
> -err_del_icc:
> -	list_for_each_entry_safe(node, &provider->nodes, node_list) {
> -		icc_node_del(node);
> -		icc_node_destroy(node->id);
> -	}
> -	icc_provider_del(provider);
> -
> -err_disable_clks:
> -	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> +err:
> +	msm8974_icc_remove(pdev);
>  
>  	return ret;
>  }
>  
> -static int msm8974_icc_remove(struct platform_device *pdev)
> -{
> -	struct msm8974_icc_provider *qp = platform_get_drvdata(pdev);
> -	struct icc_provider *provider = &qp->provider;
> -	struct icc_node *n;
> -
> -	list_for_each_entry_safe(n, &provider->nodes, node_list) {
> -		icc_node_del(n);
> -		icc_node_destroy(n->id);
> -	}
> -	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> -
> -	return icc_provider_del(provider);
> -}
> -
>  static const struct of_device_id msm8974_noc_of_match[] = {
>  	{ .compatible = "qcom,msm8974-bimc", .data = &msm8974_bimc},
>  	{ .compatible = "qcom,msm8974-cnoc", .data = &msm8974_cnoc},
> diff --git a/drivers/interconnect/qcom/qcs404.c b/drivers/interconnect/qcom/qcs404.c
> index d2b455021416..a4c6ba715f61 100644
> --- a/drivers/interconnect/qcom/qcs404.c
> +++ b/drivers/interconnect/qcom/qcs404.c
> @@ -406,6 +406,15 @@ static int qcom_icc_set(struct icc_node *src, struct icc_node *dst)
>  	return 0;
>  }
>  
> +static int qnoc_remove(struct platform_device *pdev)
> +{
> +	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
> +
> +	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> +	icc_nodes_remove(&qp->provider);
> +	return icc_provider_del(&qp->provider);
> +}
> +
>  static int qnoc_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -494,31 +503,11 @@ static int qnoc_probe(struct platform_device *pdev)
>  
>  	return 0;
>  err:
> -	list_for_each_entry_safe(node, &provider->nodes, node_list) {
> -		icc_node_del(node);
> -		icc_node_destroy(node->id);
> -	}
> -	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> -	icc_provider_del(provider);
> +	qnoc_remove(pdev);
>  
>  	return ret;
>  }
>  
> -static int qnoc_remove(struct platform_device *pdev)
> -{
> -	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
> -	struct icc_provider *provider = &qp->provider;
> -	struct icc_node *n;
> -
> -	list_for_each_entry_safe(n, &provider->nodes, node_list) {
> -		icc_node_del(n);
> -		icc_node_destroy(n->id);
> -	}
> -	clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks);
> -
> -	return icc_provider_del(provider);
> -}
> -
>  static const struct of_device_id qcs404_noc_of_match[] = {
>  	{ .compatible = "qcom,qcs404-bimc", .data = &qcs404_bimc },
>  	{ .compatible = "qcom,qcs404-pcnoc", .data = &qcs404_pcnoc },
> diff --git a/drivers/interconnect/qcom/sdm845.c b/drivers/interconnect/qcom/sdm845.c
> index 924c2d056d85..2b8f13e78471 100644
> --- a/drivers/interconnect/qcom/sdm845.c
> +++ b/drivers/interconnect/qcom/sdm845.c
> @@ -768,6 +768,14 @@ static int cmp_vcd(const void *_l, const void *_r)
>  		return 1;
>  }
>  
> +static int qnoc_remove(struct platform_device *pdev)
> +{
> +	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
> +
> +	icc_nodes_remove(&qp->provider);
> +	return icc_provider_del(&qp->provider);
> +}
> +
>  static int qnoc_probe(struct platform_device *pdev)
>  {
>  	const struct qcom_icc_desc *desc;
> @@ -855,29 +863,10 @@ static int qnoc_probe(struct platform_device *pdev)
>  
>  	return ret;
>  err:
> -	list_for_each_entry(node, &provider->nodes, node_list) {
> -		icc_node_del(node);
> -		icc_node_destroy(node->id);
> -	}
> -
> -	icc_provider_del(provider);
> +	qnoc_remove(pdev);

This is wrong because platform_set_drvdata() is invoked at the end of
qnoc_probe(), thus platform_get_drvdata() of qnoc_remove() returns NULL
here.

>  	return ret;
>  }
>  
> -static int qnoc_remove(struct platform_device *pdev)
> -{
> -	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
> -	struct icc_provider *provider = &qp->provider;
> -	struct icc_node *n;
> -
> -	list_for_each_entry_safe(n, &provider->nodes, node_list) {
> -		icc_node_del(n);
> -		icc_node_destroy(n->id);
> -	}
> -
> -	return icc_provider_del(provider);
> -}
> -
>  static const struct of_device_id qnoc_of_match[] = {
>  	{ .compatible = "qcom,sdm845-rsc-hlos", .data = &sdm845_rsc_hlos },
>  	{ },
> 


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

* Re: [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal
  2019-11-28 13:43   ` Dmitry Osipenko
@ 2019-11-28 13:52     ` Georgi Djakov
  0 siblings, 0 replies; 10+ messages in thread
From: Georgi Djakov @ 2019-11-28 13:52 UTC (permalink / raw)
  To: Dmitry Osipenko, linux-pm
  Cc: bjorn.andersson, agross, evgreen, daidavid1, masneyb, sibis,
	linux-kernel, linux-arm-msm

On 28.11.19 г. 15:43 ч., Dmitry Osipenko wrote:
> 28.11.2019 16:34, Georgi Djakov пишет:
>> There is a new helper function for removing all nodes. Let's use it instead
>> of duplicating the code.
>>
>> In addition to the above, instead of duplicating the code, simplify the
>> probe function error path by calling driver removal function directly.
>>
>> Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
>> ---
>>   drivers/interconnect/qcom/msm8974.c | 40 ++++++++++-------------------
>>   drivers/interconnect/qcom/qcs404.c  | 31 ++++++++--------------
>>   drivers/interconnect/qcom/sdm845.c  | 29 +++++++--------------
>>   3 files changed, 33 insertions(+), 67 deletions(-)
>>
[..]>> +static int qnoc_remove(struct platform_device *pdev)
>> +{
>> +	struct qcom_icc_provider *qp = platform_get_drvdata(pdev);
>> +
>> +	icc_nodes_remove(&qp->provider);
>> +	return icc_provider_del(&qp->provider);
>> +}
>> +
>>   static int qnoc_probe(struct platform_device *pdev)
>>   {
>>   	const struct qcom_icc_desc *desc;
>> @@ -855,29 +863,10 @@ static int qnoc_probe(struct platform_device *pdev)
>>   
>>   	return ret;
>>   err:
>> -	list_for_each_entry(node, &provider->nodes, node_list) {
>> -		icc_node_del(node);
>> -		icc_node_destroy(node->id);
>> -	}
>> -
>> -	icc_provider_del(provider);
>> +	qnoc_remove(pdev);
> 
> This is wrong because platform_set_drvdata() is invoked at the end of
> qnoc_probe(), thus platform_get_drvdata() of qnoc_remove() returns NULL
> here.

True! Will fix it! Thank you!

BR,
Georgi

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

* Re: [PATCH 3/5] interconnect: qcom: msm8974: Walk the list safely on node removal
  2019-11-28 13:34 ` [PATCH 3/5] interconnect: qcom: msm8974: " Georgi Djakov
@ 2019-11-28 15:15   ` Brian Masney
  0 siblings, 0 replies; 10+ messages in thread
From: Brian Masney @ 2019-11-28 15:15 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: linux-pm, bjorn.andersson, agross, digetx, evgreen, daidavid1,
	sibis, linux-kernel, linux-arm-msm

On Thu, Nov 28, 2019 at 03:34:33PM +0200, Georgi Djakov wrote:
> As we will remove items off the list using list_del(), we need to use the
> safe version of list_for_each_entry().
> 
> Fixes: 4e60a9568dc6 ("interconnect: qcom: add msm8974 driver")
> Reported-by: Dmitry Osipenko <digetx@gmail.com>
> Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>

Reviewed-by: Brian Masney <masneyb@onstation.org>

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

* Re: [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal
  2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
                   ` (3 preceding siblings ...)
  2019-11-28 13:34 ` [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal Georgi Djakov
@ 2019-11-28 18:14 ` " Bjorn Andersson
  4 siblings, 0 replies; 10+ messages in thread
From: Bjorn Andersson @ 2019-11-28 18:14 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: linux-pm, agross, digetx, evgreen, daidavid1, masneyb, sibis,
	linux-kernel, linux-arm-msm

On Thu 28 Nov 05:34 PST 2019, Georgi Djakov wrote:

> As we will remove items off the list using list_del(), we need to use the
> safe version of list_for_each_entry().
> 
> Fixes: b5d2f741077a ("interconnect: qcom: Add sdm845 interconnect provider driver")
> Reported-by: Dmitry Osipenko <digetx@gmail.com>
> Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
> ---
>  drivers/interconnect/qcom/sdm845.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/interconnect/qcom/sdm845.c b/drivers/interconnect/qcom/sdm845.c
> index 502a6c22b41e..924c2d056d85 100644
> --- a/drivers/interconnect/qcom/sdm845.c
> +++ b/drivers/interconnect/qcom/sdm845.c
> @@ -870,7 +870,7 @@ static int qnoc_remove(struct platform_device *pdev)
>  	struct icc_provider *provider = &qp->provider;
>  	struct icc_node *n;
>  
> -	list_for_each_entry(n, &provider->nodes, node_list) {
> +	list_for_each_entry_safe(n, &provider->nodes, node_list) {

This now takes 4 parameters, please update (same issue in next patch).

Regards,
Bjorn

>  		icc_node_del(n);
>  		icc_node_destroy(n->id);
>  	}

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

* Re: [PATCH 4/5] interconnect: Add a common helper for removing all nodes
  2019-11-28 13:34 ` [PATCH 4/5] interconnect: Add a common helper for removing all nodes Georgi Djakov
@ 2019-11-28 18:20   ` Bjorn Andersson
  0 siblings, 0 replies; 10+ messages in thread
From: Bjorn Andersson @ 2019-11-28 18:20 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: linux-pm, agross, digetx, evgreen, daidavid1, masneyb, sibis,
	linux-kernel, linux-arm-msm

On Thu 28 Nov 05:34 PST 2019, Georgi Djakov wrote:

> The removal of all nodes from a provider seem to be a common functionality
> for all existing users and it would make sense to factor out this into a
> a common helper function.
> 
> Suggested-by: Dmitry Osipenko <digetx@gmail.com>
> Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/interconnect/core.c           | 22 ++++++++++++++++++++++
>  include/linux/interconnect-provider.h |  6 ++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c
> index 467c539310f3..0e4852feb395 100644
> --- a/drivers/interconnect/core.c
> +++ b/drivers/interconnect/core.c
> @@ -735,6 +735,28 @@ void icc_node_del(struct icc_node *node)
>  }
>  EXPORT_SYMBOL_GPL(icc_node_del);
>  
> +/**
> + * icc_nodes_remove() - remove all previously added nodes from provider
> + * @provider: the interconnect provider we are removing nodes from
> + *
> + * Return: 0 on success, or an error code otherwise
> + */
> +int icc_nodes_remove(struct icc_provider *provider)
> +{
> +	struct icc_node *n, *tmp;
> +
> +	if (WARN_ON(IS_ERR_OR_NULL(provider)))
> +		return -EINVAL;
> +
> +	list_for_each_entry_safe_reverse(n, tmp, &provider->nodes, node_list) {
> +		icc_node_del(n);
> +		icc_node_destroy(n->id);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(icc_nodes_remove);
> +
>  /**
>   * icc_provider_add() - add a new interconnect provider
>   * @provider: the interconnect provider that will be added into topology
> diff --git a/include/linux/interconnect-provider.h b/include/linux/interconnect-provider.h
> index b16f9effa555..31440c921216 100644
> --- a/include/linux/interconnect-provider.h
> +++ b/include/linux/interconnect-provider.h
> @@ -98,6 +98,7 @@ int icc_link_create(struct icc_node *node, const int dst_id);
>  int icc_link_destroy(struct icc_node *src, struct icc_node *dst);
>  void icc_node_add(struct icc_node *node, struct icc_provider *provider);
>  void icc_node_del(struct icc_node *node);
> +int icc_nodes_remove(struct icc_provider *provider);
>  int icc_provider_add(struct icc_provider *provider);
>  int icc_provider_del(struct icc_provider *provider);
>  
> @@ -130,6 +131,11 @@ void icc_node_del(struct icc_node *node)
>  {
>  }
>  
> +static inline int icc_nodes_remove(struct icc_provider *provider)
> +{
> +	return -ENOTSUPP;
> +}
> +
>  static inline int icc_provider_add(struct icc_provider *provider)
>  {
>  	return -ENOTSUPP;

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

end of thread, back to index

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28 13:34 [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on node removal Georgi Djakov
2019-11-28 13:34 ` [PATCH 2/5] interconnect: qcom: qcs404: " Georgi Djakov
2019-11-28 13:34 ` [PATCH 3/5] interconnect: qcom: msm8974: " Georgi Djakov
2019-11-28 15:15   ` Brian Masney
2019-11-28 13:34 ` [PATCH 4/5] interconnect: Add a common helper for removing all nodes Georgi Djakov
2019-11-28 18:20   ` Bjorn Andersson
2019-11-28 13:34 ` [PATCH 5/5] interconnect: qcom: Use the new common helper for node removal Georgi Djakov
2019-11-28 13:43   ` Dmitry Osipenko
2019-11-28 13:52     ` Georgi Djakov
2019-11-28 18:14 ` [PATCH 1/5] interconnect: qcom: sdm845: Walk the list safely on " Bjorn Andersson

Linux-ARM-MSM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-msm/0 linux-arm-msm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-msm linux-arm-msm/ https://lore.kernel.org/linux-arm-msm \
		linux-arm-msm@vger.kernel.org
	public-inbox-index linux-arm-msm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-arm-msm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git