Commit 9dbeea7f authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

rhashtable: fix a memory leak in alloc_bucket_locks()

If vmalloc() was successful, do not attempt a kmalloc_array()

Fixes: 4cf0b354 ("rhashtable: avoid large lock-array allocations")
Reported-by: default avatarCAI Qian <caiqian@redhat.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Florian Westphal <fw@strlen.de>
Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Tested-by: default avatarCAI Qian <caiqian@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e70c70c3
...@@ -77,17 +77,18 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl, ...@@ -77,17 +77,18 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
size = min_t(unsigned int, size, tbl->size >> 1); size = min_t(unsigned int, size, tbl->size >> 1);
if (sizeof(spinlock_t) != 0) { if (sizeof(spinlock_t) != 0) {
tbl->locks = NULL;
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
if (size * sizeof(spinlock_t) > PAGE_SIZE && if (size * sizeof(spinlock_t) > PAGE_SIZE &&
gfp == GFP_KERNEL) gfp == GFP_KERNEL)
tbl->locks = vmalloc(size * sizeof(spinlock_t)); tbl->locks = vmalloc(size * sizeof(spinlock_t));
else
#endif #endif
if (gfp != GFP_KERNEL) if (gfp != GFP_KERNEL)
gfp |= __GFP_NOWARN | __GFP_NORETRY; gfp |= __GFP_NOWARN | __GFP_NORETRY;
tbl->locks = kmalloc_array(size, sizeof(spinlock_t), if (!tbl->locks)
gfp); tbl->locks = kmalloc_array(size, sizeof(spinlock_t),
gfp);
if (!tbl->locks) if (!tbl->locks)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
......
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