bnx2x: clamp num_queues to prevent passing a negative value
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 25 Feb 2014 15:04:24 +0000 (16:04 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 26 Feb 2014 20:27:50 +0000 (15:27 -0500)
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>
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c

index 89d75c24335c35a4fb68f880ebe6da712fa4a5bc..34d124998823da09dd09fcdd2d5278913479ad4e 100644 (file)
@@ -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;
 }
 
 /**