Commit 8c5eaca0 authored by Sachin Kamat's avatar Sachin Kamat Committed by Dave Airlie

drm/fb_helper: Fix potential NULL pointer dereference

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: default avatarSachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent e655d122
...@@ -1251,6 +1251,11 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) ...@@ -1251,6 +1251,11 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
sizeof(struct drm_display_mode *), GFP_KERNEL); sizeof(struct drm_display_mode *), GFP_KERNEL);
enabled = kcalloc(dev->mode_config.num_connector, enabled = kcalloc(dev->mode_config.num_connector,
sizeof(bool), GFP_KERNEL); sizeof(bool), GFP_KERNEL);
if (!crtcs || !modes || !enabled) {
DRM_ERROR("Memory allocation failed\n");
goto out;
}
drm_enable_connectors(fb_helper, enabled); drm_enable_connectors(fb_helper, enabled);
...@@ -1289,6 +1294,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) ...@@ -1289,6 +1294,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
} }
} }
out:
kfree(crtcs); kfree(crtcs);
kfree(modes); kfree(modes);
kfree(enabled); kfree(enabled);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment