octeontx2-af: fix ng_rvu leak on repeated mailbox init
Ratheesh Kannoth
maintainerPATCH 1/1 octeontx2-af: fix ng_rvu leak on repeated mailbox init
From: Sai Krishna <[email protected]>
rvu_mbox_init() allocates an ng_rvu object on every call and assigns it to rvu->ng_rvu. The function is invoked separately for AF-PF mailboxes during probe and for AF-VF mailboxes when SR-IOV is enabled, so the first allocation is leaked when the second call overwrites the pointer.
Allocate ng_rvu only once and reuse it across subsequent mailbox init paths.
--- .../net/ethernet/marvell/octeontx2/af/rvu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +10 -8
@@ -2585,12 +2585,6 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw,if (!pf_bmap)return -ENOMEM ; - ng_rvu_mbox =kzalloc_obj (*ng_rvu_mbox); -if (!ng_rvu_mbox) { - err = -ENOMEM ; - goto free_bitmap; - } -/* RVU VFs */ if (type ==TYPE_AFVF )bitmap_set (pf_bmap,0 , num);
@@ -2604,9 +2598,17 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw, } } - rvu->ng_rvu = ng_rvu_mbox; +if (!rvu->ng_rvu) { + ng_rvu_mbox =kzalloc_obj (*ng_rvu_mbox); +if (!ng_rvu_mbox) { + err = -ENOMEM ; + goto free_bitmap; + } + + rvu->ng_rvu = ng_rvu_mbox; - rvu->ng_rvu->rvu_mbox_ops = &rvu_mbox_ops; + rvu->ng_rvu->rvu_mbox_ops = &rvu_mbox_ops; + } err =cn20k_rvu_mbox_init (rvu, type, num);if (err)
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerQuoted 8 lines · Ratheesh Kannoth
From: Sai Krishna <[email protected]>
rvu_mbox_init()allocates anng_rvuobject on every call and assigns it torvu->ng_rvu. The function is invoked separately for AF-PF mailboxes during probe and for AF-VF mailboxes when SR-IOV is enabled, so the first allocation is leaked when the second call overwrites the pointer.
Quoted 6 lines
Allocate
ng_rvuonly once and reuse it across subsequent mailbox init paths.Fixes e53ee4acb220 ("octeontx2-af: CN20k basic mbox operations and structures")Signed-off-by Sai Krishna <[email protected]>Signed-off-by Ratheesh Kannoth <[email protected]>
Will address sashiko comments in v2.
pw-bot: changes-requested