Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

octeontx2-pf: Fix a memleak otx2_sq_init

When qmem_alloc and pfvf->hw_ops->sq_aq_init fails, sq->sg should be
freed to prevent memleak.

Fixes: c9c12d339d93 ("octeontx2-pf: Add support for PTP clock")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Zhipeng Lu and committed by
David S. Miller
b09b58e3 f3616173

+12 -2
+12 -2
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
··· 951 951 if (pfvf->ptp && qidx < pfvf->hw.tx_queues) { 952 952 err = qmem_alloc(pfvf->dev, &sq->timestamps, qset->sqe_cnt, 953 953 sizeof(*sq->timestamps)); 954 - if (err) 954 + if (err) { 955 + kfree(sq->sg); 956 + sq->sg = NULL; 955 957 return err; 958 + } 956 959 } 957 960 958 961 sq->head = 0; ··· 971 968 sq->stats.bytes = 0; 972 969 sq->stats.pkts = 0; 973 970 974 - return pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura); 971 + err = pfvf->hw_ops->sq_aq_init(pfvf, qidx, sqb_aura); 972 + if (err) { 973 + kfree(sq->sg); 974 + sq->sg = NULL; 975 + return err; 976 + } 977 + 978 + return 0; 975 979 976 980 } 977 981