Linux-remoteproc Archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string
@ 2024-08-02 18:22 Andrew Davis
  2024-08-02 18:22 ` [PATCH 2/7] remoteproc: keystone: Use devm_rproc_alloc() helper Andrew Davis
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

This is simpler and removes the need to assume the id length to be 1
digit, which then removes a W=1 compile warning about the same.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index 7e57b90bcaf85..81b179e269a1e 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -366,8 +366,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	struct rproc *rproc;
 	int dsp_id;
 	char *fw_name = NULL;
-	char *template = "keystone-dsp%d-fw";
-	int name_len = 0;
 	int ret = 0;
 
 	if (!np) {
@@ -382,11 +380,9 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	}
 
 	/* construct a custom default fw name - subject to change in future */
-	name_len = strlen(template); /* assuming a single digit alias */
-	fw_name = devm_kzalloc(dev, name_len, GFP_KERNEL);
+	fw_name = devm_kasprintf(dev, GFP_KERNEL, "keystone-dsp%d-fw", dsp_id);
 	if (!fw_name)
 		return -ENOMEM;
-	snprintf(fw_name, name_len, template, dsp_id);
 
 	rproc = rproc_alloc(dev, dev_name(dev), &keystone_rproc_ops, fw_name,
 			    sizeof(*ksproc));
-- 
2.39.2


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

* [PATCH 2/7] remoteproc: keystone: Use devm_rproc_alloc() helper
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
@ 2024-08-02 18:22 ` Andrew Davis
  2024-08-02 18:22 ` [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory Andrew Davis
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

Use the device lifecycle managed allocation function. This helps prevent
mistakes like freeing out of order in cleanup functions and forgetting to
free on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index 81b179e269a1e..8f0f7a4cfef26 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -384,8 +384,8 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	if (!fw_name)
 		return -ENOMEM;
 
-	rproc = rproc_alloc(dev, dev_name(dev), &keystone_rproc_ops, fw_name,
-			    sizeof(*ksproc));
+	rproc = devm_rproc_alloc(dev, dev_name(dev), &keystone_rproc_ops,
+				 fw_name, sizeof(*ksproc));
 	if (!rproc)
 		return -ENOMEM;
 
@@ -396,13 +396,11 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 
 	ret = keystone_rproc_of_get_dev_syscon(pdev, ksproc);
 	if (ret)
-		goto free_rproc;
+		return ret;
 
 	ksproc->reset = devm_reset_control_get_exclusive(dev, NULL);
-	if (IS_ERR(ksproc->reset)) {
-		ret = PTR_ERR(ksproc->reset);
-		goto free_rproc;
-	}
+	if (IS_ERR(ksproc->reset))
+		return PTR_ERR(ksproc->reset);
 
 	/* enable clock for accessing DSP internal memories */
 	pm_runtime_enable(dev);
@@ -467,8 +465,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	pm_runtime_put_sync(dev);
 disable_rpm:
 	pm_runtime_disable(dev);
-free_rproc:
-	rproc_free(rproc);
 	return ret;
 }
 
@@ -480,7 +476,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
 	gpiod_put(ksproc->kick_gpio);
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-	rproc_free(ksproc->rproc);
 	of_reserved_mem_device_release(&pdev->dev);
 }
 
-- 
2.39.2


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

* [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
  2024-08-02 18:22 ` [PATCH 2/7] remoteproc: keystone: Use devm_rproc_alloc() helper Andrew Davis
