Skip to content

Commit

Permalink
drm/irq: Check for valid VBLANK before dereference
Browse files Browse the repository at this point in the history
When accessing the array of per-CRTC VBLANK structures we must always
check that the index into the array is valid before dereferencing to
avoid crashing.

Signed-off-by: Thierry Reding <[email protected]>
[danvet: Squash in my own whitespace ocd fixup in drm_vblank_count.]
Signed-off-by: Daniel Vetter <[email protected]>
  • Loading branch information
thierryreding authored and danvet committed Aug 12, 2015
1 parent 2a7d3d6 commit 7d1de85
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/gpu/drm/drm_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ u32 drm_vblank_count(struct drm_device *dev, int crtc)

if (WARN_ON(crtc >= dev->num_crtcs))
return 0;

return vblank->count;
}
EXPORT_SYMBOL(drm_vblank_count);
Expand Down Expand Up @@ -1110,10 +1111,10 @@ void drm_vblank_put(struct drm_device *dev, int crtc)
{
struct drm_vblank_crtc *vblank = &dev->vblank[crtc];

if (WARN_ON(atomic_read(&vblank->refcount) == 0))
if (WARN_ON(crtc >= dev->num_crtcs))
return;

if (WARN_ON(crtc >= dev->num_crtcs))
if (WARN_ON(atomic_read(&vblank->refcount) == 0))
return;

/* Last user schedules interrupt disable */
Expand Down Expand Up @@ -1158,6 +1159,9 @@ void drm_wait_one_vblank(struct drm_device *dev, int crtc)
int ret;
u32 last;

if (WARN_ON(crtc >= dev->num_crtcs))
return;

ret = drm_vblank_get(dev, crtc);
if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", crtc, ret))
return;
Expand Down Expand Up @@ -1428,6 +1432,9 @@ void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
if (!dev->num_crtcs)
return;

if (WARN_ON(crtc >= dev->num_crtcs))
return;

if (vblank->inmodeset) {
spin_lock_irqsave(&dev->vbl_lock, irqflags);
dev->vblank_disable_allowed = true;
Expand Down

0 comments on commit 7d1de85

Please sign in to comment.