drm/sun4i: Check return value of drm_vblank_init
authorChen-Yu Tsai <wens@csie.org>
Fri, 17 Feb 2017 03:13:26 +0000 (11:13 +0800)
committerMaxime Ripard <maxime.ripard@free-electrons.com>
Tue, 7 Mar 2017 21:15:15 +0000 (22:15 +0100)
drm_vblank_init can fail due to insufficient memory. Ignoring the error
and proceeding may cause the kernel to dereference an invalid pointer
when vblank is enabled.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
drivers/gpu/drm/sun4i/sun4i_drv.c

index 7ae179e88309f8498fcbcc97afb513f3364c480b..46887c3044d0536bce6052b2a2da727025c30ada 100644 (file)
@@ -102,7 +102,11 @@ static int sun4i_drv_bind(struct device *dev)
        }
        drm->dev_private = drv;
 
-       drm_vblank_init(drm, 1);
+       /* drm_vblank_init calls kcalloc, which can fail */
+       ret = drm_vblank_init(drm, 1);
+       if (ret)
+               goto free_drm;
+
        drm_mode_config_init(drm);
 
        ret = component_bind_all(drm->dev, drm);