[PATCH net-next] octeontx2-af: CGX: use kzalloc_flex for name

Rosen Penev posted 1 patch 3 weeks, 4 days ago
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(-)
[PATCH net-next] octeontx2-af: CGX: use kzalloc_flex for name
Posted by Rosen Penev 3 weeks, 4 days ago
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.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 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(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
index 4f33a816bc7a..0750fb696c90 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
@@ -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);
 	}

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
index 6180e68e1765..21504327032d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
@@ -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
Re: [PATCH net-next] octeontx2-af: CGX: use kzalloc_flex for name
Posted by Jakub Kicinski 3 weeks, 2 days ago
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.
-- 
pw-bot: reject
Re: [PATCH net-next] octeontx2-af: CGX: use kzalloc_flex for name
Posted by Joe Damato 3 weeks, 3 days ago
On Thu, Mar 12, 2026 at 05:32:40PM -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.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  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(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> index 4f33a816bc7a..0750fb696c90 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
> @@ -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:

Reviewed-by: Joe Damato <joe@dama.to>