octeontx2-af: CGX: use kzalloc_flex for name
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
@@ -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
@@ -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
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.
Signed-off-by Rosen Penev <[email protected]>--- 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
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:
Jakub Kicinski
maintainerQuoted 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