Skip to content

Commit cc5a726

Browse files
Varun Prakashdavem330
authored andcommitted
libcxgb: fix incorrect ppmax calculation
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0a89eb9 commit cc5a726

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ static struct cxgbi_ppm_pool *ppm_alloc_cpu_pool(unsigned int *total,
354354
ppmax = max;
355355

356356
/* pool size must be multiple of unsigned long */
357-
bmap = BITS_TO_LONGS(ppmax);
357+
bmap = ppmax / BITS_PER_TYPE(unsigned long);
358+
if (!bmap)
359+
return NULL;
360+
358361
ppmax = (bmap * sizeof(unsigned long)) << 3;
359362

360363
alloc_sz = sizeof(*pools) + sizeof(unsigned long) * bmap;
@@ -402,6 +405,10 @@ int cxgbi_ppm_init(void **ppm_pp, struct net_device *ndev,
402405
if (reserve_factor) {
403406
ppmax_pool = ppmax / reserve_factor;
404407
pool = ppm_alloc_cpu_pool(&ppmax_pool, &pool_index_max);
408+
if (!pool) {
409+
ppmax_pool = 0;
410+
reserve_factor = 0;
411+
}
405412

406413
pr_debug("%s: ppmax %u, cpu total %u, per cpu %u.\n",
407414
ndev->name, ppmax, ppmax_pool, pool_index_max);

0 commit comments

Comments
 (0)