Commit 28134a53 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

rhashtable: Fix potential crash on destroy in rhashtable_shrink

The current being_destroyed check in rhashtable_expand is not
enough since if we start a shrinking process after freeing all
elements in the table that's also going to crash.

This patch adds a being_destroyed check to the deferred worker
thread so that we bail out as soon as we take the lock.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9b55669c
...@@ -487,6 +487,9 @@ static void rht_deferred_worker(struct work_struct *work) ...@@ -487,6 +487,9 @@ static void rht_deferred_worker(struct work_struct *work)
ht = container_of(work, struct rhashtable, run_work); ht = container_of(work, struct rhashtable, run_work);
mutex_lock(&ht->mutex); mutex_lock(&ht->mutex);
if (ht->being_destroyed)
goto unlock;
tbl = rht_dereference(ht->tbl, ht); tbl = rht_dereference(ht->tbl, ht);
if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size)) if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
...@@ -494,6 +497,7 @@ static void rht_deferred_worker(struct work_struct *work) ...@@ -494,6 +497,7 @@ static void rht_deferred_worker(struct work_struct *work)
else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size)) else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
rhashtable_shrink(ht); rhashtable_shrink(ht);
unlock:
mutex_unlock(&ht->mutex); mutex_unlock(&ht->mutex);
} }
......
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