Skip to content

Commit

Permalink
bnx2x: clamp num_queues to prevent passing a negative value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michal Schmidt authored and David S. Miller committed Feb 26, 2014
1 parent 8e165e2 commit 7d0445d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ static void bnx2x_add_all_napi(struct bnx2x *bp)

static int bnx2x_calc_num_queues(struct bnx2x *bp)
{
return bnx2x_num_queues ?
min_t(int, bnx2x_num_queues, BNX2X_MAX_QUEUES(bp)) :
min_t(int, netif_get_num_default_rss_queues(),
BNX2X_MAX_QUEUES(bp));
int nq = bnx2x_num_queues ? : netif_get_num_default_rss_queues();
nq = clamp(nq, 1, BNX2X_MAX_QUEUES(bp));
return nq;
}

/**
Expand Down

0 comments on commit 7d0445d

Please sign in to comment.