All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Schmidt <mschmidt@redhat.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, ariele@broadcom.com, dmitry@broadcom.com,
	yuvalmin@broadcom.com
Subject: [PATCH net-next 1/3] bnx2x: clamp num_queues to prevent passing a negative value
Date: Tue, 25 Feb 2014 16:04:24 +0100	[thread overview]
Message-ID: <1393340666-3539-2-git-send-email-mschmidt@redhat.com> (raw)
In-Reply-To: <1393340666-3539-1-git-send-email-mschmidt@redhat.com>

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>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 5ee13af..64c17b6 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -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;
 }
 
 /**
-- 
1.8.5.3

  reply	other threads:[~2014-02-25 15:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-25 15:04 [PATCH net-next 0/3] bnx2x: minimize RAM usage in kdump Michal Schmidt
2014-02-25 15:04 ` Michal Schmidt [this message]
2014-02-25 15:04 ` [PATCH net-next 2/3] bnx2x: save RAM in kdump kernel by using a single queue Michal Schmidt
2014-02-25 15:04 ` [PATCH net-next 3/3] bnx2x: save RAM in kdump kernel by disabling TPA Michal Schmidt
2014-02-25 16:41 ` [PATCH net-next 0/3] bnx2x: minimize RAM usage in kdump Ariel Elior
2014-02-26 20:28   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393340666-3539-2-git-send-email-mschmidt@redhat.com \
    --to=mschmidt@redhat.com \
    --cc=ariele@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=dmitry@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=yuvalmin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.