Skip to content

Commit

Permalink
drm/msm: fix vram leak on bind errors
Browse files Browse the repository at this point in the history
commit 60d476a upstream.

Make sure to release the VRAM buffer also in a case a subcomponent fails
to bind.

Fixes: d863f0c ("drm/msm: Call msm_init_vram before binding the gpu")
Cc: stable@vger.kernel.org      # 5.11
Cc: Craig Tatlor <ctatlor97@gmail.com>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/525094/
Link: https://lore.kernel.org/r/20230306100722.28485-7-johan+linaro@kernel.org
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
jhovold authored and gregkh committed May 17, 2023
1 parent 0fad173 commit 5447115
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions drivers/gpu/drm/msm/msm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#define MSM_VERSION_MINOR 9
#define MSM_VERSION_PATCHLEVEL 0

static void msm_deinit_vram(struct drm_device *ddev);

static const struct drm_mode_config_funcs mode_config_funcs = {
.fb_create = msm_framebuffer_create,
.output_poll_changed = drm_fb_helper_output_poll_changed,
Expand Down Expand Up @@ -259,12 +261,7 @@ static int msm_drm_uninit(struct device *dev)
if (kms && kms->funcs)
kms->funcs->destroy(kms);

if (priv->vram.paddr) {
unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
drm_mm_takedown(&priv->vram.mm);
dma_free_attrs(dev, priv->vram.size, NULL,
priv->vram.paddr, attrs);
}
msm_deinit_vram(ddev);

component_unbind_all(dev, ddev);

Expand Down Expand Up @@ -404,6 +401,19 @@ static int msm_init_vram(struct drm_device *dev)
return ret;
}

static void msm_deinit_vram(struct drm_device *ddev)
{
struct msm_drm_private *priv = ddev->dev_private;
unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;

if (!priv->vram.paddr)
return;

drm_mm_takedown(&priv->vram.mm);
dma_free_attrs(ddev->dev, priv->vram.size, NULL, priv->vram.paddr,
attrs);
}

static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
{
struct msm_drm_private *priv = dev_get_drvdata(dev);
Expand Down Expand Up @@ -451,7 +461,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
/* Bind all our sub-components: */
ret = component_bind_all(dev, ddev);
if (ret)
goto err_put_dev;
goto err_deinit_vram;

dma_set_max_seg_size(dev, UINT_MAX);

Expand Down Expand Up @@ -549,6 +559,8 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)

return ret;

err_deinit_vram:
msm_deinit_vram(ddev);
err_put_dev:
drm_dev_put(ddev);

Expand Down

0 comments on commit 5447115

Please sign in to comment.