Commit e4eb16ab authored by Lyude's avatar Lyude Committed by Greg Kroah-Hartman

drm/fb_helper: Fix references to dev->mode_config.num_connector

commit 255f0e7c upstream.

During boot, MST hotplugs are generally expected (even if no physical
hotplugging occurs) and result in DRM's connector topology changing.
This means that using num_connector from the current mode configuration
can lead to the number of connectors changing under us. This can lead to
some nasty scenarios in fbcon:

- We allocate an array to the size of dev->mode_config.num_connectors.
- MST hotplug occurs, dev->mode_config.num_connectors gets incremented.
- We try to loop through each element in the array using the new value
  of dev->mode_config.num_connectors, and end up going out of bounds
  since dev->mode_config.num_connectors is now larger then the array we
  allocated.

fb_helper->connector_count however, will always remain consistent while
we do a modeset in fb_helper.

Note: This is just polish for 4.7, Dave Airlie's drm_connector
refcounting fixed these bugs for real. But it's good enough duct-tape
for stable kernel backporting, since backporting the refcounting
changes is way too invasive.
Signed-off-by: default avatarLyude <cpaul@redhat.com>
[danvet: Clarify why we need this. Also remove the now unused "dev"
local variable to appease gcc.]
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1463065021-18280-3-git-send-email-cpaul@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c266d007
...@@ -1895,7 +1895,6 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, ...@@ -1895,7 +1895,6 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
int n, int width, int height) int n, int width, int height)
{ {
int c, o; int c, o;
struct drm_device *dev = fb_helper->dev;
struct drm_connector *connector; struct drm_connector *connector;
const struct drm_connector_helper_funcs *connector_funcs; const struct drm_connector_helper_funcs *connector_funcs;
struct drm_encoder *encoder; struct drm_encoder *encoder;
...@@ -1914,7 +1913,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, ...@@ -1914,7 +1913,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
if (modes[n] == NULL) if (modes[n] == NULL)
return best_score; return best_score;
crtcs = kzalloc(dev->mode_config.num_connector * crtcs = kzalloc(fb_helper->connector_count *
sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
if (!crtcs) if (!crtcs)
return best_score; return best_score;
...@@ -1960,7 +1959,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, ...@@ -1960,7 +1959,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
if (score > best_score) { if (score > best_score) {
best_score = score; best_score = score;
memcpy(best_crtcs, crtcs, memcpy(best_crtcs, crtcs,
dev->mode_config.num_connector * fb_helper->connector_count *
sizeof(struct drm_fb_helper_crtc *)); sizeof(struct drm_fb_helper_crtc *));
} }
} }
......
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