Skip to content

Commit

Permalink
drm/ttm: Fix possible division by 0 in ttm_dma_pool_shrink_scan().
Browse files Browse the repository at this point in the history
list_empty(&_manager->pools) being false before taking _manager->lock
does not guarantee that _manager->npools != 0 after taking _manager->lock
because _manager->npools is updated under _manager->lock.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: stable <stable@kernel.org> [3.3+]
Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Tetsuo Handa authored and Dave Airlie committed Aug 5, 2014
1 parent 74cd62e commit 11e504c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
return SHRINK_STOP;

mutex_lock(&_manager->lock);
if (!_manager->npools)
goto out;
pool_offset = pool_offset % _manager->npools;
list_for_each_entry(p, &_manager->pools, pools) {
unsigned nr_free;
Expand All @@ -1034,6 +1036,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
p->pool->dev_name, p->pool->name, current->pid,
nr_free, shrink_pages);
}
out:
mutex_unlock(&_manager->lock);
return freed;
}
Expand Down

0 comments on commit 11e504c

Please sign in to comment.