Skip to contentSkip to conversation

octeontx2-af: CGX: use kzalloc_flex for name

PATCH In review Rosen Penev 3 participants 3 messages Mar 13 – Mar 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 octeontx2-af: CGX: use kzalloc_flex for name

Don't bother allocating separately. There's no good reason to do so for a small string like this.

Remove name kfrees as a result.

---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c     | 13 +++----------
 .../net/ethernet/marvell/octeontx2/af/lmac_common.h |  2 +-
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +3 -10
index 4f33a816bc7a..0750fb696c90 100644
@@ -1725,14 +1725,10 @@ static int cgx_lmac_init(struct cgx *cgx)
 		cgx->lmac_count = cgx->max_lmac_per_mac;
 
 	for (i = 0; i < cgx->lmac_count; i++) {
-		lmac = kzalloc_obj(struct lmac);
+		lmac = kzalloc_flex(struct lmac, name, sizeof("cgx_fwi_xxx_yyy"));
 		if (!lmac)
 			return -ENOMEM;
-		lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL);
-		if (!lmac->name) {
-			err = -ENOMEM;
-			goto err_lmac_free;
-		}
+
 		sprintf(lmac->name, "cgx_fwi_%u_%u", cgx->cgx_id, i);
 		if (cgx->mac_ops->non_contiguous_serdes_lane) {
 			lmac->lmac_id = __ffs64(lmac_list);
@@ -1750,7 +1746,7 @@ static int cgx_lmac_init(struct cgx *cgx)
 
 		err = rvu_alloc_bitmap(&lmac->mac_to_index_bmap);
 		if (err)
-			goto err_name_free;
+			goto err_lmac_free;
 
 		/* Reserve first entry for default MAC address */
 		set_bit(0, lmac->mac_to_index_bmap.bmap);
@@ -1798,8 +1794,6 @@ static int cgx_lmac_init(struct cgx *cgx)
 	rvu_free_bitmap(&lmac->rx_fc_pfvf_bmap);
 err_dmac_bmap_free:
 	rvu_free_bitmap(&lmac->mac_to_index_bmap);
-err_name_free:
-	kfree(lmac->name);
 err_lmac_free:
 	kfree(lmac);
 	return err;
@@ -1825,7 +1819,6 @@ static int cgx_lmac_exit(struct cgx *cgx)
 		rvu_free_bitmap(&lmac->mac_to_index_bmap);
 		rvu_free_bitmap(&lmac->rx_fc_pfvf_bmap);
 		rvu_free_bitmap(&lmac->tx_fc_pfvf_bmap);
-		kfree(lmac->name);
 		kfree(lmac);
 	}
 
drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +1 -1
index 6180e68e1765..21504327032d 100644
@@ -46,7 +46,7 @@ struct lmac {
 	u8 lmac_id;
 	u8 lmac_type;
 	bool cmd_pend;
-	char *name;
+	char name[];
 };
 
 /* CGX & RPM has different feature set

--
2.53.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Rosen Penev

Don't bother allocating separately. There's no good reason to do so for a small string like this.

Remove name kfrees as a result.

---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c     | 13 +++----------
 .../net/ethernet/marvell/octeontx2/af/lmac_common.h |  2 +-
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +0 -0
index 4f33a816bc7a..0750fb696c90 100644

drivers/net/ethernet/marvell/octeontx2/af/cgx.c static int cgx_lmac_init(struct cgx *cgx) · line 1728

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +1 -1
@@ -1725,14 +1725,10 @@ static int cgx_lmac_init(struct cgx *cgx)
 		cgx->lmac_count = cgx->max_lmac_per_mac;
 
 	for (i = 0; i < cgx->lmac_count; i++) {
-		lmac = kzalloc_obj(struct lmac);
+		lmac = kzalloc_flex(struct lmac, name, sizeof("cgx_fwi_xxx_yyy"));

Seems fine overall, I guess a minor nit is that I thought the typical style of kzalloc_flex usage would be kzalloc_flex(*lmac, ....

idk if it's really worth a respin just for that, so:

maintainer
#2 lore raw
In reply to Rosen Penev
Quoted 4 lines · On Thu, 12 Mar 2026 17:32:40 -0700 Rosen Penev wrote:

Don't bother allocating separately. There's no good reason to do so for a small string like this.

Remove name kfrees as a result.

This is not worth bothering with.

Signature · 1 line
pw-bot: reject