Skip to content

Commit

Permalink
drm/fb_helper: Fix potential NULL pointer dereference
Browse files Browse the repository at this point in the history
kcalloc returns NULL on failure. Hence check for the return value
and exit on error to avoid NULL pointer dereference.

Fixes the following smatch errors:
drivers/gpu/drm/drm_fb_helper.c:1271 drm_setup_crtcs() error:
potential null dereference 'modes'.  (kcalloc returns null)
drivers/gpu/drm/drm_fb_helper.c:1272 drm_setup_crtcs() error:
potential null dereference 'crtcs'.  (kcalloc returns null)

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Sachin Kamat authored and Dave Airlie committed Nov 20, 2012
1 parent e655d12 commit 8c5eaca
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/gpu/drm/drm_fb_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,11 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
sizeof(struct drm_display_mode *), GFP_KERNEL);
enabled = kcalloc(dev->mode_config.num_connector,
sizeof(bool), GFP_KERNEL);
if (!crtcs || !modes || !enabled) {
DRM_ERROR("Memory allocation failed\n");
goto out;
}


drm_enable_connectors(fb_helper, enabled);

Expand Down Expand Up @@ -1289,6 +1294,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
}
}

out:
kfree(crtcs);
kfree(modes);
kfree(enabled);
Expand Down

0 comments on commit 8c5eaca

Please sign in to comment.