drm: atmel-hlcdc: fix a NULL check
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 25 Apr 2016 09:04:54 +0000 (12:04 +0300)
committerBoris Brezillon <boris.brezillon@free-electrons.com>
Wed, 1 Jun 2016 13:59:36 +0000 (15:59 +0200)
If kmalloc() returned NULL we would end up dereferencing "state" a
couple lines later.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c

index ac4e063..bd12231 100644 (file)
@@ -414,8 +414,9 @@ atmel_hlcdc_crtc_duplicate_state(struct drm_crtc *crtc)
                return NULL;
 
        state = kmalloc(sizeof(*state), GFP_KERNEL);
-       if (state)
-               __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
+       if (!state)
+               return NULL;
+       __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
 
        cur = drm_crtc_state_to_atmel_hlcdc_crtc_state(crtc->state);
        state->output_mode = cur->output_mode;