netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] libcxgb: fix incorrect ppmax calculation
@ 2019-04-03 12:00 Varun Prakash
  2019-04-05  0:41 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Varun Prakash @ 2019-04-03 12:00 UTC (permalink / raw)
  To: davem; +Cc: netdev, dt, indranil, varun

BITS_TO_LONGS() uses DIV_ROUND_UP() because of
this ppmax value can be greater than available
per cpu page pods.

This patch removes BITS_TO_LONGS() to fix this
issue.

Signed-off-by: Varun Prakash <varun@chelsio.com>
---
 drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
index 74849be5f004..e2919005ead3 100644
--- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
+++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
@@ -354,7 +354,10 @@ static struct cxgbi_ppm_pool *ppm_alloc_cpu_pool(unsigned int *total,
 		ppmax = max;
 
 	/* pool size must be multiple of unsigned long */
-	bmap = BITS_TO_LONGS(ppmax);
+	bmap = ppmax / BITS_PER_TYPE(unsigned long);
+	if (!bmap)
+		return NULL;
+
 	ppmax = (bmap * sizeof(unsigned long)) << 3;
 
 	alloc_sz = sizeof(*pools) + sizeof(unsigned long) * bmap;
@@ -402,6 +405,10 @@ int cxgbi_ppm_init(void **ppm_pp, struct net_device *ndev,
 	if (reserve_factor) {
 		ppmax_pool = ppmax / reserve_factor;
 		pool = ppm_alloc_cpu_pool(&ppmax_pool, &pool_index_max);
+		if (!pool) {
+			ppmax_pool = 0;
+			reserve_factor = 0;
+		}
 
 		pr_debug("%s: ppmax %u, cpu total %u, per cpu %u.\n",
 			 ndev->name, ppmax, ppmax_pool, pool_index_max);
-- 
2.0.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] libcxgb: fix incorrect ppmax calculation
  2019-04-03 12:00 [PATCH net] libcxgb: fix incorrect ppmax calculation Varun Prakash
@ 2019-04-05  0:41 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-04-05  0:41 UTC (permalink / raw)
  To: varun; +Cc: netdev, dt, indranil

From: Varun Prakash <varun@chelsio.com>
Date: Wed,  3 Apr 2019 17:30:14 +0530

> BITS_TO_LONGS() uses DIV_ROUND_UP() because of
> this ppmax value can be greater than available
> per cpu page pods.
> 
> This patch removes BITS_TO_LONGS() to fix this
> issue.
> 
> Signed-off-by: Varun Prakash <varun@chelsio.com>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-05  0:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-03 12:00 [PATCH net] libcxgb: fix incorrect ppmax calculation Varun Prakash
2019-04-05  0:41 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).