Skip to content

Commit 8255d26

Browse files
Laurent Pinchartgregkh
authored andcommitted
drm: rcar-du: Simplify and fix probe error handling
commit 4f7b0d2 upstream. It isn't safe to call drm_dev_unregister() without first initializing mode setting with drm_mode_config_init(). This leads to a crash if either IO memory can't be remapped or vblank initialization fails. Fix this by reordering the initialization sequence. Move vblank initialization after the drm_mode_config_init() call, and move IO remapping before drm_dev_alloc() to avoid the need to perform clean up in case of failure. While at it remove the explicit drm_vblank_cleanup() call from rcar_du_remove() as the drm_dev_unregister() function already cleans up vblank. Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: thongsyho <[email protected]> Signed-off-by: Nhan Nguyen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5ec9d83 commit 8255d26

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

drivers/gpu/drm/rcar-du/rcar_du_drv.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ static int rcar_du_remove(struct platform_device *pdev)
260260

261261
drm_kms_helper_poll_fini(ddev);
262262
drm_mode_config_cleanup(ddev);
263-
drm_vblank_cleanup(ddev);
264263

265264
drm_dev_unref(ddev);
266265

@@ -291,6 +290,15 @@ static int rcar_du_probe(struct platform_device *pdev)
291290
rcdu->dev = &pdev->dev;
292291
rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
293292

293+
platform_set_drvdata(pdev, rcdu);
294+
295+
/* I/O resources */
296+
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
297+
rcdu->mmio = devm_ioremap_resource(&pdev->dev, mem);
298+
if (IS_ERR(rcdu->mmio))
299+
ret = PTR_ERR(rcdu->mmio);
300+
301+
/* DRM/KMS objects */
294302
ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev);
295303
if (!ddev)
296304
return -ENOMEM;
@@ -300,26 +308,6 @@ static int rcar_du_probe(struct platform_device *pdev)
300308
rcdu->ddev = ddev;
301309
ddev->dev_private = rcdu;
302310

303-
platform_set_drvdata(pdev, rcdu);
304-
305-
/* I/O resources */
306-
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
307-
rcdu->mmio = devm_ioremap_resource(&pdev->dev, mem);
308-
if (IS_ERR(rcdu->mmio)) {
309-
ret = PTR_ERR(rcdu->mmio);
310-
goto error;
311-
}
312-
313-
/* Initialize vertical blanking interrupts handling. Start with vblank
314-
* disabled for all CRTCs.
315-
*/
316-
ret = drm_vblank_init(ddev, (1 << rcdu->info->num_crtcs) - 1);
317-
if (ret < 0) {
318-
dev_err(&pdev->dev, "failed to initialize vblank\n");
319-
goto error;
320-
}
321-
322-
/* DRM/KMS objects */
323311
ret = rcar_du_modeset_init(rcdu);
324312
if (ret < 0) {
325313
dev_err(&pdev->dev, "failed to initialize DRM/KMS (%d)\n", ret);

drivers/gpu/drm/rcar-du/rcar_du_kms.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,13 @@ int rcar_du_modeset_init(struct rcar_du_device *rcdu)
761761
if (ret < 0)
762762
return ret;
763763

764+
/* Initialize vertical blanking interrupts handling. Start with vblank
765+
* disabled for all CRTCs.
766+
*/
767+
ret = drm_vblank_init(dev, (1 << rcdu->info->num_crtcs) - 1);
768+
if (ret < 0)
769+
return ret;
770+
764771
/* Initialize the groups. */
765772
num_groups = DIV_ROUND_UP(rcdu->num_crtcs, 2);
766773

0 commit comments

Comments
 (0)