Commit ea3aa620 authored by Daniel Vetter's avatar Daniel Vetter

drm/v3d: Use drmm_add_final_kfree

With this we can drop the final kfree from the release function.

I also noticed that the unwind code is wrong, after drm_dev_init the
drm_device owns the v3d allocation, so the kfree(v3d) is a double-free.
Reorder the setup to fix this issue.

After a bit more prep in drivers and drm core v3d should be able to
switch over to devm_drm_dev_init, which should clean this up further.
Acked-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Cc: Eric Anholt <eric@anholt.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-11-daniel.vetter@ffwll.ch
parent b6097727
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_fb_cma_helper.h> #include <drm/drm_fb_cma_helper.h>
#include <drm/drm_fb_helper.h> #include <drm/drm_fb_helper.h>
#include <drm/drm_managed.h>
#include <uapi/drm/v3d_drm.h> #include <uapi/drm/v3d_drm.h>
#include "v3d_drv.h" #include "v3d_drv.h"
...@@ -257,13 +258,23 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -257,13 +258,23 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
v3d->pdev = pdev; v3d->pdev = pdev;
drm = &v3d->drm; drm = &v3d->drm;
ret = drm_dev_init(&v3d->drm, &v3d_drm_driver, dev);
if (ret) {
kfree(v3d);
return ret;
}
platform_set_drvdata(pdev, drm);
drm->dev_private = v3d;
drmm_add_final_kfree(drm, v3d);
ret = map_regs(v3d, &v3d->hub_regs, "hub"); ret = map_regs(v3d, &v3d->hub_regs, "hub");
if (ret) if (ret)
goto dev_free; goto dev_destroy;
ret = map_regs(v3d, &v3d->core_regs[0], "core0"); ret = map_regs(v3d, &v3d->core_regs[0], "core0");
if (ret) if (ret)
goto dev_free; goto dev_destroy;
mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO); mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO);
dev->coherent_dma_mask = dev->coherent_dma_mask =
...@@ -281,21 +292,21 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -281,21 +292,21 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
ret = PTR_ERR(v3d->reset); ret = PTR_ERR(v3d->reset);
if (ret == -EPROBE_DEFER) if (ret == -EPROBE_DEFER)
goto dev_free; goto dev_destroy;
v3d->reset = NULL; v3d->reset = NULL;
ret = map_regs(v3d, &v3d->bridge_regs, "bridge"); ret = map_regs(v3d, &v3d->bridge_regs, "bridge");
if (ret) { if (ret) {
dev_err(dev, dev_err(dev,
"Failed to get reset control or bridge regs\n"); "Failed to get reset control or bridge regs\n");
goto dev_free; goto dev_destroy;
} }
} }
if (v3d->ver < 41) { if (v3d->ver < 41) {
ret = map_regs(v3d, &v3d->gca_regs, "gca"); ret = map_regs(v3d, &v3d->gca_regs, "gca");
if (ret) if (ret)
goto dev_free; goto dev_destroy;
} }
v3d->mmu_scratch = dma_alloc_wc(dev, 4096, &v3d->mmu_scratch_paddr, v3d->mmu_scratch = dma_alloc_wc(dev, 4096, &v3d->mmu_scratch_paddr,
...@@ -303,23 +314,16 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -303,23 +314,16 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
if (!v3d->mmu_scratch) { if (!v3d->mmu_scratch) {
dev_err(dev, "Failed to allocate MMU scratch page\n"); dev_err(dev, "Failed to allocate MMU scratch page\n");
ret = -ENOMEM; ret = -ENOMEM;
goto dev_free; goto dev_destroy;
} }
pm_runtime_use_autosuspend(dev); pm_runtime_use_autosuspend(dev);
pm_runtime_set_autosuspend_delay(dev, 50); pm_runtime_set_autosuspend_delay(dev, 50);
pm_runtime_enable(dev); pm_runtime_enable(dev);
ret = drm_dev_init(&v3d->drm, &v3d_drm_driver, dev);
if (ret)
goto dma_free;
platform_set_drvdata(pdev, drm);
drm->dev_private = v3d;
ret = v3d_gem_init(drm); ret = v3d_gem_init(drm);
if (ret) if (ret)
goto dev_destroy; goto dma_free;
ret = v3d_irq_init(v3d); ret = v3d_irq_init(v3d);
if (ret) if (ret)
...@@ -335,12 +339,10 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -335,12 +339,10 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
v3d_irq_disable(v3d); v3d_irq_disable(v3d);
gem_destroy: gem_destroy:
v3d_gem_destroy(drm); v3d_gem_destroy(drm);
dev_destroy:
drm_dev_put(drm);
dma_free: dma_free:
dma_free_wc(dev, 4096, v3d->mmu_scratch, v3d->mmu_scratch_paddr); dma_free_wc(dev, 4096, v3d->mmu_scratch, v3d->mmu_scratch_paddr);
dev_free: dev_destroy:
kfree(v3d); drm_dev_put(drm);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment