Skip to content

Commit a695949

Browse files
ziyao233superna9999
authored andcommitted
drm/meson: fix canvas release in bind function
Allocated canvases may not be released on the error exit path of meson_drv_bind_master(), leading to resource leaking. Rewrite exit path to release canvases on error. Fixes: 2bf6b5b ("drm/meson: exclusively use the canvas provider module") Signed-off-by: Yao Zi <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Neil Armstrong <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 91f9f4a commit a695949

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

drivers/gpu/drm/meson/meson_drv.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,20 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
250250
if (ret)
251251
goto free_drm;
252252
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
253-
if (ret) {
254-
meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
255-
goto free_drm;
256-
}
253+
if (ret)
254+
goto free_canvas_osd1;
257255
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_1);
258-
if (ret) {
259-
meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
260-
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
261-
goto free_drm;
262-
}
256+
if (ret)
257+
goto free_canvas_vd1_0;
263258
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_2);
264-
if (ret) {
265-
meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
266-
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
267-
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
268-
goto free_drm;
269-
}
259+
if (ret)
260+
goto free_canvas_vd1_1;
270261

271262
priv->vsync_irq = platform_get_irq(pdev, 0);
272263

273264
ret = drm_vblank_init(drm, 1);
274265
if (ret)
275-
goto free_drm;
266+
goto free_canvas_vd1_2;
276267

277268
/* Assign limits per soc revision/package */
278269
for (i = 0 ; i < ARRAY_SIZE(meson_drm_soc_attrs) ; ++i) {
@@ -288,11 +279,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
288279
*/
289280
ret = drm_aperture_remove_framebuffers(&meson_driver);
290281
if (ret)
291-
goto free_drm;
282+
goto free_canvas_vd1_2;
292283

293284
ret = drmm_mode_config_init(drm);
294285
if (ret)
295-
goto free_drm;
286+
goto free_canvas_vd1_2;
296287
drm->mode_config.max_width = 3840;
297288
drm->mode_config.max_height = 2160;
298289
drm->mode_config.funcs = &meson_mode_config_funcs;
@@ -307,7 +298,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
307298
if (priv->afbcd.ops) {
308299
ret = priv->afbcd.ops->init(priv);
309300
if (ret)
310-
goto free_drm;
301+
goto free_canvas_vd1_2;
311302
}
312303

313304
/* Encoder Initialization */
@@ -371,6 +362,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
371362
exit_afbcd:
372363
if (priv->afbcd.ops)
373364
priv->afbcd.ops->exit(priv);
365+
free_canvas_vd1_2:
366+
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
367+
free_canvas_vd1_1:
368+
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
369+
free_canvas_vd1_0:
370+
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
371+
free_canvas_osd1:
372+
meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
374373
free_drm:
375374
drm_dev_put(drm);
376375

0 commit comments

Comments
 (0)