Commit b388fc74 authored by Gregory CLEMENT's avatar Gregory CLEMENT Committed by David S. Miller

net: hwbm: Fix unbalanced spinlock in error case

When hwbm_pool_add exited in error the spinlock was not released. This
patch fixes this issue.

Fixes: 8cb2d8bf ("net: add a hardware buffer management helper API")
Reported-by: default avatarJean-Jacques Hiblot <jjhiblot@traphandler.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarGregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 91c45e38
...@@ -55,18 +55,21 @@ int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num, gfp_t gfp) ...@@ -55,18 +55,21 @@ int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num, gfp_t gfp)
spin_lock_irqsave(&bm_pool->lock, flags); spin_lock_irqsave(&bm_pool->lock, flags);
if (bm_pool->buf_num == bm_pool->size) { if (bm_pool->buf_num == bm_pool->size) {
pr_warn("pool already filled\n"); pr_warn("pool already filled\n");
spin_unlock_irqrestore(&bm_pool->lock, flags);
return bm_pool->buf_num; return bm_pool->buf_num;
} }
if (buf_num + bm_pool->buf_num > bm_pool->size) { if (buf_num + bm_pool->buf_num > bm_pool->size) {
pr_warn("cannot allocate %d buffers for pool\n", pr_warn("cannot allocate %d buffers for pool\n",
buf_num); buf_num);
spin_unlock_irqrestore(&bm_pool->lock, flags);
return 0; return 0;
} }
if ((buf_num + bm_pool->buf_num) < bm_pool->buf_num) { if ((buf_num + bm_pool->buf_num) < bm_pool->buf_num) {
pr_warn("Adding %d buffers to the %d current buffers will overflow\n", pr_warn("Adding %d buffers to the %d current buffers will overflow\n",
buf_num, bm_pool->buf_num); buf_num, bm_pool->buf_num);
spin_unlock_irqrestore(&bm_pool->lock, flags);
return 0; return 0;
} }
......
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