remoteproc: wkup_m3: Use devm_pm_runtime_enable() helper
PATCH 1/4 remoteproc: wkup_m3: Use devm_pm_runtime_enable() helper
Use device life-cycle managed runtime enable function to simplify probe and exit paths.
--- drivers/remoteproc/wkup_m3_rproc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/remoteproc/wkup_m3_rproc.c +3 -3
@@ -148,7 +148,9 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)return -ENODEV ; } -pm_runtime_enable (&pdev->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_get_sync (&pdev->dev);if (ret <0 ) {dev_err (&pdev->dev,"pm_runtime_get_sync() failed\n" );
@@ -219,7 +221,6 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)rproc_free (rproc); err:pm_runtime_put_noidle (dev); -pm_runtime_disable (dev);return ret; }
@@ -230,7 +231,6 @@ static void wkup_m3_rproc_remove(struct platform_device *pdev)rproc_del (rproc);rproc_free (rproc);pm_runtime_put_sync (&pdev->dev); -pm_runtime_disable (&pdev->dev); }#ifdef CONFIG_PM
Signature · 1 line
2.39.2
PATCH 2/4 remoteproc: wkup_m3: Use devm action to call PM runtime put sync
This helps prevent mistakes like putting out of order in cleanup functions and forgetting to put sync on error paths.
--- drivers/remoteproc/wkup_m3_rproc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/remoteproc/wkup_m3_rproc.c +14 -11
@@ -125,6 +125,13 @@ static const struct of_device_id wkup_m3_rproc_of_match[] = { };MODULE_DEVICE_TABLE (of, wkup_m3_rproc_of_match); +static void wkup_m3_rproc_pm_runtime_put (void *data) +{ +struct device *dev = data; + +pm_runtime_put_sync (dev); +} +static int wkup_m3_rproc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -152,17 +159,16 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable runtime PM\n" ); ret =pm_runtime_get_sync (&pdev->dev); -if (ret <0 ) { -dev_err (&pdev->dev,"pm_runtime_get_sync() failed\n" ); - goto err; - } +if (ret <0 ) +return dev_err_probe (dev, ret,"pm_runtime_get_sync() failed\n" ); + ret =devm_add_action_or_reset (dev, wkup_m3_rproc_pm_runtime_put, dev); +if (ret) +return dev_err_probe (dev, ret,"failed to add disable pm devm action\n" ); rproc =rproc_alloc (dev,"wkup_m3" , &wkup_m3_rproc_ops, fw_name,sizeof (*wkupm3)); -if (!rproc) { - ret = -ENOMEM ; - goto err; - } +if (!rproc) +return -ENOMEM ; rproc->auto_boot = false; rproc->sysfs_read_only = true;
@@ -219,8 +225,6 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev) err_put_rproc:rproc_free (rproc); -err: -pm_runtime_put_noidle (dev);return ret; }
@@ -230,7 +234,6 @@ static void wkup_m3_rproc_remove(struct platform_device *pdev)rproc_del (rproc);rproc_free (rproc); -pm_runtime_put_sync (&pdev->dev); }#ifdef CONFIG_PM
Signature · 1 line
2.39.2
PATCH 3/4 remoteproc: wkup_m3: 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/wkup_m3_rproc.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/remoteproc/wkup_m3_rproc.c +8 -20
@@ -165,8 +165,8 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)if (ret)return dev_err_probe (dev, ret,"failed to add disable pm devm action\n" ); - rproc =rproc_alloc (dev,"wkup_m3" , &wkup_m3_rproc_ops, - fw_name,sizeof (*wkupm3)); + rproc =devm_rproc_alloc (dev,"wkup_m3" , &wkup_m3_rproc_ops, + fw_name,sizeof (*wkupm3));if (!rproc)return -ENOMEM ;
@@ -183,9 +183,7 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)if (!wkupm3->rsts) {if (!(pdata && pdata->deassert_reset && pdata->assert_reset && pdata->reset_name)) { -dev_err (dev,"Platform data missing!\n" ); - ret = -ENODEV ; - goto err_put_rproc; +return dev_err_probe (dev, -ENODEV ,"Platform data missing!\n" ); } }
@@ -193,12 +191,9 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev) res =platform_get_resource_byname (pdev,IORESOURCE_MEM , mem_names[i]); wkupm3->mem[i].cpu_addr =devm_ioremap_resource (dev, res); -if (IS_ERR (wkupm3->mem[i].cpu_addr)) { -dev_err (&pdev->dev,"devm_ioremap_resource failed for resource %d\n" , - i); - ret =PTR_ERR (wkupm3->mem[i].cpu_addr); - goto err_put_rproc; - } +if (IS_ERR (wkupm3->mem[i].cpu_addr)) +return dev_err_probe (dev,PTR_ERR (wkupm3->mem[i].cpu_addr), +"devm_ioremap_resource failed for resource %d\n" , i); wkupm3->mem[i].bus_addr = res->start; wkupm3->mem[i].size =resource_size (res); addrp =of_get_address (dev->of_node, i, &size,NULL );
@@ -216,16 +211,10 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev)dev_set_drvdata (dev, rproc); ret =rproc_add (rproc); -if (ret) { -dev_err (dev,"rproc_add failed\n" ); - goto err_put_rproc; - } +if (ret) +return dev_err_probe (dev, ret,"rproc_add failed\n" );return 0 ; - -err_put_rproc: -rproc_free (rproc); -return ret; }static void wkup_m3_rproc_remove (struct platform_device *pdev)
@@ -233,7 +222,6 @@ static void wkup_m3_rproc_remove(struct platform_device *pdev)struct rproc *rproc =platform_get_drvdata (pdev);rproc_del (rproc); -rproc_free (rproc); }#ifdef CONFIG_PM
Signature · 1 line
2.39.2
PATCH 4/4 remoteproc: wkup_m3: 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/wkup_m3_rproc.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/remoteproc/wkup_m3_rproc.c +1 -11
@@ -208,22 +208,13 @@ static int wkup_m3_rproc_probe(struct platform_device *pdev) wkupm3->mem[i].dev_addr =be32_to_cpu (*addrp) - l4_offset; } -dev_set_drvdata (dev, rproc); - - ret =rproc_add (rproc); + ret =devm_rproc_add (dev, rproc);if (ret)return dev_err_probe (dev, ret,"rproc_add failed\n" );return 0 ; } -static void wkup_m3_rproc_remove (struct platform_device *pdev) -{ -struct rproc *rproc =platform_get_drvdata (pdev); - -rproc_del (rproc); -} -#ifdef CONFIG_PM static int wkup_m3_rpm_suspend (struct device *dev) {
@@ -242,7 +233,6 @@ static const struct dev_pm_ops wkup_m3_rproc_pm_ops = {static struct platform_driver wkup_m3_rproc_driver = { .probe = wkup_m3_rproc_probe, - .remove = wkup_m3_rproc_remove, .driver = { .name ="wkup_m3_rproc" , .of_match_table = wkup_m3_rproc_of_match,
Signature · 1 line
2.39.2