@ 2024-08-02 18:22 ` Andrew Davis
  2024-08-13 15:55   ` Mathieu Poirier
  2024-08-02 18:22 ` [PATCH 4/7] remoteproc: keystone: Use devm_pm_runtime_enable() helper Andrew Davis
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

This helps prevent mistakes like freeing out of order in cleanup functions
and forgetting to free on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index 8f0f7a4cfef26..033e573544fef 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -358,6 +358,13 @@ static int keystone_rproc_of_get_dev_syscon(struct platform_device *pdev,
 	return 0;
 }
 
+static void keystone_rproc_mem_release(void *data)
+{
+	struct device *dev = data;
+
+	of_reserved_mem_device_release(dev);
+}
+
 static int keystone_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -434,8 +441,14 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 		goto disable_clk;
 	}
 
-	if (of_reserved_mem_device_init(dev))
+	ret = of_reserved_mem_device_init(dev);
+	if (ret) {
 		dev_warn(dev, "device does not have specific CMA pool\n");
+	} else {
+		ret = devm_add_action_or_reset(dev, keystone_rproc_mem_release, dev);
+		if (ret)
+			return ret;
+	}
 
 	/* ensure the DSP is in reset before loading firmware */
 	ret = reset_control_status(ksproc->reset);
@@ -459,7 +472,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	return 0;
 
 release_mem:
-	of_reserved_mem_device_release(dev);
 	gpiod_put(ksproc->kick_gpio);
 disable_clk:
 	pm_runtime_put_sync(dev);
@@ -476,7 +488,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
 	gpiod_put(ksproc->kick_gpio);
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-	of_reserved_mem_device_release(&pdev->dev);
 }
 
 static const struct of_device_id keystone_rproc_of_match[] = {
-- 
2.39.2


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

* [PATCH 4/7] remoteproc: keystone: Use devm_pm_runtime_enable() helper
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
  2024-08-02 18:22 ` [PATCH 2/7] remoteproc: keystone: Use devm_rproc_alloc() helper Andrew Davis
  2024-08-02 18:22 ` [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory Andrew Davis
@ 2024-08-02 18:22 ` Andrew Davis
  2024-08-02 18:22 ` [PATCH 5/7] remoteproc: keystone: Use devm action to call PM runtime put sync Andrew Davis
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

Use device life-cycle managed runtime enable function to simplify probe
and exit paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index 033e573544fef..f457cadc1fae0 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -410,12 +410,13 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 		return PTR_ERR(ksproc->reset);
 
 	/* enable clock for accessing DSP internal memories */
-	pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to enable runtime PM\n");
+
 	ret = pm_runtime_resume_and_get(dev);
-	if (ret < 0) {
-		dev_err(dev, "failed to enable clock, status = %d\n", ret);
-		goto disable_rpm;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "failed to enable clock\n");
 
 	ret = keystone_rproc_of_get_memories(pdev, ksproc);
 	if (ret)
@@ -475,8 +476,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	gpiod_put(ksproc->kick_gpio);
 disable_clk:
 	pm_runtime_put_sync(dev);
-disable_rpm:
-	pm_runtime_disable(dev);
 	return ret;
 }
 
@@ -487,7 +486,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
 	rproc_del(ksproc->rproc);
 	gpiod_put(ksproc->kick_gpio);
 	pm_runtime_put_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
 }
 
 static const struct of_device_id keystone_rproc_of_match[] = {
-- 
2.39.2


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

* [PATCH 5/7] remoteproc: keystone: Use devm action to call PM runtime put sync
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
                   ` (2 preceding siblings ...)
  2024-08-02 18:22 ` [PATCH 4/7] remoteproc: keystone: Use devm_pm_runtime_enable() helper Andrew Davis
@ 2024-08-02 18:22 ` Andrew Davis
  2024-08-02 18:22 ` [PATCH 6/7] remoteproc: keystone: Use devm_gpiod_get() helper Andrew Davis
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

This helps prevent mistakes like putting out of order in cleanup functions
and forgetting to put sync on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 34 ++++++++++++------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index f457cadc1fae0..e65f99b1bf379 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -365,6 +365,13 @@ static void keystone_rproc_mem_release(void *data)
 	of_reserved_mem_device_release(dev);
 }
 
+static void keystone_rproc_pm_runtime_put(void *data)
+{
+	struct device *dev = data;
+
+	pm_runtime_put_sync(dev);
+}
+
 static int keystone_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -417,30 +424,26 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "failed to enable clock\n");
+	ret = devm_add_action_or_reset(dev, keystone_rproc_pm_runtime_put, dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to add disable pm devm action\n");
 
 	ret = keystone_rproc_of_get_memories(pdev, ksproc);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	ksproc->irq_ring = platform_get_irq_byname(pdev, "vring");
-	if (ksproc->irq_ring < 0) {
-		ret = ksproc->irq_ring;
-		goto disable_clk;
-	}
+	if (ksproc->irq_ring < 0)
+		return ksproc->irq_ring;
 
 	ksproc->irq_fault = platform_get_irq_byname(pdev, "exception");
-	if (ksproc->irq_fault < 0) {
-		ret = ksproc->irq_fault;
-		goto disable_clk;
-	}
+	if (ksproc->irq_fault < 0)
+		return ksproc->irq_fault;
 
 	ksproc->kick_gpio = gpiod_get(dev, "kick", GPIOD_ASIS);
 	ret = PTR_ERR_OR_ZERO(ksproc->kick_gpio);
-	if (ret) {
-		dev_err(dev, "failed to get gpio for virtio kicks, status = %d\n",
-			ret);
-		goto disable_clk;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to get gpio for virtio kicks\n");
 
 	ret = of_reserved_mem_device_init(dev);
 	if (ret) {
@@ -474,8 +477,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 
 release_mem:
 	gpiod_put(ksproc->kick_gpio);
-disable_clk:
-	pm_runtime_put_sync(dev);
 	return ret;
 }
 
@@ -485,7 +486,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
 
 	rproc_del(ksproc->rproc);
 	gpiod_put(ksproc->kick_gpio);
-	pm_runtime_put_sync(&pdev->dev);
 }
 
 static const struct of_device_id keystone_rproc_of_match[] = {
-- 
2.39.2


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

* [PATCH 6/7] remoteproc: keystone: Use devm_gpiod_get() helper
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
                   ` (3 preceding siblings ...)
  2024-08-02 18:22 ` [PATCH 5/7] remoteproc: keystone: Use devm action to call PM runtime put sync Andrew Davis
@ 2024-08-02 18:22 ` Andrew Davis
  2024-08-02 18:23 ` [PATCH 7/7] remoteproc: keystone: Use devm_rproc_add() helper Andrew Davis
  2024-08-08 11:34 ` [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Hari Nagalla
  6 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:22 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

Use device life-cycle managed GPIO get function to simplify probe
and exit paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index e65f99b1bf379..da5d5969829fb 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -440,7 +440,7 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	if (ksproc->irq_fault < 0)
 		return ksproc->irq_fault;
 
-	ksproc->kick_gpio = gpiod_get(dev, "kick", GPIOD_ASIS);
+	ksproc->kick_gpio = devm_gpiod_get(dev, "kick", GPIOD_ASIS);
 	ret = PTR_ERR_OR_ZERO(ksproc->kick_gpio);
 	if (ret)
 		return dev_err_probe(dev, ret, "failed to get gpio for virtio kicks\n");
@@ -457,27 +457,19 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 	/* ensure the DSP is in reset before loading firmware */
 	ret = reset_control_status(ksproc->reset);
 	if (ret < 0) {
-		dev_err(dev, "failed to get reset status, status = %d\n", ret);
-		goto release_mem;
+		return dev_err_probe(dev, ret, "failed to get reset status\n");
 	} else if (ret == 0) {
 		WARN(1, "device is not in reset\n");
 		keystone_rproc_dsp_reset(ksproc);
 	}
 
 	ret = rproc_add(rproc);
-	if (ret) {
-		dev_err(dev, "failed to add register device with remoteproc core, status = %d\n",
-			ret);
-		goto release_mem;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register device with remoteproc core\n");
 
 	platform_set_drvdata(pdev, ksproc);
 
 	return 0;
-
-release_mem:
-	gpiod_put(ksproc->kick_gpio);
-	return ret;
 }
 
 static void keystone_rproc_remove(struct platform_device *pdev)
@@ -485,7 +477,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
 	struct keystone_rproc *ksproc = platform_get_drvdata(pdev);
 
 	rproc_del(ksproc->rproc);
-	gpiod_put(ksproc->kick_gpio);
 }
 
 static const struct of_device_id keystone_rproc_of_match[] = {
-- 
2.39.2


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

* [PATCH 7/7] remoteproc: keystone: Use devm_rproc_add() helper
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
                   ` (4 preceding siblings ...)
  2024-08-02 18:22 ` [PATCH 6/7] remoteproc: keystone: Use devm_gpiod_get() helper Andrew Davis
@ 2024-08-02 18:23 ` Andrew Davis
  2024-08-08 11:34 ` [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Hari Nagalla
  6 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2024-08-02 18:23 UTC (permalink / raw)
  To: Hari Nagalla, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Andrew Davis

Use the device lifecycle managed add function. This helps prevent mistakes
like deleting out of order in cleanup functions and forgetting to delete
on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/remoteproc/keystone_remoteproc.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
index da5d5969829fb..27ebe6661b0b7 100644
--- a/drivers/remoteproc/keystone_remoteproc.c
+++ b/drivers/remoteproc/keystone_remoteproc.c
@@ -463,22 +463,13 @@ static int keystone_rproc_probe(struct platform_device *pdev)
 		keystone_rproc_dsp_reset(ksproc);
 	}
 
-	ret = rproc_add(rproc);
+	ret = devm_rproc_add(dev, rproc);
 	if (ret)
 		return dev_err_probe(dev, ret, "failed to register device with remoteproc core\n");
 
-	platform_set_drvdata(pdev, ksproc);
-
 	return 0;
 }
 
