netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v1] octeontx2-af: Initialize bitmap arrays.
@ 2024-01-25  6:34 Ratheesh Kannoth
  2024-01-25 11:41 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Ratheesh Kannoth @ 2024-01-25  6:34 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: sgoutham, davem, edumazet, kuba, pabeni, sbhatta, gakula, hkelam,
	bcreeley, sumang, Ratheesh Kannoth

kmalloc_array() without __GFP_ZERO flag does not initializes
memory to zero.  This causes issues with bitmap. Use __GFP_ZERO
to fix the issue.

Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>

ChangeLogs:
v0 -> v1: Removed devm_kcalloc()._
---
 .../ethernet/marvell/octeontx2/af/rvu_npc.c   | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
index 167145bdcb75..b56def17a2ba 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -1905,12 +1905,13 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 
 	/* Allocate bitmaps for managing MCAM entries */
 	mcam->bmap = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
-				   sizeof(long), GFP_KERNEL);
+				   sizeof(long), GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->bmap)
 		return -ENOMEM;
 
 	mcam->bmap_reverse = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
-					   sizeof(long), GFP_KERNEL);
+					   sizeof(long),
+					   GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->bmap_reverse)
 		goto free_bmap;
 
@@ -1918,7 +1919,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 
 	/* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
 	mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
-					     sizeof(u16), GFP_KERNEL);
+					     sizeof(u16),
+					     GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->entry2pfvf_map)
 		goto free_bmap_reverse;
 
@@ -1942,7 +1944,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 		goto free_entry_map;
 
 	mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
-					    sizeof(u16), GFP_KERNEL);
+					    sizeof(u16),
+					    GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->cntr2pfvf_map)
 		goto free_cntr_bmap;
 
@@ -1950,18 +1953,21 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 	 * counter's reference count.
 	 */
 	mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
-					     sizeof(u16), GFP_KERNEL);
+					     sizeof(u16),
+					     GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->entry2cntr_map)
 		goto free_cntr_map;
 
 	mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
-					  sizeof(u16), GFP_KERNEL);
+					  sizeof(u16),
+					  GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->cntr_refcnt)
 		goto free_entry_cntr_map;
 
 	/* Alloc memory for saving target device of mcam rule */
 	mcam->entry2target_pffunc = kmalloc_array(mcam->total_entries,
-						  sizeof(u16), GFP_KERNEL);
+						  sizeof(u16),
+						  GFP_KERNEL | __GFP_ZERO);
 	if (!mcam->entry2target_pffunc)
 		goto free_cntr_refcnt;
 
-- 
2.25.1


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

* Re: [PATCH net v1] octeontx2-af: Initialize bitmap arrays.
  2024-01-25  6:34 [PATCH net v1] octeontx2-af: Initialize bitmap arrays Ratheesh Kannoth
@ 2024-01-25 11:41 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2024-01-25 11:41 UTC (permalink / raw)
  To: Ratheesh Kannoth
  Cc: netdev, linux-kernel, sgoutham, davem, edumazet, kuba, pabeni,
	sbhatta, gakula, hkelam, bcreeley, sumang

On Thu, Jan 25, 2024 at 12:04:14PM +0530, Ratheesh Kannoth wrote:
> kmalloc_array() without __GFP_ZERO flag does not initializes
> memory to zero.  This causes issues with bitmap. Use __GFP_ZERO
> to fix the issue.
> 
> Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
> 
> ChangeLogs:
> v0 -> v1: Removed devm_kcalloc()._

Hi Ratheesh,

sorry for missing this in my first review,
but perhaps it is better to use bitmap_zalloc() and bitmap_free()
as suggested by Brett Creeley.

Link: https://lore.kernel.org/all/cf035125-d7fb-4423-8f64-a5be7505243d@amd.com/

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

end of thread, other threads:[~2024-01-25 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-25  6:34 [PATCH net v1] octeontx2-af: Initialize bitmap arrays Ratheesh Kannoth
2024-01-25 11:41 ` Simon Horman

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).