2024-02-05 18:32:28

by Andrew Davis

[permalink] [raw]
Subject: [PATCH v2 0/5] K3 DSP Remoteproc remove cleanup

Hello all,

This series uses various devm_ helpers to simplify the device
removal path.

Removing an unused var "ret1" got squashed into the wrong patch in
the v1 series causing a bisectability error. v2 is based on -next
with the first 3 already taken. These are the last 5 patches of the
v1 series[0].

Thanks,
Andrew

[0] https://lore.kernel.org/lkml/[email protected]/T/

Andrew Davis (5):
remoteproc: k3-dsp: Use devm_ti_sci_get_by_phandle() helper
remoteproc: k3-dsp: Use devm_kzalloc() helper
remoteproc: k3-dsp: Add devm action to release tsp
remoteproc: k3-dsp: Use devm_ioremap_wc() helper
remoteproc: k3-dsp: Use devm_rproc_add() helper

drivers/remoteproc/ti_k3_dsp_remoteproc.c | 116 ++++++----------------
1 file changed, 32 insertions(+), 84 deletions(-)

--
2.39.2



2024-02-05 18:32:46

by Andrew Davis

[permalink] [raw]
Subject: [PATCH v2 3/5] remoteproc: k3-dsp: Add devm action to release tsp

Use a device lifecycle managed action to release tps ti_sci_proc handle.
This helps prevent mistakes like releasing out of order in cleanup
functions and forgetting to release on error paths.

Signed-off-by: Andrew Davis <[email protected]>
---
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 27 +++++++++++------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index b9332c66a52ab..800c8c6767086 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -646,6 +646,13 @@ static void k3_dsp_reserved_mem_exit(struct k3_dsp_rproc *kproc)
iounmap(kproc->rmem[i].cpu_addr);
}

+static void k3_dsp_release_tsp(void *data)
+{
+ struct ti_sci_proc *tsp = data;
+
+ ti_sci_proc_release(tsp);
+}
+
static
struct ti_sci_proc *k3_dsp_rproc_of_get_tsp(struct device *dev,
const struct ti_sci_handle *sci)
@@ -682,7 +689,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
const char *fw_name;
bool p_state = false;
int ret = 0;
- int ret1;

data = of_device_get_match_data(dev);
if (!data)
@@ -732,16 +738,17 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_err_probe(dev, ret, "ti_sci_proc_request failed\n");
return ret;
}
+ ret = devm_add_action_or_reset(dev, k3_dsp_release_tsp, kproc->tsp);
+ if (ret)
+ return ret;

ret = k3_dsp_rproc_of_get_memories(pdev, kproc);
if (ret)
- goto release_tsp;
+ return ret;

ret = k3_dsp_reserved_mem_init(kproc);
- if (ret) {
- dev_err_probe(dev, ret, "reserved memory init failed\n");
- goto release_tsp;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "reserved memory init failed\n");

ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id,
NULL, &p_state);
@@ -793,10 +800,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)

release_mem:
k3_dsp_reserved_mem_exit(kproc);
-release_tsp:
- ret1 = ti_sci_proc_release(kproc->tsp);
- if (ret1)
- dev_err(dev, "failed to release proc (%pe)\n", ERR_PTR(ret1));
return ret;
}

@@ -818,10 +821,6 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)

rproc_del(kproc->rproc);

- ret = ti_sci_proc_release(kproc->tsp);
- if (ret)
- dev_err(dev, "failed to release proc (%pe)\n", ERR_PTR(ret));
-
k3_dsp_reserved_mem_exit(kproc);
}

--
2.39.2


2024-02-05 18:32:50

by Andrew Davis

[permalink] [raw]
Subject: [PATCH v2 5/5] remoteproc: k3-dsp: Use devm_rproc_add() helper

Use device lifecycle managed devm_rproc_add() helper function. This helps
prevent mistakes like deleting out of order in cleanup functions and
forgetting to delete on all error paths.

Signed-off-by: Andrew Davis <[email protected]>
---
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index f799f74734b4a..3555b535b1683 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -768,7 +768,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
}
}

- ret = rproc_add(rproc);
+ ret = devm_rproc_add(dev, rproc);
if (ret)
return dev_err_probe(dev, ret, "failed to add register device with remoteproc core\n");

@@ -786,14 +786,9 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)

