drm: Correct unbalanced drm_vblank_put() during mode setting.
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 19 Feb 2009 14:48:22 +0000 (14:48 +0000)
committerDave Airlie <airlied@linux.ie>
Wed, 25 Feb 2009 04:45:50 +0000 (14:45 +1000)
The first time we install a mode, the vblank will be disabled for a pipe
and so drm_vblank_get() in drm_vblank_pre_modeset() will fail. As we
unconditionally call drm_vblank_put() afterwards, the vblank reference
counter becomes unbalanced.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: Dave Airlie <airlied@linux.ie>
drivers/gpu/drm/drm_irq.c

index 3795dbc0f50cff99b167fc0659f0d0862c8d57d5..93e677a481f5388f380bc86547297e8f87bddbb0 100644 (file)
@@ -435,6 +435,8 @@ EXPORT_SYMBOL(drm_vblank_get);
  */
 void drm_vblank_put(struct drm_device *dev, int crtc)
 {
+       BUG_ON (atomic_read (&dev->vblank_refcount[crtc]) == 0);
+
        /* Last user schedules interrupt disable */
        if (atomic_dec_and_test(&dev->vblank_refcount[crtc]))
                mod_timer(&dev->vblank_disable_timer, jiffies + 5*DRM_HZ);
@@ -460,8 +462,9 @@ void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
         * so that interrupts remain enabled in the interim.
         */
        if (!dev->vblank_inmodeset[crtc]) {
-               dev->vblank_inmodeset[crtc] = 1;
-               drm_vblank_get(dev, crtc);
+               dev->vblank_inmodeset[crtc] = 0x1;
+               if (drm_vblank_get(dev, crtc) == 0)
+                       dev->vblank_inmodeset[crtc] |= 0x2;
        }
 }
 EXPORT_SYMBOL(drm_vblank_pre_modeset);
@@ -473,9 +476,12 @@ void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
        if (dev->vblank_inmodeset[crtc]) {
                spin_lock_irqsave(&dev->vbl_lock, irqflags);
                dev->vblank_disable_allowed = 1;
-               dev->vblank_inmodeset[crtc] = 0;
                spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
-               drm_vblank_put(dev, crtc);
+
+               if (dev->vblank_inmodeset[crtc] & 0x2)
+                       drm_vblank_put(dev, crtc);
+
+               dev->vblank_inmodeset[crtc] = 0;
        }
 }
 EXPORT_SYMBOL(drm_vblank_post_modeset);