Skip to content

Commit

Permalink
drm/i915: Improve how the memory for crtc state is allocated
Browse files Browse the repository at this point in the history
The previous patch changed the config field in intel_crtc to a pointer,
but to keep the mechanical changes (done with spatch) separate from the
new code, the pointer was made to point to a new _config field with type
struct intel_crtc_state added to that struct. This patch improves that
code by getting rid of that field, allocating a state struct in
intel_crtc_init() a keeping it properly updated when a mode set
happens.

v2: Manual changes split from previous patch. (Matt)
    Don't leak the current state when the crtc is destroyed (Matt)

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
[danvet: Squash in fixup from Matt Roper for driver unload.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  • Loading branch information
Ander Conselvan de Oliveira authored and Daniel Vetter committed Jan 27, 2015
1 parent 6e3c971 commit f5de6e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 16 additions & 4 deletions drivers/gpu/drm/i915/intel_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -8926,6 +8926,13 @@ void intel_mark_idle(struct drm_device *dev)
intel_runtime_pm_put(dev_priv);
}

static void intel_crtc_set_state(struct intel_crtc *crtc,
struct intel_crtc_state *crtc_state)
{
kfree(crtc->config);
crtc->config = crtc_state;
}

static void intel_crtc_destroy(struct drm_crtc *crtc)
{
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Expand All @@ -8942,6 +8949,7 @@ static void intel_crtc_destroy(struct drm_crtc *crtc)
kfree(work);
}

intel_crtc_set_state(intel_crtc, NULL);
drm_crtc_cleanup(crtc);

kfree(intel_crtc);
Expand Down Expand Up @@ -10995,8 +11003,7 @@ static int __intel_set_mode(struct drm_crtc *crtc,
crtc->mode = *mode;
/* mode_set/enable/disable functions rely on a correct pipe
* config. */
(*(to_intel_crtc(crtc)->config)) = *pipe_config;
to_intel_crtc(crtc)->new_config = to_intel_crtc(crtc)->config;
intel_crtc_set_state(to_intel_crtc(crtc), pipe_config);

/*
* Calculate and store various constants which
Expand Down Expand Up @@ -11040,7 +11047,6 @@ static int __intel_set_mode(struct drm_crtc *crtc,
if (ret && crtc->enabled)
crtc->mode = *saved_mode;

kfree(pipe_config);
kfree(saved_mode);
return ret;
}
Expand Down Expand Up @@ -12186,6 +12192,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
{
struct drm_i915_private *dev_priv = dev->dev_private;
struct intel_crtc *intel_crtc;
struct intel_crtc_state *crtc_state = NULL;
struct drm_plane *primary = NULL;
struct drm_plane *cursor = NULL;
int i, ret;
Expand All @@ -12194,6 +12201,11 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
if (intel_crtc == NULL)
return;

crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
if (!crtc_state)
goto fail;
intel_crtc_set_state(intel_crtc, crtc_state);

primary = intel_primary_plane_create(dev, pipe);
if (!primary)
goto fail;
Expand Down Expand Up @@ -12239,14 +12251,14 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);

WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
intel_crtc->config = &intel_crtc->_config;
return;

fail:
if (primary)
drm_plane_cleanup(primary);
if (cursor)
drm_plane_cleanup(cursor);
kfree(crtc_state);
kfree(intel_crtc);
}

Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/i915/intel_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ struct intel_crtc {
uint32_t cursor_base;

struct intel_plane_config plane_config;
struct intel_crtc_state _config;
struct intel_crtc_state *config;
struct intel_crtc_state *new_config;
bool new_enabled;
Expand Down

0 comments on commit f5de6e0

Please sign in to comment.