Commit a2889606 authored by Ville Syrjälä's avatar Ville Syrjälä Committed by Daniel Vetter

drm/fb-helper: Keep references for the current set of used connectors

The fbdev helper code keeps around two lists of connectors. One is the
list of all connectors it could use, and that list already holds
references for all the connectors. However the other list, or rather
lists, is the one actively being used. That list is tracked per-crtc
and currently doesn't hold any extra references. Let's grab those
extra references to avoid oopsing when the connector vanishes. The
list of all possible connectors should get updated when the hpd happens,
but the list of actively used connectors would not get updated until
the next time the fb-helper picks through the set of possible connectors.
And so we need to hang on to the connectors until that time.

Since we need to clean up in drm_fb_helper_crtc_free() as well,
let's pull the code to a common place. And while at it let's
pull in up the modeset->mode cleanup in there as well. The case
of modeset->fb is a bit less clear. I'm thinking we should probably
hold a reference to it, but for now I just slapped on a FIXME.

v2: Cleanup things drm_fb_helper_crtc_free() too (Chris)
v3: Don't leak modeset->connectors (Chris)

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: stable@vger.kernel.org
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Tested-by: Carlos Santa <carlos.santa@intel.com> (v1)
Tested-by: Kirill A. Shutemov <kirill@shutemov.name> (v1)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97666Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1477492878-4990-1-git-send-email-ville.syrjala@linux.intel.com
parent 38d868e4
...@@ -608,6 +608,24 @@ int drm_fb_helper_blank(int blank, struct fb_info *info) ...@@ -608,6 +608,24 @@ int drm_fb_helper_blank(int blank, struct fb_info *info)
} }
EXPORT_SYMBOL(drm_fb_helper_blank); EXPORT_SYMBOL(drm_fb_helper_blank);
static void drm_fb_helper_modeset_release(struct drm_fb_helper *helper,
struct drm_mode_set *modeset)
{
int i;
for (i = 0; i < modeset->num_connectors; i++) {
drm_connector_unreference(modeset->connectors[i]);
modeset->connectors[i] = NULL;
}
modeset->num_connectors = 0;
drm_mode_destroy(helper->dev, modeset->mode);
modeset->mode = NULL;
/* FIXME should hold a ref? */
modeset->fb = NULL;
}
static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
{ {
int i; int i;
...@@ -617,10 +635,12 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) ...@@ -617,10 +635,12 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
kfree(helper->connector_info[i]); kfree(helper->connector_info[i]);
} }
kfree(helper->connector_info); kfree(helper->connector_info);
for (i = 0; i < helper->crtc_count; i++) { for (i = 0; i < helper->crtc_count; i++) {
kfree(helper->crtc_info[i].mode_set.connectors); struct drm_mode_set *modeset = &helper->crtc_info[i].mode_set;
if (helper->crtc_info[i].mode_set.mode)
drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode); drm_fb_helper_modeset_release(helper, modeset);
kfree(modeset->connectors);
} }
kfree(helper->crtc_info); kfree(helper->crtc_info);
} }
...@@ -2095,7 +2115,6 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) ...@@ -2095,7 +2115,6 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
struct drm_fb_helper_crtc **crtcs; struct drm_fb_helper_crtc **crtcs;
struct drm_display_mode **modes; struct drm_display_mode **modes;
struct drm_fb_offset *offsets; struct drm_fb_offset *offsets;
struct drm_mode_set *modeset;
bool *enabled; bool *enabled;
int width, height; int width, height;
int i; int i;
...@@ -2143,45 +2162,35 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) ...@@ -2143,45 +2162,35 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
/* need to set the modesets up here for use later */ /* need to set the modesets up here for use later */
/* fill out the connector<->crtc mappings into the modesets */ /* fill out the connector<->crtc mappings into the modesets */
for (i = 0; i < fb_helper->crtc_count; i++) { for (i = 0; i < fb_helper->crtc_count; i++)
modeset = &fb_helper->crtc_info[i].mode_set; drm_fb_helper_modeset_release(fb_helper,
modeset->num_connectors = 0; &fb_helper->crtc_info[i].mode_set);
modeset->fb = NULL;
}
for (i = 0; i < fb_helper->connector_count; i++) { for (i = 0; i < fb_helper->connector_count; i++) {
struct drm_display_mode *mode = modes[i]; struct drm_display_mode *mode = modes[i];
struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
struct drm_fb_offset *offset = &offsets[i]; struct drm_fb_offset *offset = &offsets[i];
modeset = &fb_crtc->mode_set; struct drm_mode_set *modeset = &fb_crtc->mode_set;
if (mode && fb_crtc) { if (mode && fb_crtc) {
struct drm_connector *connector =
fb_helper->connector_info[i]->connector;
DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n", DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y); mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y);
fb_crtc->desired_mode = mode; fb_crtc->desired_mode = mode;
fb_crtc->x = offset->x; fb_crtc->x = offset->x;
fb_crtc->y = offset->y; fb_crtc->y = offset->y;
if (modeset->mode)
drm_mode_destroy(dev, modeset->mode);
modeset->mode = drm_mode_duplicate(dev, modeset->mode = drm_mode_duplicate(dev,
fb_crtc->desired_mode); fb_crtc->desired_mode);
modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; drm_connector_reference(connector);
modeset->connectors[modeset->num_connectors++] = connector;
modeset->fb = fb_helper->fb; modeset->fb = fb_helper->fb;
modeset->x = offset->x; modeset->x = offset->x;
modeset->y = offset->y; modeset->y = offset->y;
} }
} }
/* Clear out any old modes if there are no more connected outputs. */
for (i = 0; i < fb_helper->crtc_count; i++) {
modeset = &fb_helper->crtc_info[i].mode_set;
if (modeset->num_connectors == 0) {
BUG_ON(modeset->fb);
if (modeset->mode)
drm_mode_destroy(dev, modeset->mode);
modeset->mode = NULL;
}
}
out: out:
kfree(crtcs); kfree(crtcs);
kfree(modes); kfree(modes);
......
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