remoteproc: omap: Use devm_rproc_alloc() helper
PATCH 1/6 remoteproc: omap: Use devm_rproc_alloc() helper
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.
--- drivers/remoteproc/omap_remoteproc.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/remoteproc/omap_remoteproc.c +8 -12
@@ -1305,8 +1305,8 @@ static int omap_rproc_probe(struct platform_device *pdev)return ret; } - rproc =rproc_alloc (&pdev->dev,dev_name (&pdev->dev), &omap_rproc_ops, - firmware,sizeof (*oproc)); + rproc =devm_rproc_alloc (&pdev->dev,dev_name (&pdev->dev), &omap_rproc_ops, + firmware,sizeof (*oproc));if (!rproc)return -ENOMEM ;
@@ -1318,15 +1318,15 @@ static int omap_rproc_probe(struct platform_device *pdev) ret =omap_rproc_of_get_internal_memories (pdev, rproc);if (ret) - goto free_rproc; +return ret; ret =omap_rproc_get_boot_data (pdev, rproc);if (ret) - goto free_rproc; +return ret; ret =omap_rproc_of_get_timers (pdev, rproc);if (ret) - goto free_rproc; +return ret;init_completion (&oproc->pm_comp); oproc->autosuspend_delay =DEFAULT_AUTOSUSPEND_DELAY ;
@@ -1337,10 +1337,8 @@ static int omap_rproc_probe(struct platform_device *pdev)pm_runtime_set_autosuspend_delay (&pdev->dev, oproc->autosuspend_delay); oproc->fck =devm_clk_get (&pdev->dev,0 ); -if (IS_ERR (oproc->fck)) { - ret =PTR_ERR (oproc->fck); - goto free_rproc; - } +if (IS_ERR (oproc->fck)) +return PTR_ERR (oproc->fck); ret =of_reserved_mem_device_init (&pdev->dev);if (ret) {
@@ -1359,8 +1357,7 @@ static int omap_rproc_probe(struct platform_device *pdev) release_mem:of_reserved_mem_device_release (&pdev->dev); -free_rproc: -rproc_free (rproc); +return ret; }
@@ -1369,7 +1366,6 @@ static void omap_rproc_remove(struct platform_device *pdev)struct rproc *rproc =platform_get_drvdata (pdev);rproc_del (rproc); -rproc_free (rproc);of_reserved_mem_device_release (&pdev->dev); }
Signature · 1 line
2.39.2
PATCH 2/6 remoteproc: omap: Use devm action to release reserved memory
This helps prevent mistakes like freeing out of order in cleanup functions and forgetting to free on error paths.
--- drivers/remoteproc/omap_remoteproc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/remoteproc/omap_remoteproc.c +11 -7
@@ -1277,6 +1277,13 @@ static int omap_rproc_of_get_timers(struct platform_device *pdev,return 0 ; } +static void omap_rproc_mem_release (void *data) +{ +struct device *dev = data; + +of_reserved_mem_device_release (dev); +} +static int omap_rproc_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;
@@ -1346,19 +1353,17 @@ static int omap_rproc_probe(struct platform_device *pdev)dev_warn (&pdev->dev,"Typically this should be provided,\n" );dev_warn (&pdev->dev,"only omit if you know what you are doing.\n" ); } + ret =devm_add_action_or_reset (&pdev->dev, omap_rproc_mem_release, &pdev->dev); +if (ret) +return ret;platform_set_drvdata (pdev, rproc); ret =rproc_add (rproc);if (ret) - goto release_mem; +return ret;return 0 ; - -release_mem: -of_reserved_mem_device_release (&pdev->dev); - -return ret; }static void omap_rproc_remove (struct platform_device *pdev)
@@ -1366,7 +1371,6 @@ static void omap_rproc_remove(struct platform_device *pdev)struct rproc *rproc =platform_get_drvdata (pdev);rproc_del (rproc); -of_reserved_mem_device_release (&pdev->dev); }static const struct dev_pm_ops omap_rproc_pm_ops = {
Signature · 1 line
2.39.2
PATCH 3/6 remoteproc: omap: Use devm_rproc_add() helper
In reply to Andrew DavisUse 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.
--- drivers/remoteproc/omap_remoteproc.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/remoteproc/omap_remoteproc.c +1 -9
@@ -1359,20 +1359,13 @@ static int omap_rproc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, rproc); - ret =rproc_add (rproc); + ret =devm_rproc_add (&pdev->dev, rproc);if (ret)return ret;return 0 ; } -static void omap_rproc_remove (struct platform_device *pdev) -{ -struct rproc *rproc =platform_get_drvdata (pdev); - -rproc_del (rproc); -} -static const struct dev_pm_ops omap_rproc_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(omap_rproc_suspend, omap_rproc_resume) SET_RUNTIME_PM_OPS(omap_rproc_runtime_suspend,
@@ -1381,7 +1374,6 @@ static const struct dev_pm_ops omap_rproc_pm_ops = {static struct platform_driver omap_rproc_driver = { .probe = omap_rproc_probe, - .remove_new = omap_rproc_remove, .driver = { .name ="omap-rproc" , .pm = &omap_rproc_pm_ops,
Signature · 1 line
2.39.2
PATCH 4/6 remoteproc: da8xx: Use devm_rproc_alloc() helper
In reply to Andrew DavisUse 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.
--- drivers/remoteproc/da8xx_remoteproc.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/remoteproc/da8xx_remoteproc.c +6 -9
@@ -295,8 +295,8 @@ static int da8xx_rproc_probe(struct platform_device *pdev) } } - rproc =rproc_alloc (dev,"dsp" , &da8xx_rproc_ops, da8xx_fw_name, -sizeof (*drproc)); + rproc =devm_rproc_alloc (dev,"dsp" , &da8xx_rproc_ops, da8xx_fw_name, +sizeof (*drproc));if (!rproc) { ret = -ENOMEM ; goto free_mem;
@@ -313,7 +313,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =da8xx_rproc_get_internal_memories (pdev, drproc);if (ret) - goto free_rproc; + goto free_mem;platform_set_drvdata (pdev, rproc);
@@ -323,7 +323,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) rproc);if (ret) {dev_err (dev,"devm_request_threaded_irq error: %d\n" , ret); - goto free_rproc; + goto free_mem; }/*
@@ -333,7 +333,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)*/ ret =reset_control_assert (dsp_reset);if (ret) - goto free_rproc; + goto free_mem; drproc->chipsig = chipsig; drproc->bootreg = bootreg;
@@ -344,13 +344,11 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =rproc_add (rproc);if (ret) {dev_err (dev,"rproc_add failed: %d\n" , ret); - goto free_rproc; + goto free_mem; }return 0 ; -free_rproc: -rproc_free (rproc); free_mem:if (dev->of_node)of_reserved_mem_device_release (dev);
@@ -371,7 +369,6 @@ static void da8xx_rproc_remove(struct platform_device *pdev)disable_irq (drproc->irq);rproc_del (rproc); -rproc_free (rproc);if (dev->of_node)of_reserved_mem_device_release (dev); }
Signature · 1 line
2.39.2
PATCH 5/6 remoteproc: da8xx: Use devm action to release reserved memory
In reply to Andrew DavisThis helps prevent mistakes like freeing out of order in cleanup functions and forgetting to free on error paths.
--- drivers/remoteproc/da8xx_remoteproc.c | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/remoteproc/da8xx_remoteproc.c +14 -15
@@ -233,6 +233,13 @@ static int da8xx_rproc_get_internal_memories(struct platform_device *pdev,return 0 ; } +static void da8xx_rproc_mem_release (void *data) +{ +struct device *dev = data; + +of_reserved_mem_device_release (dev); +} +static int da8xx_rproc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -293,14 +300,13 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret);return ret; } +devm_add_action_or_reset (&pdev->dev, da8xx_rproc_mem_release, &pdev->dev); } rproc =devm_rproc_alloc (dev,"dsp" , &da8xx_rproc_ops, da8xx_fw_name,sizeof (*drproc)); -if (!rproc) { - ret = -ENOMEM ; - goto free_mem; - } +if (!rproc) +return -ENOMEM ;/* error recovery is not supported at present */ rproc->recovery_disabled = true;
@@ -313,7 +319,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =da8xx_rproc_get_internal_memories (pdev, drproc);if (ret) - goto free_mem; +return ret;platform_set_drvdata (pdev, rproc);
@@ -323,7 +329,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) rproc);if (ret) {dev_err (dev,"devm_request_threaded_irq error: %d\n" , ret); - goto free_mem; +return ret; }/*
@@ -333,7 +339,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)*/ ret =reset_control_assert (dsp_reset);if (ret) - goto free_mem; +return ret; drproc->chipsig = chipsig; drproc->bootreg = bootreg;
@@ -344,15 +350,10 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =rproc_add (rproc);if (ret) {dev_err (dev,"rproc_add failed: %d\n" , ret); - goto free_mem; +return ret; }return 0 ; - -free_mem: -if (dev->of_node) -of_reserved_mem_device_release (dev); -return ret; }static void da8xx_rproc_remove (struct platform_device *pdev)
@@ -369,8 +370,6 @@ static void da8xx_rproc_remove(struct platform_device *pdev)disable_irq (drproc->irq);rproc_del (rproc); -if (dev->of_node) -of_reserved_mem_device_release (dev); }static const struct of_device_id davinci_rproc_of_match[]__maybe_unused = {
Signature · 1 line
2.39.2
Mathieu Poirier
maintainerRe: [PATCH 5/6] remoteproc: da8xx: Use devm action to release reserved memory
Hi Andrew,
Quoted 89 lines · 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 <[email protected]>--- drivers/remoteproc/da8xx_remoteproc.c | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-)drivers/remoteproc/da8xx_remoteproc.c +14
-13@@ -233,6 +233,13 @@ static int da8xx_rproc_get_internal_memories(struct platform_device *pdev,return 0 ; } +static void da8xx_rproc_mem_release (void *data) +{ +struct device *dev = data; + +of_reserved_mem_device_release (dev); +} +static int da8xx_rproc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -293,14 +300,13 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret);return ret; } +devm_add_action_or_reset (&pdev->dev, da8xx_rproc_mem_release, &pdev->dev); } rproc =devm_rproc_alloc (dev,"dsp" , &da8xx_rproc_ops, da8xx_fw_name,sizeof (*drproc)); -if (!rproc) { - ret = -ENOMEM ; - goto free_mem; - } +if (!rproc) +return -ENOMEM ;/* error recovery is not supported at present */ rproc->recovery_disabled = true;@@ -313,7 +319,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =da8xx_rproc_get_internal_memories (pdev, drproc);if (ret) - goto free_mem; +return ret;platform_set_drvdata (pdev, rproc);@@ -323,7 +329,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) rproc);if (ret) {dev_err (dev,"devm_request_threaded_irq error: %d\n" , ret); - goto free_mem; +return ret; }/* @@ -333,7 +339,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)*/ ret =reset_control_assert (dsp_reset);if (ret) - goto free_mem; +return ret; drproc->chipsig = chipsig; drproc->bootreg = bootreg;@@ -344,15 +350,10 @@ static int da8xx_rproc_probe(struct platform_device *pdev) ret =rproc_add (rproc);if (ret) {dev_err (dev,"rproc_add failed: %d\n" , ret); - goto free_mem; +return ret; }return 0 ; - -free_mem: -if (dev->of_node) -of_reserved_mem_device_release (dev); -return ret; }static void da8xx_rproc_remove (struct platform_device *pdev)
drivers/remoteproc/da8xx_remoteproc.c static void da8xx_rproc_remove(struct platform_device *pdev) · line 373
Quoted 5 lines
drivers/remoteproc/da8xx_remoteproc.c +0
-2@@ -369,8 +370,6 @@ static void da8xx_rproc_remove(struct platform_device *pdev)disable_irq (drproc->irq);rproc_del (rproc); -if (dev->of_node) -of_reserved_mem_device_release (dev);
This patch gives me the following compilation warning:
CC kernel/module/main.o CC drivers/remoteproc/da8xx_remoteproc.o AR drivers/base/firmware_loader/built-in.a AR drivers/base/built-in.a
remoteproc/kernel/drivers/remoteproc/da8xx_remoteproc.c: In function ‘da8xx_rproc_remove’:remoteproc/kernel/drivers/remoteproc/da8xx_remoteproc.c:363:24: warning: unused variable ‘dev’ [-Wunused-variable]
363 | struct device *dev = &pdev->dev;
| ^~~
AR drivers/remoteproc/built-in.a
which is then fixed in the following patch with the introduction of devm_rproc_add(). I suggest doing the opposite, i.e introduce devm_rproc_add() and then get rid of da8xx_rproc_remove() by introducing da8xx_rproc_mem_release().
No need to resend the omap set, I have them.
Thanks,
Mathieu
Quoted 6 lines
drivers/remoteproc/da8xx_remoteproc.c +0
-0}static const struct of_device_id davinci_rproc_of_match[]__maybe_unused = {Signature · 1 line
2.39.2
PATCH 6/6 remoteproc: da8xx: Use devm_rproc_add() helper
In reply to Andrew DavisUse 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.
--- drivers/remoteproc/da8xx_remoteproc.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/remoteproc/da8xx_remoteproc.c +1 -20
@@ -321,8 +321,6 @@ static int da8xx_rproc_probe(struct platform_device *pdev)if (ret)return ret; -platform_set_drvdata (pdev, rproc); -/* everything the ISR needs is now setup, so hook it up */ ret = devm_request_threaded_irq(dev, irq, da8xx_rproc_callback, handle_event, 0, "da8xx-remoteproc",
@@ -347,7 +345,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev) drproc->irq_data = irq_data; drproc->irq = irq; - ret =rproc_add (rproc); + ret =devm_rproc_add (dev, rproc);if (ret) {dev_err (dev,"rproc_add failed: %d\n" , ret);return ret;
@@ -356,22 +354,6 @@ static int da8xx_rproc_probe(struct platform_device *pdev)return 0 ; } -static void da8xx_rproc_remove (struct platform_device *pdev) -{ -struct rproc *rproc =platform_get_drvdata (pdev); -struct da8xx_rproc *drproc = rproc->priv; -struct device *dev = &pdev->dev; - -/* -* The devm subsystem might end up releasing things before -* freeing the irq, thus allowing an interrupt to sneak in while -* the device is being removed. This should prevent that. -*/ -disable_irq (drproc->irq); - -rproc_del (rproc); -} -static const struct of_device_id davinci_rproc_of_match[]__maybe_unused = { { .compatible ="ti,da850-dsp" , }, {/* sentinel */ },
@@ -380,7 +362,6 @@ MODULE_DEVICE_TABLE(of, davinci_rproc_of_match);static struct platform_driver da8xx_rproc_driver = { .probe = da8xx_rproc_probe, - .remove_new = da8xx_rproc_remove, .driver = { .name ="davinci-rproc" , .of_match_table =of_match_ptr (davinci_rproc_of_match),
Signature · 1 line
2.39.2