[net] cnic: tidy up a size calculation
diff mbox series

Message ID 20180628093125.6qamire66fzkv47l@kili.mountain
State Accepted, archived
Delegated to: David Miller
Headers show
Series
  • [net] cnic: tidy up a size calculation
Related show

Commit Message

Dan Carpenter June 28, 2018, 9:31 a.m. UTC
Static checkers complain that id_tbl->table points to longs and 4 bytes
is smaller than sizeof(long).  But the since other side is dividing by
32 instead of sizeof(long), that means the current code works fine.

Anyway, it's more conventional to use the BITS_TO_LONGS() macro when
we're allocating a bitmap.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

David Miller June 30, 2018, 9:47 a.m. UTC | #1
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Thu, 28 Jun 2018 12:31:25 +0300

> Static checkers complain that id_tbl->table points to longs and 4 bytes
> is smaller than sizeof(long).  But the since other side is dividing by
> 32 instead of sizeof(long), that means the current code works fine.
> 
> Anyway, it's more conventional to use the BITS_TO_LONGS() macro when
> we're allocating a bitmap.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied.

Patch
diff mbox series

diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c
index 30273a7717e2..4fd829b5e65d 100644
--- a/drivers/net/ethernet/broadcom/cnic.c
+++ b/drivers/net/ethernet/broadcom/cnic.c
@@ -660,7 +660,7 @@  static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id,
 	id_tbl->max = size;
 	id_tbl->next = next;
 	spin_lock_init(&id_tbl->lock);
-	id_tbl->table = kcalloc(DIV_ROUND_UP(size, 32), 4, GFP_KERNEL);
+	id_tbl->table = kcalloc(BITS_TO_LONGS(size), sizeof(long), GFP_KERNEL);
 	if (!id_tbl->table)
 		return -ENOMEM;