Skip to content

Commit 0374a4e

Browse files
tititiou36andersson
authored andcommitted
remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak. Move the 'copy_dma_range_map()' call after the device registration so that 'rproc_rvdev_release()' can be called to free some resources. Also, branch to the error handling path if 'copy_dma_range_map()' instead of a direct return to avoid some other leaks. Fixes: e0d0727 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") Signed-off-by: Christophe JAILLET <[email protected]> Reviewed-by: Jim Quinlan <[email protected]> Reviewed-by: Mathieu Poirier <[email protected]> Signed-off-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/e6d0dad6620da4fdf847faa903f79b735d35f262.1630755377.git.christophe.jaillet@wanadoo.fr
1 parent d6a33c5 commit 0374a4e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/remoteproc/remoteproc_core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
556556
/* Initialise vdev subdevice */
557557
snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index);
558558
rvdev->dev.parent = &rproc->dev;
559-
ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
560-
if (ret)
561-
return ret;
562559
rvdev->dev.release = rproc_rvdev_release;
563560
dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name);
564561
dev_set_drvdata(&rvdev->dev, rvdev);
@@ -568,6 +565,11 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
568565
put_device(&rvdev->dev);
569566
return ret;
570567
}
568+
569+
ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
570+
if (ret)
571+
goto free_rvdev;
572+
571573
/* Make device dma capable by inheriting from parent's capabilities */
572574
set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent));
573575

0 commit comments

Comments
 (0)