Skip to content

Commit 4bb87c0

Browse files
Lyudegregkh
authored andcommitted
drm/fb_helper: Fix references to dev->mode_config.num_connector
commit 255f0e7 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: Lyude <cpaul@redhat.com> [danvet: Clarify why we need this. Also remove the now unused "dev" local variable to appease gcc.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1463065021-18280-3-git-send-email-cpaul@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 369168d commit 4bb87c0

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/gpu/drm/drm_fb_helper.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,6 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
13471347
int n, int width, int height)
13481348
{
13491349
int c, o;
1350-
struct drm_device *dev = fb_helper->dev;
13511350
struct drm_connector *connector;
13521351
struct drm_connector_helper_funcs *connector_funcs;
13531352
struct drm_encoder *encoder;
@@ -1366,7 +1365,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
13661365
if (modes[n] == NULL)
13671366
return best_score;
13681367

1369-
crtcs = kzalloc(dev->mode_config.num_connector *
1368+
crtcs = kzalloc(fb_helper->connector_count *
13701369
sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
13711370
if (!crtcs)
13721371
return best_score;
@@ -1412,7 +1411,7 @@ static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
14121411
if (score > best_score) {
14131412
best_score = score;
14141413
memcpy(best_crtcs, crtcs,
1415-
dev->mode_config.num_connector *
1414+
fb_helper->connector_count *
14161415
sizeof(struct drm_fb_helper_crtc *));
14171416
}
14181417
}

0 commit comments

Comments
 (0)