Commit 11e504cc authored by Tetsuo Handa's avatar Tetsuo Handa Committed by Dave Airlie

drm/ttm: Fix possible division by 0 in ttm_dma_pool_shrink_scan().

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: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: stable <stable@kernel.org> [3.3+]
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 74cd62ea
...@@ -1015,6 +1015,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) ...@@ -1015,6 +1015,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
return SHRINK_STOP; return SHRINK_STOP;
mutex_lock(&_manager->lock); mutex_lock(&_manager->lock);
if (!_manager->npools)
goto out;
pool_offset = pool_offset % _manager->npools; pool_offset = pool_offset % _manager->npools;
list_for_each_entry(p, &_manager->pools, pools) { list_for_each_entry(p, &_manager->pools, pools) {
unsigned nr_free; unsigned nr_free;
...@@ -1034,6 +1036,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) ...@@ -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, p->pool->dev_name, p->pool->name, current->pid,
nr_free, shrink_pages); nr_free, shrink_pages);
} }
out:
mutex_unlock(&_manager->lock); mutex_unlock(&_manager->lock);
return freed; return freed;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment