Re: [PATCH] remoteproc: core: Free rvdev on error path

From: Alex Dewar
Date: Thu Sep 03 2020 - 06:09:24 EST


On Thu, Sep 03, 2020 at 11:01:42AM +0100, Alex Dewar wrote:
> In rpoc_handle_vdev(), rvdev is not freed properly on the error path and
> one of the labels is misnamed. Fix this up.

Actually, don't apply this. I didn't realise that device_unregister
already frees memory. Sorry for the noise!

>
> Fixes: 086d08725d34 ("remoteproc: create vdev subdevice with specific dma memory pool")
> Signed-off-by: Alex Dewar <alex.dewar90@xxxxxxxxx>
> ---
> drivers/remoteproc/remoteproc_core.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index d4bd71f87b03..84dea43d196e 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -531,7 +531,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
> rvdev->dev.parent = &rproc->dev;
> ret = dma_copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
> if (ret)
> - return ret;
> + goto free_rvdev;
> rvdev->dev.release = rproc_rvdev_release;
> dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name);
> dev_set_drvdata(&rvdev->dev, rvdev);
> @@ -539,7 +539,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
> ret = device_register(&rvdev->dev);
> if (ret) {
> put_device(&rvdev->dev);
> - return ret;
> + goto free_rvdev;
> }
> /* Make device dma capable by inheriting from parent's capabilities */
> set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent));
> @@ -556,7 +556,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
> for (i = 0; i < rsc->num_of_vrings; i++) {
> ret = rproc_parse_vring(rvdev, rsc, i);
> if (ret)
> - goto free_rvdev;
> + goto unregister_dev;
> }
>
> /* remember the resource offset*/
> @@ -581,8 +581,10 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc,
> unwind_vring_allocations:
> for (i--; i >= 0; i--)
> rproc_free_vring(&rvdev->vring[i]);
> -free_rvdev:
> +unregister_dev:
> device_unregister(&rvdev->dev);
> +free_rvdev:
> + kfree(rvdev);
> return ret;
> }
>
> --
> 2.28.0
>