octeontx2-af: fix memory leak of lmac and lmac->name

Currently the error return paths don't kfree lmac and lmac->name
leading to some memory leaks.  Fix this by adding two error return
paths that kfree these objects

Addresses-Coverity: ("Resource leak")
Fixes: 1463f382f5 ("octeontx2-af: Add support for CGX link management")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20210107123916.189748-1-colin.king@canonical.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Colin Ian King 2021-01-07 12:39:16 +00:00 committed by Jakub Kicinski
parent 85bd6055e3
commit ac7996d680

View File

@ -871,8 +871,10 @@ static int cgx_lmac_init(struct cgx *cgx)
if (!lmac) if (!lmac)
return -ENOMEM; return -ENOMEM;
lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL); lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL);
if (!lmac->name) if (!lmac->name) {
return -ENOMEM; err = -ENOMEM;
goto err_lmac_free;
}
sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i); sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
lmac->lmac_id = i; lmac->lmac_id = i;
lmac->cgx = cgx; lmac->cgx = cgx;
@ -883,7 +885,7 @@ static int cgx_lmac_init(struct cgx *cgx)
CGX_LMAC_FWI + i * 9), CGX_LMAC_FWI + i * 9),
cgx_fwi_event_handler, 0, lmac->name, lmac); cgx_fwi_event_handler, 0, lmac->name, lmac);
if (err) if (err)
return err; goto err_irq;
/* Enable interrupt */ /* Enable interrupt */
cgx_write(cgx, lmac->lmac_id, CGXX_CMRX_INT_ENA_W1S, cgx_write(cgx, lmac->lmac_id, CGXX_CMRX_INT_ENA_W1S,
@ -895,6 +897,12 @@ static int cgx_lmac_init(struct cgx *cgx)
} }
return cgx_lmac_verify_fwi_version(cgx); return cgx_lmac_verify_fwi_version(cgx);
err_irq:
kfree(lmac->name);
err_lmac_free:
kfree(lmac);
return err;
} }
static int cgx_lmac_exit(struct cgx *cgx) static int cgx_lmac_exit(struct cgx *cgx)