if (rproc->state == RPROC_ATTACHED) {
ret = rproc_detach(rproc);
- if (ret) {
- /* Note this error path leaks resources */
+ if (ret)
dev_err(dev, "failed to detach proc (%pe)\n", ERR_PTR(ret));
- return;
- }
}
-
- rproc_del(kproc->rproc);
}

static const struct k3_dsp_mem_data c66_mems[] = {
--
2.39.2


2024-02-05 18:41:42

by Andrew Davis

[permalink] [raw]
Subject: [PATCH v2 1/5] remoteproc: k3-dsp: Use devm_ti_sci_get_by_phandle() helper

Use the device lifecycle managed TI-SCI get() function. This helps prevent
mistakes like not put()'ing in the wrong order in cleanup functions and
forgetting to put() on error paths.

Signed-off-by: Andrew Davis <[email protected]>
---
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 32 +++++++----------------
1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index a13552c71f440..64ec5759c4ec1 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -708,30 +708,24 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
kproc->dev = dev;
kproc->data = data;

- kproc->ti_sci = ti_sci_get_by_phandle(np, "ti,sci");
+ kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci");
if (IS_ERR(kproc->ti_sci))
return dev_err_probe(dev, PTR_ERR(kproc->ti_sci),
"failed to get ti-sci handle\n");

ret = of_property_read_u32(np, "ti,sci-dev-id", &kproc->ti_sci_id);
- if (ret) {
- dev_err_probe(dev, ret, "missing 'ti,sci-dev-id' property\n");
- goto put_sci;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "missing 'ti,sci-dev-id' property\n");

kproc->reset = devm_reset_control_get_exclusive(dev, NULL);
- if (IS_ERR(kproc->reset)) {
- ret = dev_err_probe(dev, PTR_ERR(kproc->reset),
- "failed to get reset\n");
- goto put_sci;
- }
+ if (IS_ERR(kproc->reset))
+ return dev_err_probe(dev, PTR_ERR(kproc->reset),
+ "failed to get reset\n");

kproc->tsp = k3_dsp_rproc_of_get_tsp(dev, kproc->ti_sci);
- if (IS_ERR(kproc->tsp)) {
- ret = dev_err_probe(dev, PTR_ERR(kproc->tsp),
- "failed to construct ti-sci proc control\n");
- goto put_sci;
- }
+ if (IS_ERR(kproc->tsp))
+ return dev_err_probe(dev, PTR_ERR(kproc->tsp),
+ "failed to construct ti-sci proc control\n");

ret = ti_sci_proc_request(kproc->tsp);
if (ret < 0) {
@@ -805,10 +799,6 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_err(dev, "failed to release proc (%pe)\n", ERR_PTR(ret1));
free_tsp:
kfree(kproc->tsp);
-put_sci:
- ret1 = ti_sci_put_handle(kproc->ti_sci);
- if (ret1)
- dev_err(dev, "failed to put ti_sci handle (%pe)\n", ERR_PTR(ret1));
return ret;
}

@@ -836,10 +826,6 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)

kfree(kproc->tsp);

- ret = ti_sci_put_handle(kproc->ti_sci);
- if (ret)
- dev_err(dev, "failed to put ti_sci handle (%pe)\n", ERR_PTR(ret));
-
k3_dsp_reserved_mem_exit(kproc);
}

--
2.39.2


2024-02-05 21:52:27

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] K3 DSP Remoteproc remove cleanup

On Mon, Feb 05, 2024 at 12:27:48PM -0600, Andrew Davis wrote:
> Hello all,
>
> This series uses various devm_ helpers to simplify the device
> removal path.
>
> Removing an unused var "ret1" got squashed into the wrong patch in
> the v1 series causing a bisectability error. v2 is based on -next
> with the first 3 already taken. These are the last 5 patches of the
> v1 series[0].
>
> Thanks,
> Andrew
>
> [0] https://lore.kernel.org/lkml/[email protected]/T/
>
> Andrew Davis (5):
> remoteproc: k3-dsp: Use devm_ti_sci_get_by_phandle() helper
> remoteproc: k3-dsp: Use devm_kzalloc() helper
> remoteproc: k3-dsp: Add devm action to release tsp
> remoteproc: k3-dsp: Use devm_ioremap_wc() helper
> remoteproc: k3-dsp: Use devm_rproc_add() helper
>
> drivers/remoteproc/ti_k3_dsp_remoteproc.c | 116 ++++++----------------
> 1 file changed, 32 insertions(+), 84 deletions(-)
>

I have applied this set.

Thanks,
Mathieu

> --
> 2.39.2
>