aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTim Gardner <tim.gardner@canonical.com>2012-12-07 09:54:26 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2012-12-10 04:13:35 -0500
commit3ac18232946aacf0a9807c3143f8449ed4aa68f4 (patch)
treee84d135a791f856002505e6ac039a28db42c64a4 /drivers
parent378a6a77ae59d3312627b996ded94e23166d9e63 (diff)
i915: intel_set_mode: Reduce stack allocation from 500 bytes to 2 pointers
smatch warning: drivers/gpu/drm/i915/intel_display.c:7019 intel_set_mode() warn: function puts 500 bytes on stack Refactor so that saved_mode and saved_hwmode are dynamically allocated as opposed to being automatic variables. 500 bytes seems like it could run the potential for blowing the kernel stack. Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: David Airlie <airlied@linux.ie> Cc: dri-devel@lists.freedesktop.org Signed-off-by: Tim Gardner <tim.gardner@canonical.com> Reviewed-by: Jani Nikula <jani.nikula@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/i915/intel_display.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 34832bc04931..115bf626037c 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -7398,11 +7398,18 @@ bool intel_set_mode(struct drm_crtc *crtc,
7398{ 7398{
7399 struct drm_device *dev = crtc->dev; 7399 struct drm_device *dev = crtc->dev;
7400 drm_i915_private_t *dev_priv = dev->dev_private; 7400 drm_i915_private_t *dev_priv = dev->dev_private;
7401 struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode; 7401 struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
7402 struct intel_crtc *intel_crtc; 7402 struct intel_crtc *intel_crtc;
7403 unsigned disable_pipes, prepare_pipes, modeset_pipes; 7403 unsigned disable_pipes, prepare_pipes, modeset_pipes;
7404 bool ret = true; 7404 bool ret = true;
7405 7405
7406 saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
7407 if (!saved_mode) {
7408 DRM_ERROR("i915: Could not allocate saved display mode.\n");
7409 return false;
7410 }
7411 saved_hwmode = saved_mode + 1;
7412
7406 intel_modeset_affected_pipes(crtc, &modeset_pipes, 7413 intel_modeset_affected_pipes(crtc, &modeset_pipes,
7407 &prepare_pipes, &disable_pipes); 7414 &prepare_pipes, &disable_pipes);
7408 7415
@@ -7412,8 +7419,8 @@ bool intel_set_mode(struct drm_crtc *crtc,
7412 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) 7419 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7413 intel_crtc_disable(&intel_crtc->base); 7420 intel_crtc_disable(&intel_crtc->base);
7414 7421
7415 saved_hwmode = crtc->hwmode; 7422 *saved_hwmode = crtc->hwmode;
7416 saved_mode = crtc->mode; 7423 *saved_mode = crtc->mode;
7417 7424
7418 /* Hack: Because we don't (yet) support global modeset on multiple 7425 /* Hack: Because we don't (yet) support global modeset on multiple
7419 * crtcs, we don't keep track of the new mode for more than one crtc. 7426 * crtcs, we don't keep track of the new mode for more than one crtc.
@@ -7424,7 +7431,8 @@ bool intel_set_mode(struct drm_crtc *crtc,
7424 if (modeset_pipes) { 7431 if (modeset_pipes) {
7425 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode); 7432 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7426 if (IS_ERR(adjusted_mode)) { 7433 if (IS_ERR(adjusted_mode)) {
7427 return false; 7434 ret = false;
7435 goto out;
7428 } 7436 }
7429 } 7437 }
7430 7438
@@ -7476,12 +7484,14 @@ bool intel_set_mode(struct drm_crtc *crtc,
7476done: 7484done:
7477 drm_mode_destroy(dev, adjusted_mode); 7485 drm_mode_destroy(dev, adjusted_mode);
7478 if (!ret && crtc->enabled) { 7486 if (!ret && crtc->enabled) {
7479 crtc->hwmode = saved_hwmode; 7487 crtc->hwmode = *saved_hwmode;
7480 crtc->mode = saved_mode; 7488 crtc->mode = *saved_mode;
7481 } else { 7489 } else {
7482 intel_modeset_check_state(dev); 7490 intel_modeset_check_state(dev);
7483 } 7491 }
7484 7492
7493out:
7494 kfree(saved_mode);
7485 return ret; 7495 return ret;
7486} 7496}
7487 7497