bnx2x: clamp num_queues to prevent passing a negative value

Use the clamp() macro to make the calculation of the number of queues
slightly easier to understand. It also avoids a crash when someone
accidentally passes a negative value in num_queues= module parameter.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Michal Schmidt 2014-02-25 16:04:24 +01:00 committed by David S. Miller
parent 8e165e2034
commit 7d0445d66a
1 changed files with 3 additions and 4 deletions

View File

@ -61,10 +61,9 @@ static void bnx2x_add_all_napi(struct bnx2x *bp)
static int bnx2x_calc_num_queues(struct bnx2x *bp) static int bnx2x_calc_num_queues(struct bnx2x *bp)
{ {
return bnx2x_num_queues ? int nq = bnx2x_num_queues ? : netif_get_num_default_rss_queues();
min_t(int, bnx2x_num_queues, BNX2X_MAX_QUEUES(bp)) : nq = clamp(nq, 1, BNX2X_MAX_QUEUES(bp));
min_t(int, netif_get_num_default_rss_queues(), return nq;
BNX2X_MAX_QUEUES(bp));
} }
/** /**