Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -77,15 +77,16 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
	size = min_t(unsigned int, size, tbl->size >> 1);

	if (sizeof(spinlock_t) != 0) {
		tbl->locks = NULL;
#ifdef CONFIG_NUMA
		if (size * sizeof(spinlock_t) > PAGE_SIZE &&
		    gfp == GFP_KERNEL)
			tbl->locks = vmalloc(size * sizeof(spinlock_t));
		else
#endif
		if (gfp != GFP_KERNEL)
			gfp |= __GFP_NOWARN | __GFP_NORETRY;

		if (!tbl->locks)
			tbl->locks = kmalloc_array(size, sizeof(spinlock_t),
						   gfp);
		if (!tbl->locks)