-static void keystone_rproc_remove(struct platform_device *pdev)
-{
-	struct keystone_rproc *ksproc = platform_get_drvdata(pdev);
-
-	rproc_del(ksproc->rproc);
-}
-
 static const struct of_device_id keystone_rproc_of_match[] = {
 	{ .compatible = "ti,k2hk-dsp", },
 	{ .compatible = "ti,k2l-dsp", },
@@ -490,7 +481,6 @@ MODULE_DEVICE_TABLE(of, keystone_rproc_of_match);
 
 static struct platform_driver keystone_rproc_driver = {
 	.probe	= keystone_rproc_probe,
-	.remove_new = keystone_rproc_remove,
 	.driver	= {
 		.name = "keystone-rproc",
 		.of_match_table = keystone_rproc_of_match,
-- 
2.39.2


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

* Re: [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string
  2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
                   ` (5 preceding siblings ...)
  2024-08-02 18:23 ` [PATCH 7/7] remoteproc: keystone: Use devm_rproc_add() helper Andrew Davis
@ 2024-08-08 11:34 ` Hari Nagalla
  6 siblings, 0 replies; 9+ messages in thread
From: Hari Nagalla @ 2024-08-08 11:34 UTC (permalink / raw)
  To: Andrew Davis, Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel

On 8/2/24 13:22, Andrew Davis wrote:
> This is simpler and removes the need to assume the id length to be 1
> digit, which then removes a W=1 compile warning about the same.
> 
> Signed-off-by: Andrew Davis <afd@ti.com>
Acked/Tested-by: Hari Nagalla <hnagalla@ti.com>
> ---
>   drivers/remoteproc/keystone_remoteproc.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
> index 7e57b90bcaf85..81b179e269a1e 100644
> --- a/drivers/remoteproc/keystone_remoteproc.c
> +++ b/drivers/remoteproc/keystone_remoteproc.c
> @@ -366,8 +366,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
>   	struct rproc *rproc;
>   	int dsp_id;
>   	char *fw_name = NULL;
> -	char *template = "keystone-dsp%d-fw";
> -	int name_len = 0;
>   	int ret = 0;
>   
>   	if (!np) {
> @@ -382,11 +380,9 @@ static int keystone_rproc_probe(struct platform_device *pdev)
>   	}
>   
>   	/* construct a custom default fw name - subject to change in future */
> -	name_len = strlen(template); /* assuming a single digit alias */
> -	fw_name = devm_kzalloc(dev, name_len, GFP_KERNEL);
> +	fw_name = devm_kasprintf(dev, GFP_KERNEL, "keystone-dsp%d-fw", dsp_id);
>   	if (!fw_name)
>   		return -ENOMEM;
> -	snprintf(fw_name, name_len, template, dsp_id);
>   
>   	rproc = rproc_alloc(dev, dev_name(dev), &keystone_rproc_ops, fw_name,
>   			    sizeof(*ksproc));


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

* Re: [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory
  2024-08-02 18:22 ` [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory Andrew Davis
@ 2024-08-13 15:55   ` Mathieu Poirier
  0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Poirier @ 2024-08-13 15:55 UTC (permalink / raw)
  To: Andrew Davis
  Cc: Hari Nagalla, Bjorn Andersson, linux-remoteproc, linux-kernel

On Fri, Aug 02, 2024 at 01:22:56PM -0500, Andrew Davis wrote:
> This helps prevent mistakes like freeing out of order in cleanup functions
> and forgetting to free on error paths.
> 
> Signed-off-by: Andrew Davis <afd@ti.com>
> ---
>  drivers/remoteproc/keystone_remoteproc.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c
> index 8f0f7a4cfef26..033e573544fef 100644
> --- a/drivers/remoteproc/keystone_remoteproc.c
> +++ b/drivers/remoteproc/keystone_remoteproc.c
> @@ -358,6 +358,13 @@ static int keystone_rproc_of_get_dev_syscon(struct platform_device *pdev,
>  	return 0;
>  }
>  
> +static void keystone_rproc_mem_release(void *data)
> +{
> +	struct device *dev = data;
> +
> +	of_reserved_mem_device_release(dev);
> +}
> +
>  static int keystone_rproc_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -434,8 +441,14 @@ static int keystone_rproc_probe(struct platform_device *pdev)
>  		goto disable_clk;
>  	}
>  
> -	if (of_reserved_mem_device_init(dev))
> +	ret = of_reserved_mem_device_init(dev);
> +	if (ret) {
>  		dev_warn(dev, "device does not have specific CMA pool\n");
> +	} else {
> +		ret = devm_add_action_or_reset(dev, keystone_rproc_mem_release, dev);
> +		if (ret)
> +			return ret;

It gets sorted out in the next patches but we still need to "goto disable_clk"
to avoid git-bisect problems.

I have applied the first two patches of this set so no need to resend them.

Thanks,
Mathieu

> +	}
>  
>  	/* ensure the DSP is in reset before loading firmware */
>  	ret = reset_control_status(ksproc->reset);
> @@ -459,7 +472,6 @@ static int keystone_rproc_probe(struct platform_device *pdev)
>  	return 0;
>  
>  release_mem:
> -	of_reserved_mem_device_release(dev);
>  	gpiod_put(ksproc->kick_gpio);
>  disable_clk:
>  	pm_runtime_put_sync(dev);
> @@ -476,7 +488,6 @@ static void keystone_rproc_remove(struct platform_device *pdev)
>  	gpiod_put(ksproc->kick_gpio);
>  	pm_runtime_put_sync(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
> -	of_reserved_mem_device_release(&pdev->dev);
>  }
>  
>  static const struct of_device_id keystone_rproc_of_match[] = {
> -- 
> 2.39.2
> 

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

end of thread, other threads:[~2024-08-13 15:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 18:22 [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Andrew Davis
2024-08-02 18:22 ` [PATCH 2/7] remoteproc: keystone: Use devm_rproc_alloc() helper Andrew Davis
2024-08-02 18:22 ` [PATCH 3/7] remoteproc: keystone: Use devm action to release reserved memory Andrew Davis
2024-08-13 15:55   ` Mathieu Poirier
2024-08-02 18:22 ` [PATCH 4/7] remoteproc: keystone: Use devm_pm_runtime_enable() helper Andrew Davis
2024-08-02 18:22 ` [PATCH 5/7] remoteproc: keystone: Use devm action to call PM runtime put sync Andrew Davis
2024-08-02 18:22 ` [PATCH 6/7] remoteproc: keystone: Use devm_gpiod_get() helper Andrew Davis
2024-08-02 18:23 ` [PATCH 7/7] remoteproc: keystone: Use devm_rproc_add() helper Andrew Davis
2024-08-08 11:34 ` [PATCH 1/7] remoteproc: keystone: Use devm_kasprintf() to build name string Hari Nagalla

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 read-only IMAP folder(s) and NNTP newsgroup(s).