Skip to content

Commit ac7996d

Browse files
Colin Ian Kingkuba-moo
authored andcommitted
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: 1463f38 ("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>
1 parent 85bd605 commit ac7996d

File tree

1 file changed

+11
-3
lines changed
  • drivers/net/ethernet/marvell/octeontx2/af

1 file changed

+11
-3
lines changed

drivers/net/ethernet/marvell/octeontx2/af/cgx.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,10 @@ static int cgx_lmac_init(struct cgx *cgx)
871871
if (!lmac)
872872
return -ENOMEM;
873873
lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL);
874-
if (!lmac->name)
875-
return -ENOMEM;
874+
if (!lmac->name) {
875+
err = -ENOMEM;
876+
goto err_lmac_free;
877+
}
876878
sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
877879
lmac->lmac_id = i;
878880
lmac->cgx = cgx;
@@ -883,7 +885,7 @@ static int cgx_lmac_init(struct cgx *cgx)
883885
CGX_LMAC_FWI + i * 9),
884886
cgx_fwi_event_handler, 0, lmac->name, lmac);
885887
if (err)
886-
return err;
888+
goto err_irq;
887889

888890
/* Enable interrupt */
889891
cgx_write(cgx, lmac->lmac_id, CGXX_CMRX_INT_ENA_W1S,
@@ -895,6 +897,12 @@ static int cgx_lmac_init(struct cgx *cgx)
895897
}
896898

897899
return cgx_lmac_verify_fwi_version(cgx);
900+
901+
err_irq:
902+
kfree(lmac->name);
903+
err_lmac_free:
904+
kfree(lmac);
905+
return err;
898906
}
899907

900908
static int cgx_lmac_exit(struct cgx *cgx)

0 commit comments

Comments
 (0)